// File: /workspace/github_c_makefile_star2_O2/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 $0x27e8, %rsp           # imm = 0x27E8
movq %rdi, %r14
callq 0x4278
movl %eax, %r12d
movq %r14, %rdi
callq 0x4288
movl %eax, %ebx
movq %r14, %rdi
callq 0x4298
movl %eax, %r13d
movq %r14, %rdi
callq 0x42d3
movq %rax, %r14
movq %rax, %rdi
callq 0x3f21
movl %eax, %ebp
movq %r14, %rdi
callq 0x3f4f
movl %eax, %r15d
movq %r14, %rdi
callq 0x3fb2
movl %eax, 0x18(%rsp)
movq %r14, %rdi
callq 0x3f99
movl %eax, %r14d
cmpw $0x2, 0x89a4(%rip)      # 0xa142
jne 0x17b0
movupd 0x48af(%rip), %xmm0     # 0x6057
movapd %xmm0, 0x30(%rsp)
jmp 0x17d8
movl %r12d, %eax
orl %ebx, %eax
orl %r13d, %eax
jne 0x1814
movabsq $0x7478742e656469, %rax # imm = 0x7478742E656469
movq %rax, 0x37(%rsp)
movabsq $0x6963697573646e65, %rax # imm = 0x6963697573646E65
movq %rax, 0x30(%rsp)
pushq $0x2e
popq %rdx
pushq $0x78
popq %rcx
pushq $0x1
popq %r8
xorl %edi, %edi
xorl %esi, %esi
xorl %r9d, %r9d
callq 0x3c28
movq %rax, %rbx
leaq 0x4842(%rip), %rsi      # 0x603a
leaq 0x30(%rsp), %rdi
callq 0x11a0
testq %rax, %rax
je 0x180c
testq %rbx, %rbx
jne 0x183c
pushq $-0x1
popq %rdi
callq 0x11c0
movl %r12d, %eax
xorl $0x3, %eax
movl %ebx, %ecx
xorl $0x3, %ecx
orl %eax, %ecx
movl %r13d, %eax
xorl $0x3, %eax
orl %ecx, %eax
jne 0x1ad5
movupd 0x483f(%rip), %xmm0     # 0x6076
jmp 0x17a8
movq %rax, %r13
movl %r14d, 0x1c(%rsp)
movl %r15d, 0x20(%rsp)
movl %ebp, 0x24(%rsp)
negl 0x18(%rsp)
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
callq 0x3c71
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x11d0
leaq 0xc(%rsp), %r15
leaq 0x8(%rsp), %rbp
leaq 0xd0(%rsp), %r14
movq 0x875f(%rip), %r12      # 0x9fe0
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x10f0
testl %eax, %eax
jne 0x1927
movq %r13, %rdi
leaq 0x479f(%rip), %rsi      # 0x603c
movq %r15, %rdx
movq %rbp, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x1060
movq %rbx, %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, %rbx
movq %rax, %rdi
movq %r14, %rsi
callq 0x1050
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movq 0x10(%rsp), %rdi
movq %rbx, %rcx
callq 0x3d9a
movq (%r12), %rdi
callq 0x10d0
movl %eax, %ecx
shll $0x18, %ecx
andl $0xdf, %eax
cmpl $0x41, %eax
je 0x191b
cmpl $0xa000000, %ecx        # imm = 0xA000000
jne 0x18fb
cmpl $0xa000000, %ecx        # imm = 0xA000000
jne 0x1883
movq %r13, %rdi
callq 0x1070
leaq 0x47a8(%rip), %rdi      # 0x60de
leaq 0x46fd(%rip), %rsi      # 0x603a
callq 0x11a0
movq %rax, %r13
movq 0x10(%rsp), %rdi
callq 0x3c71
leaq 0x80(%rsp), %r14
movq %r13, 0x28(%rsp)
movq %r13, %rdi
callq 0x10f0
testl %eax, %eax
jne 0x1a26
movq %r13, %rdi
leaq 0x46c6(%rip), %rsi      # 0x603c
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
leaq 0xd0(%rsp), %r12
movq %r12, %r8
xorl %eax, %eax
callq 0x1060
movq %r12, %rdi
callq 0x1080
movq %rax, %rbp
movq %rbx, %rdi
callq 0x1030
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
movq %r12, %rsi
callq 0x1050
movslq %ebp, %r12
xorl %ebp, %ebp
movq %r13, %rbx
cmpq %r12, %rbp
jge 0x1a15
cmpl $0x2d, %r15d
jg 0x1a15
movq %r13, %rbx
addq %rbp, %rbx
movq %r14, %rdi
movq %rbx, %rsi
pushq $0x41
popq %rdx
callq 0x1100
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movq 0x10(%rsp), %rdi
movq %r14, %rcx
callq 0x3d9a
addq $0x41, %rbp
incl %r15d
jmp 0x19d8
movq 0x85c4(%rip), %r12      # 0x9fe0
movq 0x28(%rsp), %r13
jmp 0x195c
cvtsi2sdl 0x24(%rsp), %xmm0
movl 0x20(%rsp), %eax
addl %eax, %eax
cvtsi2sd %eax, %xmm1
mulsd 0x45da(%rip), %xmm0     # 0x6018
addsd %xmm1, %xmm0
cvtsi2sdl 0x18(%rsp), %xmm1
mulsd 0x45d0(%rip), %xmm1     # 0x6020
cvtsi2sdl 0x1c(%rsp), %xmm2
addsd %xmm0, %xmm1
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %edx
leaq 0x4681(%rip), %rsi      # 0x60ea
leaq 0x80(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x11b0
pushq $0x21
popq %rsi
pushq $0xf
popq %rdx
movq 0x10(%rsp), %rdi
movq %r14, %rcx
callq 0x3d9a
movq (%r12), %rdi
callq 0x10d0
cmpb $0xa, %al
jne 0x1a8e
movq %r13, %rdi
callq 0x1070
movq 0x10(%rsp), %rdi
callq 0x3d19
movq %rbx, %rdi
callq 0x1030
movq (%r12), %rdi
callq 0x1120
leaq 0x863f(%rip), %rdx      # 0xa104
movl %eax, %edi
xorl %esi, %esi
callq 0x1190
xorl %edi, %edi
callq 0x11c0
leal (%r12,%r13), %eax
leal (%rax,%rbx), %ecx
cmpl $0xb, %ecx
setl %cl
cmpl $0x3, %r12d
setl %dl
cmpl $0x3, %r13d
setl %sil
orb %dl, %sil
cmpl $0x3, %ebx
setl %dl
orb %sil, %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x1b36
testl %r12d, %r12d
sete %cl
leal (%rbx,%r13), %edx
cmpl $0x7, %edx
setge %dl
testb %dl, %cl
je 0x1b6b
movabsq $0x7478742e736578, %rax # imm = 0x7478742E736578
movq %rax, 0x37(%rsp)
movabsq $0x786f626f6e646e65, %rax # imm = 0x786F626F6E646E65
jmp 0x17d3
xorl $0x5, %r12d
xorl $0x5, %ebx
orl %r12d, %ebx
xorl $0x5, %r13d
orl %ebx, %r13d
jne 0x1be2
movabsq $0x7478742e657269, %rax # imm = 0x7478742E657269
movq %rax, 0x36(%rsp)
movabsq $0x7269706d65646e65, %rax # imm = 0x7269706D65646E65
jmp 0x17d3
testl %r13d, %r13d
sete %dl
testl %ebx, %ebx
sete %cl
leal (%rbx,%r12), %esi
cmpl $0x7, %esi
setge %sil
cmpl $0x7, %eax
setge %al
testb %sil, %dl
jne 0x1bac
andb %al, %cl
jne 0x1bac
movabsq $0x2e65736f6c646e65, %rax # imm = 0x2E65736F6C646E65
movq %rax, 0x30(%rsp)
movl $0x747874, 0x38(%rsp)   # imm = 0x747874
jmp 0x17d8
testl %r12d, %r12d
je 0x1b18
testl %r13d, %r13d
jne 0x1bc4
movupd 0x44ed(%rip), %xmm0     # 0x60af
jmp 0x1bd0
testl %ebx, %ebx
jne 0x1be2
movupd 0x44f1(%rip), %xmm0     # 0x60c1
movapd %xmm0, 0x30(%rsp)
movw $0x74, 0x40(%rsp)
jmp 0x17d8
movabsq $0x742e6e6977646e65, %rax # imm = 0x742E6E6977646E65
movq %rax, 0x30(%rsp)
movl $0x747874, 0x37(%rsp)   # imm = 0x747874
jmp 0x17d8