/* 
 * Script decompiled by jagdecs2 v3.2
 * Decompiler opts:
 * --------------
 * t1LocalAnalyzer:true
 * t2LocalAnalyzer:true
 * beautifier:true
 * --------------
 * Made by mgi125 ;)
 */


int script_9177(int a0,int a1,int a2) {
	int v9 = 0;
	int v10 = cs2method_10924(a1);
	globalarray_0 = new int[v10];
	globalarray_1 = new int[v10];
	globalarray_2 = new int[v10];
	globalarray_3 = new int[v10];
	globalarray_4 = new int[v10];
	int v20 = 0;
	int v8 = 0;
	int v19 = 0;
	int v17 = 0;
	int v3 = 0;
	int v11 = 0;
	int v4 = 0;
	int v5 = 0;
	int v26 = 1;
	int v0 = a0;
	int v6 = 0;
	int v21 = -1;
	while (v9 < v10) {
		int v22 = idx17mapData('i', 'J', a1, cs2method_10060(1, v9));
		if ((a2 == 0 || script_9178(idx22mapAttribute(v22, 1268)) == 1) && (idx22mapAttribute(v22, 3812) == 0 || script_3224(idx22mapAttribute(v22, 1268)) == 1)) {
			int v29 = idx22mapAttribute(v22, 1268);
			script_9132_struct(2,0,0) v30 = script_9132(v29);
			int v31 = v30.intpart_1;
			int v28 = v30.intpart_0;
			switch (v28) {
				case 0:
				case 1:
				case 4:
					globalarray_0[v19] = v9;
					v19 = cs2method_10060(v19, 1);
					break;
				case 2:
				case 5:
					globalarray_0[v17] = v9;
					v17 = cs2method_10060(v17, 1);
					break;
				case 3:
				case 6:
				case 7:
					globalarray_0[v3] = v9;
					v3 = cs2method_10060(v3, 1);
					break;
				case -1:
					globalarray_0[v11] = v9;
					v11 = cs2method_10060(v11, 1);
			}
			globalarray_0[v9] = v31;
		}
		v9 = cs2method_10060(v9, 1);
	}
	while (v26 < v19) {
		int v29 = globalarray_0[v26];
		for (int v30 = idx22mapAttribute(idx17mapData('i', 'J', a1, cs2method_10060(1, v29)), 3632), int v28 = v26; v28 > 0 && v30 < idx22mapAttribute(idx17mapData('i', 'J', a1, cs2method_10060(1, globalarray_0[cs2method_10461(v28, 1)])), 3632); v28 = cs2method_10461(v28, 1)) {
			globalarray_0[v28] = globalarray_0[cs2method_10461(v28, 1)];
		}
		globalarray_0[v28] = v29;
		v26 = cs2method_10060(v26, 1);
	}
	for (int v18 = 0, int v15 = 0, int v1 = 1, int v12 = 0; v1 < v17; v1 = cs2method_10060(v1, 1)) {
		int v28 = globalarray_1[v1];
		for (int v29 = globalarray_4[v28], int v30 = v1; v30 > 0 && v29 > globalarray_4[globalarray_1[cs2method_10461(v30, 1)]]; v30 = cs2method_10461(v30, 1)) {
			globalarray_0[v30] = globalarray_1[cs2method_10461(v30, 1)];
		}
		globalarray_0[v30] = v28;
	}
	for (int v7 = 0, int v16 = 0, int v13 = 1, int v25 = 0; v13 < v3; v13 = cs2method_10060(v13, 1)) {
		int v29 = globalarray_2[v13];
		for (int v30 = idx22mapAttribute(idx17mapData('i', 'J', a1, cs2method_10060(1, v29)), 3632), int v28 = v13; v28 > 0 && v30 < idx22mapAttribute(idx17mapData('i', 'J', a1, cs2method_10060(1, globalarray_2[cs2method_10461(v28, 1)])), 3632); v28 = cs2method_10461(v28, 1)) {
			globalarray_0[v28] = globalarray_2[cs2method_10461(v28, 1)];
		}
		globalarray_0[v28] = v29;
	}
	int v23 = a0;
	int v24 = 0;
	while (v24 < v11) {
		script_9173(globalarray_3[v24], v23);
		v23 = cs2method_10060(v23, 1);
		v24 = cs2method_10060(v24, 1);
	}
	for (int v14 = 0; v14 < v3; v14 = cs2method_10060(v14, 1)) {
		script_9173(globalarray_2[v14], v23);
		v23 = cs2method_10060(v23, 1);
	}
	for (int v27 = 0; v27 < v17; v27 = cs2method_10060(v27, 1)) {
		script_9173(globalarray_1[v27], v23);
		v23 = cs2method_10060(v23, 1);
	}
	for (int v2 = 0; v2 < v19; v2 = cs2method_10060(v2, 1)) {
		script_9173(globalarray_0[v2], v23);
		v23 = cs2method_10060(v23, 1);
	}
	return v23;
}
