// File: /workspace/github_c_makefile_star2_O3/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 0x4573
movl %eax, %r14d
movq %r12, %rdi
callq 0x4585
movl %eax, %ebx
movq %r12, %rdi
callq 0x4597
movl %eax, %r15d
movq %r12, %rdi
callq 0x45d4
movq %rax, %r12
movq %rax, %rdi
callq 0x41f0
movl %eax, %ebp
movq %r12, %rdi
callq 0x4220
movl %eax, %r13d
movq %r12, %rdi
callq 0x4289
movl %eax, 0x10(%rsp)
movq %r12, %rdi
callq 0x426e
cmpw $0x2, 0x88be(%rip)      # 0xa13a
movl %eax, 0x1c(%rsp)
jne 0x1890
movups 0x47ce(%rip), %xmm0     # 0x6057
movaps %xmm0, 0x20(%rsp)
jmp 0x18b8
movl %r14d, %ecx
orl %ebx, %ecx
orl %r15d, %ecx
jne 0x18fc
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 0x3ec7
movq %rax, %r15
leaq 0x475c(%rip), %rsi      # 0x603a
leaq 0x20(%rsp), %rdi
callq 0x1190
testq %rax, %rax
je 0x18f2
testq %r15, %r15
jne 0x1923
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x11b0
movl %r14d, %edx
xorl $0x3, %edx
movl %ebx, %ecx
xorl $0x3, %ecx
orl %edx, %ecx
movl %r15d, %edx
xorl $0x3, %edx
orl %ecx, %edx
jne 0x1c12
movups 0x4758(%rip), %xmm0     # 0x6076
jmp 0x1889
movq %rax, %rbx
movl %r13d, 0x14(%rsp)
movl %ebp, 0x18(%rsp)
negl 0x10(%rsp)
movq %r15, %rdi
callq 0x3f12
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x11c0
leaq 0x8(%rsp), %rbp
leaq 0xc0(%rsp), %r14
movq 0x8687(%rip), %r12      # 0x9fe0
xorl %r13d, %r13d
movq %rbx, %rdi
callq 0x10f0
testl %eax, %eax
jne 0x1a2b
movq %rbx, %rdi
leaq 0x46c6(%rip), %rsi      # 0x603c
leaq 0xc(%rsp), %rdx
movq %rbp, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x1060
testq %r13, %r13
je 0x1995
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 0x4025
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 0x1a1f
movq (%r12), %rdi
callq 0x10d0
movl %eax, %ecx
shll $0x18, %ecx
andl $0xdf, %eax
cmpl $0x41, %eax
je 0x1a1f
cmpl $0xa000000, %ecx        # imm = 0xA000000
jne 0x19ff
cmpl $0xa000000, %ecx        # imm = 0xA000000
jne 0x195c
movq %rbx, %rdi
callq 0x1070
leaq 0x46a4(%rip), %rdi      # 0x60de
leaq 0x45f9(%rip), %rsi      # 0x603a
callq 0x1190
movq %rax, %rbp
movq %r15, %rdi
callq 0x3f12
movq %rbp, %rdi
callq 0x10f0
testl %eax, %eax
jne 0x1b5b
movq %rbp, 0x68(%rsp)
movq %rbp, %rdi
leaq 0x45cc(%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 0x1aa4
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 0x1b36
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 0x4025
leal 0x1(%rbx), %r12d
cmpl %ebp, %r15d
jge 0x1b39
addl $0x41, %r15d
cmpl $0x2d, %ebx
movl %r12d, %ebx
jl 0x1af3
jmp 0x1b39
movl %ebx, %r12d
movq 0x68(%rsp), %rbp
movq %rbp, %rdi
callq 0x10f0
movl %r12d, %ebx
testl %eax, %eax
movq %r14, %r15
movq 0x848b(%rip), %r12      # 0x9fe0
je 0x1a66
xorps %xmm0, %xmm0
cvtsi2sdl 0x18(%rsp), %xmm0
movl 0x14(%rsp), %eax
addl %eax, %eax
cvtsi2sd %eax, %xmm1
mulsd 0x44a2(%rip), %xmm0     # 0x6018
addsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x10(%rsp), %xmm1
mulsd 0x4495(%rip), %xmm1     # 0x6020
cvtsi2sdl 0x1c(%rsp), %xmm2
addsd %xmm0, %xmm1
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %edx
leaq 0x4546(%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 0x4025
movq (%r12), %rdi
callq 0x10d0
cmpb $0xa, %al
jne 0x1bc8
movq %rbp, %rdi
callq 0x1070
movq %r15, %rdi
callq 0x3fbd
testq %r13, %r13
je 0x1bf2
movq %r13, %rdi
callq 0x1030
movq (%r12), %rdi
callq 0x1120
leaq 0x84fa(%rip), %rdx      # 0xa0fc
movl %eax, %edi
xorl %esi, %esi
callq 0x1180
xorl %edi, %edi
callq 0x11b0
leal (%r15,%r14), %edi
leal (%rdi,%rbx), %ecx
cmpl $0xb, %ecx
setl %cl
cmpl $0x3, %r14d
setl %dl
cmpl $0x3, %r15d
setl %sil
orb %dl, %sil
cmpl $0x3, %ebx
setl %dl
orb %sil, %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x1c73
testl %r14d, %r14d
sete %cl
leal (%r15,%rbx), %edx
cmpl $0x7, %edx
setge %dl
testb %dl, %cl
je 0x1ca8
movabsq $0x7478742e736578, %rax # imm = 0x7478742E736578
movq %rax, 0x27(%rsp)
movabsq $0x786f626f6e646e65, %rax # imm = 0x786F626F6E646E65
jmp 0x18b3
xorl $0x5, %r14d
xorl $0x5, %ebx
orl %r14d, %ebx
xorl $0x5, %r15d
orl %ebx, %r15d
jne 0x1d1e
movabsq $0x7478742e657269, %rax # imm = 0x7478742E657269
movq %rax, 0x26(%rsp)
movabsq $0x7269706d65646e65, %rax # imm = 0x7269706D65646E65
jmp 0x18b3
testl %r15d, %r15d
sete %dl
testl %ebx, %ebx
sete %cl
leal (%rbx,%r14), %esi
cmpl $0x7, %esi
setge %sil
cmpl $0x7, %edi
setge %dil
testb %sil, %dl
jne 0x1ceb
andb %dil, %cl
jne 0x1ceb
movabsq $0x2e65736f6c646e65, %rax # imm = 0x2E65736F6C646E65
movq %rax, 0x20(%rsp)
movl $0x747874, 0x28(%rsp)   # imm = 0x747874
jmp 0x18b8
testl %r14d, %r14d
je 0x1c55
testl %r15d, %r15d
jne 0x1d02
movups 0x43af(%rip), %xmm0     # 0x60af
jmp 0x1d0d
testl %ebx, %ebx
jne 0x1d1e
movups 0x43b4(%rip), %xmm0     # 0x60c1
movaps %xmm0, 0x20(%rsp)
movw $0x74, 0x30(%rsp)
jmp 0x18b8
movabsq $0x742e6e6977646e65, %rax # imm = 0x742E6E6977646E65
movq %rax, 0x20(%rsp)
movl $0x747874, 0x27(%rsp)   # imm = 0x747874
jmp 0x18b8