// File: /workspace/github_c_makefile_star2_O3/ajpaulson[P]srogue11/rip.c
// Function: score
int score(int amount,int aflag,char monst)
{
	struct sc_ent *scp, *sc2;
	int i, fd, prflags = 0;
	FILE *outf;
	char *packend;

	signal(SIGINT, byebye);
	signal(SIGQUIT, byebye);
	if (aflag != WINNER) {
		if (aflag == CHICKEN)
			packend = "when you chickened out";
		else
			packend = "at your untimely demise";
		mvaddstr(LINES - 1, 0, retstr);
		refresh();
		wgetnstr(stdscr,prbuf,80);
		oldpurse = purse;
		showpack(FALSE, packend);
	}
	/*
	 * Open file and read list
	 */
	if ((fd = open(scorefile, O_RDWR | O_CREAT, 0666)) < 0)
		return 0;
	outf = (FILE *) fdopen(fd, "w");
	for (scp = top_ten; scp <= &top_ten[9]; scp++) {
		scp->sc_score = 0;
		for (i = 0; i < 80; i++)
			scp->sc_name[i] = rnd(255);
		scp->sc_flags = rnd(255);
		scp->sc_level = rnd(255);
		scp->sc_monster = rnd(255);
		scp->sc_uid = rnd(255);
		scp->sc_date = rnd(255);
	}
	mvaddstr(LINES - 1, 0, retstr);
	refresh();
	wgetnstr(stdscr,prbuf,80);
	if (author() || wizard)
		if (strcmp(prbuf, "names") == 0)
			prflags = 1;
        for(i = 0; i < 10; i++)
        {
            unsigned int mon;

            encread((char *) &top_ten[i].sc_name, LINLEN, fd);
            encread((char *) scoreline, 100, fd);
            sscanf(scoreline, " %d %d %d %d %u %d %ld %lx \n",
                &top_ten[i].sc_score,   &top_ten[i].sc_flags,
                &top_ten[i].sc_level,   &top_ten[i].sc_uid,
                &mon,                   &top_ten[i].sc_explvl,
                &top_ten[i].sc_exppts,  &top_ten[i].sc_date);
            top_ten[i].sc_monster = mon;
        }
	/*
	 * Insert it in list if need be
	 */
	if (!waswizard) {
		for (scp = top_ten; scp <= &top_ten[9]; scp++)
			if (amount > scp->sc_score)
				break;
			if (scp <= &top_ten[9]) {
				for (sc2 = &top_ten[9]; sc2 > scp; sc2--)
					*sc2 = *(sc2-1);
				scp->sc_score = amount;
				strcpy(scp->sc_name, whoami);
				scp->sc_flags = aflag;
				if (aflag == WINNER)
					scp->sc_level = max_level;
				else
					scp->sc_level = level;
				scp->sc_monster = monst;
				scp->sc_uid = playuid;
				scp->sc_explvl = him->s_lvl;
				scp->sc_exppts = him->s_exp;
				time(&scp->sc_date);
		}
	}
	ignore();
	fseek(outf, 0L, 0);
        for(i = 0; i < 10; i++)
        {
            memset(scoreline,0,100);
            encwrite((char *) top_ten[i].sc_name, LINLEN, outf);
            sprintf(scoreline, " %d %d %d %d %u %d %ld %lx \n",
                top_ten[i].sc_score, top_ten[i].sc_flags,
                top_ten[i].sc_level, top_ten[i].sc_uid,
                top_ten[i].sc_monster, top_ten[i].sc_explvl,
                top_ten[i].sc_exppts, top_ten[i].sc_date);
            encwrite((char *) scoreline, 100, outf);
        }
	fclose(outf);
	signal(SIGINT, byebye);
	signal(SIGQUIT, byebye);
	clear();
	refresh();
	endwin();
	showtop(prflags);		/* print top ten list */
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, 0x10(%rsp)
movl %esi, %ebp
movl %edi, %r15d
leaq -0x68ac(%rip), %rbx     # 0xc65c
movl $0x2, %edi
movq %rbx, %rsi
callq 0x6280
movl $0x3, %edi
movq %rbx, %rsi
callq 0x6280
cmpl $0x1, %ebp
je 0x12f35
cmpl $0x2, %ebp
je 0x12fa6
leaq 0xef49(%rip), %rbx      # 0x21e7c
jmp 0x12f3c
leaq 0xef29(%rip), %rbx      # 0x21e65
movq 0x16fed(%rip), %r14     # 0x29f30
movq (%r14), %rdi
movq 0x17063(%rip), %rax     # 0x29fb0
movl (%rax), %esi
decl %esi
xorl %edx, %edx
callq 0x6490
cmpl $-0x1, %eax
je 0x12f71
movq (%r14), %rdi
leaq 0x173d9(%rip), %rsi     # 0x2a340
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6550
movq (%r14), %rdi
callq 0x6200
movq (%r14), %rdi
leaq 0x1af0d(%rip), %rsi     # 0x2de90
movl $0x50, %edx
callq 0x63e0
leaq 0x1a8d8(%rip), %rax     # 0x2d86c
movl (%rax), %eax
movl %eax, 0x1ff24(%rip)     # 0x32ec0
xorl %edi, %edi
movq %rbx, %rsi
callq 0x133b2
leaq 0x1b073(%rip), %rdi     # 0x2e020
movl $0x42, %esi
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x6450
testl %eax, %eax
js 0x133a1
movl %eax, %r13d
movl %r15d, 0x18(%rsp)
movl %ebp, 0xc(%rsp)
leaq 0xd079(%rip), %rsi      # 0x20052
movl %eax, %edi
callq 0x63d0
movq %rax, %rbp
leaq 0x1fee6(%rip), %rbx     # 0x32ed0
movq %rbx, %r15
xorl %r12d, %r12d
movl $0x0, (%r12,%rbx)
movl $0x4, %r14d
movl $0xff, %edi
xorl %eax, %eax
callq 0xc674
movb %al, (%r15,%r14)
incq %r14
cmpq $0x54, %r14
jne 0x12ffe
movl $0xff, %edi
xorl %eax, %eax
callq 0xc674
movl %eax, 0x54(%r12,%rbx)
movl $0xff, %edi
xorl %eax, %eax
callq 0xc674
movl %eax, 0x58(%r12,%rbx)
movl $0xff, %edi
xorl %eax, %eax
callq 0xc674
movb %al, 0x60(%r12,%rbx)
movl $0xff, %edi
xorl %eax, %eax
callq 0xc674
movl %eax, 0x5c(%r12,%rbx)
movl $0xff, %edi
xorl %eax, %eax
callq 0xc674
cltq
movq %rax, 0x70(%r12,%rbx)
leaq 0x78(%r12), %rax
addq $0x78, %r15
cmpq $0x3c1, %r12            # imm = 0x3C1
movq %rax, %r12
jb 0x12ff0
movq 0x16ea2(%rip), %rbx     # 0x29f30
movq (%rbx), %rdi
movq 0x16f18(%rip), %rax     # 0x29fb0
movl (%rax), %esi
decl %esi
xorl %edx, %edx
callq 0x6490
cmpl $-0x1, %eax
je 0x130bc
movq (%rbx), %rdi
leaq 0x1728e(%rip), %rsi     # 0x2a340
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6550
movq %rbp, 0x20(%rsp)
movq (%rbx), %rdi
callq 0x6200
movq (%rbx), %rdi
leaq 0x1adbd(%rip), %rsi     # 0x2de90
movl $0x50, %edx
callq 0x63e0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xc818
testb %al, %al
jne 0x130f6
leaq 0x1a7ac(%rip), %rax     # 0x2d89d
cmpb $0x1, (%rax)
jne 0x13110
leaq 0x1ad93(%rip), %rdi     # 0x2de90
leaq 0xed90(%rip), %rsi      # 0x21e94
callq 0x6250
xorl %ebx, %ebx
testl %eax, %eax
sete %bl
movl %ebx, 0x14(%rsp)
leaq 0x1fdb5(%rip), %rbx     # 0x32ed0
leaq 0x2025e(%rip), %rbp     # 0x33380
xorl %r14d, %r14d
leaq (%rbx,%r14), %r15
leaq (%r14,%rbx), %rdi
addq $0x4, %rdi
movl $0x50, %esi
movl %r13d, %edx
callq 0x15594
movq %rbp, %rdi
movl $0x64, %esi
movl %r13d, %edx
callq 0x15594
leaq (%r14,%rbx), %rcx
addq $0x54, %rcx
leaq 0x58(%r14,%rbx), %r8
leaq 0x5c(%r14,%rbx), %r9
leaq 0x64(%r14,%rbx), %r10
leaq 0x68(%r14,%rbx), %r11
leaq 0x70(%r14,%rbx), %r12
movq %rbp, %rdi
leaq 0xed21(%rip), %rsi      # 0x21e9a
movq %r15, %rdx
xorl %eax, %eax
pushq %r12
pushq %r11
pushq %r10
leaq 0x34(%rsp), %r10
pushq %r10
callq 0x6360
addq $0x20, %rsp
movb 0x1c(%rsp), %al
movb %al, -0x10(%r12)
addq $0x78, %r14
cmpq $0x4b0, %r14            # imm = 0x4B0
jne 0x13125
leaq 0x1a6eb(%rip), %rax     # 0x2d8a0
cmpb $0x0, (%rax)
movq 0x20(%rsp), %rbp
movl 0x18(%rsp), %edx
jne 0x13275
xorl %eax, %eax
cmpl %edx, (%rbx)
jl 0x131e5
leaq 0x78(%rax), %rcx
addq $0x78, %rbx
cmpq $0x3c0, %rax            # imm = 0x3C0
movq %rcx, %rax
jbe 0x131c9
jmp 0x13275
cmpq $0x437, %rax            # imm = 0x437
ja 0x1320b
leaq 0x20114(%rip), %rdi     # 0x33308
leaq -0x78(%rdi), %rax
movl $0xf, %ecx
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
cmpq %rbx, %rax
ja 0x131f4
movl %edx, (%rbx)
leaq 0x4(%rbx), %rdi
leaq 0x1acc8(%rip), %rsi     # 0x2dee0
callq 0x60e0
movl 0xc(%rsp), %eax
movl %eax, 0x54(%rbx)
cmpl $0x2, %eax
jne 0x13232
leaq 0x170cc(%rip), %rax     # 0x2a2fc
jmp 0x13239
leaq 0x170b7(%rip), %rax     # 0x2a2f0
movl (%rax), %eax
movl %eax, 0x58(%rbx)
movl 0x10(%rsp), %eax
movb %al, 0x60(%rbx)
leaq 0x1ac14(%rip), %rax     # 0x2de60
movl (%rax), %eax
movl %eax, 0x5c(%rbx)
leaq 0x1ab08(%rip), %rax     # 0x2dd60
movq (%rax), %rax
movl 0x28(%rax), %ecx
movl %ecx, 0x64(%rbx)
movq 0x20(%rax), %rax
movq %rax, 0x68(%rbx)
addq $0x70, %rbx
movq %rbx, %rdi
callq 0x62e0
xorl %eax, %eax
callq 0x14018
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x63a0
leaq 0x200f1(%rip), %rbx     # 0x33380
leaq 0x1fc3a(%rip), %r13     # 0x32ed0
leaq 0xebfd(%rip), %r15      # 0x21e9a
xorl %r14d, %r14d
xorps %xmm0, %xmm0
movaps %xmm0, 0x20126(%rip)    # 0x333d0
movaps %xmm0, 0x2010f(%rip)    # 0x333c0
movaps %xmm0, 0x200f8(%rip)    # 0x333b0
movaps %xmm0, 0x200e1(%rip)    # 0x333a0
movaps %xmm0, 0x200ca(%rip)    # 0x33390
movaps %xmm0, 0x200b3(%rip)    # 0x33380
movl $0x0, 0x20109(%rip)     # 0x333e0
leaq 0x4(%r14,%r13), %r12
movq %r12, %rdi
movl $0x50, %esi
movq %rbp, %rdx
callq 0x15534
movl -0x4(%r12), %edx
movl 0x50(%r12), %ecx
movl 0x54(%r12), %r8d
movl 0x58(%r12), %r9d
movzbl 0x5c(%r12), %eax
movl 0x60(%r12), %esi
movups 0x64(%r12), %xmm0
subq $0x20, %rsp
movups %xmm0, 0x10(%rsp)
movl %esi, 0x8(%rsp)
movl %eax, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x64f0
addq $0x20, %rsp
movq %rbx, %rdi
movl $0x64, %esi
movq %rbp, %rdx
callq 0x15534
addq $0x78, %r14
cmpq $0x4b0, %r14            # imm = 0x4B0
jne 0x132a0
movq %rbp, %rdi
callq 0x6140
leaq -0x6d06(%rip), %rbx     # 0xc65c
movl $0x2, %edi
movq %rbx, %rsi
callq 0x6280
movl $0x3, %edi
movq %rbx, %rsi
callq 0x6280
movq 0x16bad(%rip), %rbx     # 0x29f30
movq (%rbx), %rdi
callq 0x6120
movq (%rbx), %rdi
callq 0x6200
callq 0x6530
movl 0x14(%rsp), %edi
callq 0x13574
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq