// File: /workspace/github_c_makefile_star2_O1/rafa9811[P]theIndiependenceGame/theindiependencegame.c
// Function: GetEnd
void GetEnd(Interact *interact){
	    sc_rectangle *intro;
	    FILE * in;
			Stat* stat;
	    char *dialog=NULL, *ini, line[INTRO_LINE],choice, buff[MAX], endpath[INTRO_LINE];
	    int len,j=0,linenumber,x,y,boxes,printers,meetings,motivation, chaos, nodanger, score, money;
			
			boxes = interact_getBoxes(interact);
			printers = interact_getPrinters(interact);
			meetings = interact_getMeetings(interact);
			stat = interact_getStat(interact);
			motivation = stat_get_motivation(stat);
			chaos = stat_get_chaos(stat);
			nodanger = -stat_get_nodanger(stat);
			money = stat_get_money(stat);
			
			if(end==2){
				strcpy(endpath,"endarrested.txt");
				goto endlabel;
			}
						
			if (boxes == 0 && printers == 0 && meetings == 0) {
					strcpy(endpath, "endsuicide.txt");
					goto endlabel;
			}
			if (boxes == 3 && printers == 3 && meetings == 3) {
					strcpy(endpath, "endbrussels.txt");
					goto endlabel;
			}
			if ((boxes + meetings + printers <= 10) || boxes<3 || meetings<3 || printers<3) {
					if((boxes==0 && meetings + printers > 6)|| (meetings==0 && boxes + printers > 6) || (printers==0 && boxes + meetings >6)) goto nosomething;
					strcpy(endpath, "endlose.txt");
					goto endlabel;
			}

			if (boxes == 5 && printers == 5 && meetings == 5) {
					strcpy(endpath, "endempire.txt");
					goto endlabel;
			}
			if ((boxes + meetings + printers >= 11) || boxes==0 || meetings==0 || printers==0) {
					nosomething: if (boxes == 0) {
							strcpy(endpath, "endnoboxes.txt");
							goto endlabel;
					}
					if (meetings == 0) {
							strcpy(endpath, "endnomeetings.txt");
							goto endlabel;
					}
					if (printers == 0) {
							strcpy(endpath, "endnoprinters.txt");
							goto endlabel;
					}
					strcpy(endpath, "endwin.txt");
					goto endlabel;
			}
			
			
	    endlabel: intro = win_new(0,0,INTROY,INTROX,BGCOLOR,CHARCOLOR); /*Creating the intro window, which occupies all the screen.*/
	    in = (FILE*) fopen(endpath, "r"); /*Openning the intro txt file which contains every dialog from the intro.*/
	
		if(!in) exit(-1);
	  if (!intro) exit(-1);
			win_cls(intro);
			usleep(1000000);
		while(!feof(in)){
			fscanf(in,"%d\t%d\t%[^\n]s",&x,&y,buff);
			if(dialog) free(dialog);
			len = strlen(buff);
			dialog = (char*) malloc(len+1);
			strcpy(dialog,buff);
	    win_write_line_at(intro,y,x,dialog);
	    j+=INTRO_LINE;
			choice = fgetc(stdin);
			while(choice!='a' && choice!='A' && choice!='\n'){
			    choice = fgetc(stdin);
			}
			if(choice=='\n'){
			    break;
			}
		}
	
		fclose(in);
		in = (FILE*) fopen("endmenu.txt", "r");
		win_cls(intro);
	    while(!feof(in)){
			fscanf(in,"%d\t%d\t%[^\n]s",&x,&y,buff);
			len = strlen(buff);
			if(dialog) free(dialog);
			dialog = (char*) malloc(len+1);
			strcpy(dialog,buff);
	    ini=dialog;
	    j=0;
	    while(j<len && linenumber<INTROY){
	      dialog = ini + j;
	      memcpy(line,dialog,INTRO_LINE);
	      win_write_line_at(intro,y,x,line);
	      j+=INTRO_LINE;
	      linenumber++;
	    }
			
	    }
			score = (int)(2.5*motivation + 2*chaos + 1.5*nodanger + money);
			sprintf(line,"YOUR SCORE: %d PuidgePoints",score);
			win_write_line_at(intro,33,15,line);
			choice = fgetc(stdin);
			while(choice!='\n'){
			    choice = fgetc(stdin);
			}
			if(choice=='\n'){
				fclose(in);
				win_delete(intro);
				if(dialog) free(dialog);
				tcsetattr(fileno(stdin), TCSANOW, &initial);
				exit(0);
			}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x27d8, %rsp           # imm = 0x27D8
movq %rdi, %r12
callq 0x459f
movl %eax, %r15d
movq %r12, %rdi
callq 0x45b1
movl %eax, %ebx
movq %r12, %rdi
callq 0x45c3
movl %eax, %r14d
movq %r12, %rdi
callq 0x4600
movq %rax, %r12
movq %rax, %rdi
callq 0x4242
movl %eax, %ebp
movq %r12, %rdi
callq 0x4278
movl %eax, %r13d
movq %r12, %rdi
callq 0x42f0
movl %eax, 0x10(%rsp)
movq %r12, %rdi
callq 0x42d2
cmpw $0x2, 0x88cb(%rip)      # 0xa13a
movl %eax, 0x1c(%rsp)
jne 0x1883
movups 0x47db(%rip), %xmm0     # 0x6057
movaps %xmm0, 0x20(%rsp)
jmp 0x18ab
movl %r15d, %ecx
orl %ebx, %ecx
orl %r14d, %ecx
jne 0x18ef
movabsq $0x7478742e656469, %rax # imm = 0x7478742E656469
movq %rax, 0x27(%rsp)
movabsq $0x6963697573646e65, %rax # imm = 0x6963697573646E65
movq %rax, 0x20(%rsp)
xorl %edi, %edi
xorl %esi, %esi
movl $0x2e, %edx
movl $0x78, %ecx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x3f23
movq %rax, %r15
leaq 0x4769(%rip), %rsi      # 0x603a
leaq 0x20(%rsp), %rdi
callq 0x1190
testq %rax, %rax
je 0x18e5
testq %r15, %r15
jne 0x1916
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x11b0
movl %r15d, %edx
xorl $0x3, %edx
movl %ebx, %ecx
xorl $0x3, %ecx
orl %edx, %ecx
movl %r14d, %edx
xorl $0x3, %edx
orl %ecx, %edx
jne 0x1c05
movups 0x4765(%rip), %xmm0     # 0x6076
jmp 0x187c
movq %rax, %rbx
movl %r13d, 0x14(%rsp)
movl %ebp, 0x18(%rsp)
negl 0x10(%rsp)
movq %r15, %rdi
callq 0x3f6e
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x11c0
leaq 0x8(%rsp), %rbp
leaq 0xc0(%rsp), %r14
movq 0x8694(%rip), %r12      # 0x9fe0
xorl %r13d, %r13d
movq %rbx, %rdi
callq 0x10f0
testl %eax, %eax
jne 0x1a1e
movq %rbx, %rdi
leaq 0x46d3(%rip), %rsi      # 0x603c
leaq 0xc(%rsp), %rdx
movq %rbp, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x1060
testq %r13, %r13
je 0x1988
movq %r13, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1080
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
leaq (%rax,%rcx), %rdi
sarq $0x20, %rdi
callq 0x1130
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
callq 0x1050
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movq %r15, %rdi
movq %r13, %rcx
callq 0x4081
movq (%r12), %rdi
callq 0x10d0
movl %eax, %ecx
shll $0x18, %ecx
andl $0xdf, %eax
cmpl $0x41, %eax
sete %al
cmpl $0xa000000, %ecx        # imm = 0xA000000
sete %dl
orb %al, %dl
jne 0x1a12
movq (%r12), %rdi
callq 0x10d0
movl %eax, %ecx
shll $0x18, %ecx
andl $0xdf, %eax
cmpl $0x41, %eax
je 0x1a12
cmpl $0xa000000, %ecx        # imm = 0xA000000
jne 0x19f2
cmpl $0xa000000, %ecx        # imm = 0xA000000
jne 0x194f
movq %rbx, %rdi
callq 0x1070
leaq 0x46b1(%rip), %rdi      # 0x60de
leaq 0x4606(%rip), %rsi      # 0x603a
callq 0x1190
movq %rax, %rbp
movq %r15, %rdi
callq 0x3f6e
movq %rbp, %rdi
callq 0x10f0
testl %eax, %eax
jne 0x1b4e
movq %rbp, 0x68(%rsp)
movq %rbp, %rdi
leaq 0x45d9(%rip), %rsi      # 0x603c
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
leaq 0xc0(%rsp), %r14
movq %r14, %r8
xorl %eax, %eax
callq 0x1060
movq %r14, %rdi
callq 0x1080
movq %rax, %rbp
testq %r13, %r13
je 0x1a97
movq %r13, %rdi
callq 0x1030
movq %r15, %r14
movq %rbp, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
callq 0x1130
movq %rax, %r13
movq %rax, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x1050
testl %ebp, %ebp
setg %al
cmpl $0x2e, %ebx
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1b29
addq $-0x41, %r13
movl $0x41, %r15d
addq $0x41, %r13
movl $0x41, %edx
leaq 0x70(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x1100
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movq %r14, %rdi
movq %r12, %rcx
callq 0x4081
leal 0x1(%rbx), %r12d
cmpl %ebp, %r15d
jge 0x1b2c
addl $0x41, %r15d
cmpl $0x2d, %ebx
movl %r12d, %ebx
jl 0x1ae6
jmp 0x1b2c
movl %ebx, %r12d
movq 0x68(%rsp), %rbp
movq %rbp, %rdi
callq 0x10f0
movl %r12d, %ebx
testl %eax, %eax
movq %r14, %r15
movq 0x8498(%rip), %r12      # 0x9fe0
je 0x1a59
xorps %xmm0, %xmm0
cvtsi2sdl 0x18(%rsp), %xmm0
movl 0x14(%rsp), %eax
addl %eax, %eax
cvtsi2sd %eax, %xmm1
mulsd 0x44af(%rip), %xmm0     # 0x6018
addsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x10(%rsp), %xmm1
mulsd 0x44a2(%rip), %xmm1     # 0x6020
cvtsi2sdl 0x1c(%rsp), %xmm2
addsd %xmm0, %xmm1
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %edx
leaq 0x4553(%rip), %rsi      # 0x60ea
leaq 0x70(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x11a0
movq %r15, %rdi
movl $0x21, %esi
movl $0xf, %edx
movq %r14, %rcx
callq 0x4081
movq (%r12), %rdi
callq 0x10d0
cmpb $0xa, %al
jne 0x1bbb
movq %rbp, %rdi
callq 0x1070
movq %r15, %rdi
callq 0x4019
testq %r13, %r13
je 0x1be5
movq %r13, %rdi
callq 0x1030
movq (%r12), %rdi
callq 0x1120
leaq 0x8507(%rip), %rdx      # 0xa0fc
movl %eax, %edi
xorl %esi, %esi
callq 0x1180
xorl %edi, %edi
callq 0x11b0
leal (%r14,%r15), %edi
leal (%rdi,%rbx), %ecx
cmpl $0xb, %ecx
setl %cl
cmpl $0x3, %r15d
setl %dl
cmpl $0x3, %r14d
setl %sil
orb %dl, %sil
cmpl $0x3, %ebx
setl %dl
orb %sil, %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x1c8b
testl %r15d, %r15d
sete %cl
leal (%r14,%rbx), %edx
cmpl $0x7, %edx
setge %dl
testb %dl, %cl
jne 0x1cc0
testl %r14d, %r14d
sete %dl
testl %ebx, %ebx
sete %cl
leal (%rbx,%r15), %esi
cmpl $0x7, %esi
setge %sil
cmpl $0x7, %edi
setge %dil
testb %sil, %dl
jne 0x1cc0
andb %dil, %cl
jne 0x1cc0
movabsq $0x2e65736f6c646e65, %rax # imm = 0x2E65736F6C646E65
movq %rax, 0x20(%rsp)
movl $0x747874, 0x28(%rsp)   # imm = 0x747874
jmp 0x18ab
movl %r15d, %edx
xorl $0x5, %edx
movl %ebx, %ecx
xorl $0x5, %ecx
orl %edx, %ecx
movl %r14d, %edx
xorl $0x5, %edx
orl %ecx, %edx
jne 0x1cc0
movabsq $0x7478742e657269, %rax # imm = 0x7478742E657269
movq %rax, 0x26(%rsp)
movabsq $0x7269706d65646e65, %rax # imm = 0x7269706D65646E65
jmp 0x18a6
testl %r15d, %r15d
jne 0x1ce3
movabsq $0x7478742e736578, %rax # imm = 0x7478742E736578
movq %rax, 0x27(%rsp)
movabsq $0x786f626f6e646e65, %rax # imm = 0x786F626F6E646E65
jmp 0x18a6
testl %r14d, %r14d
jne 0x1cf1
movups 0x43c0(%rip), %xmm0     # 0x60af
jmp 0x1cfc
testl %ebx, %ebx
jne 0x1d0d
movups 0x43c5(%rip), %xmm0     # 0x60c1
movaps %xmm0, 0x20(%rsp)
movw $0x74, 0x30(%rsp)
jmp 0x18ab
movabsq $0x742e6e6977646e65, %rax # imm = 0x742E6E6977646E65
movq %rax, 0x20(%rsp)
movl $0x747874, 0x27(%rsp)   # imm = 0x747874
jmp 0x18ab