// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movl %esi, %r15d
movl %edi, %r12d
leaq -0x625c(%rip), %rbx     # 0xbfec
pushq $0x2
popq %rdi
movq %rbx, %rsi
callq 0x6270
pushq $0x3
popq %rdi
movq %rbx, %rsi
callq 0x6270
cmpl $0x1, %r15d
je 0x12273
cmpl $0x2, %r15d
je 0x122e0
leaq 0xdc0b(%rip), %rbx      # 0x1fe7c
jmp 0x1227a
leaq 0xdbeb(%rip), %rbx      # 0x1fe65
movq 0x17cb7(%rip), %r14     # 0x29f38
movq (%r14), %rdi
movq 0x17d35(%rip), %rax     # 0x29fc0
movl (%rax), %esi
decl %esi
xorl %edx, %edx
callq 0x6470
cmpl $-0x1, %eax
je 0x122ad
movq (%r14), %rdi
leaq 0x1808b(%rip), %rsi     # 0x2a330
pushq $-0x1
popq %rdx
callq 0x6530
movq (%r14), %rdi
callq 0x6200
movq (%r14), %rdi
leaq 0x1bbc1(%rip), %rsi     # 0x2de80
pushq $0x50
popq %rdx
callq 0x63d0
leaq 0x1b58e(%rip), %rax     # 0x2d85c
movl (%rax), %eax
movl %eax, 0x20bda(%rip)     # 0x32eb0
xorl %edi, %edi
movq %rbx, %rsi
callq 0x126cf
leaq 0x1bd29(%rip), %rdi     # 0x2e010
pushq $0x42
popq %rsi
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x6430
testl %eax, %eax
js 0x126be
movl %eax, %r13d
movl %r12d, 0x20(%rsp)
movl %r15d, 0x14(%rsp)
movl %ebp, 0x18(%rsp)
leaq 0xbd3c(%rip), %rsi      # 0x1e052
movl %eax, %edi
callq 0x63c0
movq %rax, 0x8(%rsp)
leaq 0x20b97(%rip), %rbx     # 0x32ec0
pushq $0x4
popq %r14
movq %rbx, %r15
xorl %r12d, %r12d
cmpq $0x438, %r12            # imm = 0x438
ja 0x123b7
andl $0x0, (%r12,%rbx)
movq %r14, %rbp
movl $0xff, %edi
xorl %eax, %eax
callq 0xc004
cmpq $0x54, %rbp
je 0x1235f
movb %al, (%r15,%rbp)
incq %rbp
jmp 0x12344
movl %eax, 0x54(%r12,%rbx)
movl $0xff, %edi
xorl %eax, %eax
callq 0xc004
movl %eax, 0x58(%r12,%rbx)
movl $0xff, %edi
xorl %eax, %eax
callq 0xc004
movb %al, 0x60(%r12,%rbx)
movl $0xff, %edi
xorl %eax, %eax
callq 0xc004
movl %eax, 0x5c(%r12,%rbx)
movl $0xff, %edi
xorl %eax, %eax
callq 0xc004
cltq
movq %rax, 0x70(%r12,%rbx)
addq $0x78, %r12
addq $0x78, %r15
jmp 0x12333
movq 0x17b7a(%rip), %rbx     # 0x29f38
movq (%rbx), %rdi
movq 0x17bf8(%rip), %rax     # 0x29fc0
movl (%rax), %esi
decl %esi
xorl %edx, %edx
callq 0x6470
cmpl $-0x1, %eax
je 0x123ea
movq (%rbx), %rdi
leaq 0x17f4e(%rip), %rsi     # 0x2a330
pushq $-0x1
popq %rdx
callq 0x6530
movq (%rbx), %rdi
callq 0x6200
movq (%rbx), %rdi
leaq 0x1ba84(%rip), %rsi     # 0x2de80
pushq $0x50
popq %rdx
callq 0x63d0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xc164
testb %al, %al
jne 0x1241d
leaq 0x1b475(%rip), %rax     # 0x2d88d
cmpb $0x1, (%rax)
jne 0x12437
leaq 0x1ba5c(%rip), %rdi     # 0x2de80
leaq 0xda69(%rip), %rsi      # 0x1fe94
callq 0x6240
xorl %ebx, %ebx
testl %eax, %eax
sete %bl
movl %ebx, 0x1c(%rsp)
leaq 0x20a7e(%rip), %r15     # 0x32ec0
leaq 0x20f27(%rip), %rbp     # 0x33370
xorl %r12d, %r12d
cmpq $0x4b0, %r12            # imm = 0x4B0
je 0x124cc
leaq (%r15,%r12), %r14
leaq (%r12,%r15), %rdi
addq $0x4, %rdi
pushq $0x50
popq %rsi
movl %r13d, %edx
callq 0x146da
movq %rbp, %rdi
pushq $0x64
popq %rsi
movl %r13d, %edx
callq 0x146da
leaq (%r12,%r15), %rcx
addq $0x54, %rcx
leaq 0x58(%r12,%r15), %r8
leaq 0x5c(%r12,%r15), %r9
leaq 0x64(%r12,%r15), %r10
leaq 0x68(%r12,%r15), %r11
leaq 0x70(%r12,%r15), %rbx
movq %rbp, %rdi
leaq 0xd9f5(%rip), %rsi      # 0x1fe9a
movq %r14, %rdx
xorl %eax, %eax
pushq %rbx
pushq %r11
pushq %r10
leaq 0x3c(%rsp), %r10
pushq %r10
callq 0x6350
addq $0x20, %rsp
movb 0x24(%rsp), %al
movb %al, -0x10(%rbx)
addq $0x78, %r12
jmp 0x1244c
leaq 0x1b3bd(%rip), %rax     # 0x2d890
cmpb $0x0, (%rax)
movl 0x20(%rsp), %r9d
jne 0x1259a
leaq 0x209d0(%rip), %rax     # 0x32eb8
xorl %ecx, %ecx
cmpq $0x438, %rcx            # imm = 0x438
ja 0x1259a
addq $0x78, %rcx
leaq 0x78(%rax), %r13
cmpl %r9d, 0x8(%rax)
movq %r13, %rax
jge 0x124ea
leaq -0x70(%r13), %r8
leaq 0x20de5(%rip), %rdi     # 0x332f8
pushq $0xf
popq %rax
cmpq %r8, %rdi
jbe 0x1252d
leaq -0x78(%rdi), %rdx
movq %rax, %rcx
movq %rdx, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rdx, %rdi
jmp 0x12516
movl %r9d, -0x70(%r13)
leaq -0x6c(%r13), %rdi
leaq 0x1b994(%rip), %rsi     # 0x2ded0
callq 0x60e0
movl 0x14(%rsp), %eax
movl %eax, -0x1c(%r13)
cmpl $0x2, %eax
jne 0x12557
leaq 0x17d97(%rip), %rax     # 0x2a2ec
jmp 0x1255e
leaq 0x17d82(%rip), %rax     # 0x2a2e0
movl (%rax), %eax
movl %eax, -0x18(%r13)
movl 0x18(%rsp), %eax
movb %al, -0x10(%r13)
leaq 0x1b8dd(%rip), %rax     # 0x2de50
movl (%rax), %eax
movl %eax, -0x14(%r13)
leaq 0x1b7d0(%rip), %rax     # 0x2dd50
movq (%rax), %rax
movl 0x28(%rax), %ecx
movl %ecx, -0xc(%r13)
movq 0x20(%rax), %rax
movq %rax, -0x8(%r13)
movq %r13, %rdi
callq 0x62d0
xorl %eax, %eax
callq 0x13210
movq 0x8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x6390
leaq 0x20dba(%rip), %rbx     # 0x33370
pushq $0x64
popq %r12
xorl %ebp, %ebp
movq 0x8(%rsp), %r13
cmpq $0x4b0, %rbp            # imm = 0x4B0
je 0x12672
xorps %xmm0, %xmm0
movaps %xmm0, 0x20de8(%rip)    # 0x333c0
movaps %xmm0, 0x20dd1(%rip)    # 0x333b0
movaps %xmm0, 0x20dba(%rip)    # 0x333a0
movaps %xmm0, 0x20da3(%rip)    # 0x33390
movaps %xmm0, 0x20d8c(%rip)    # 0x33380
movaps %xmm0, 0x20d75(%rip)    # 0x33370
andl $0x0, 0x20dce(%rip)     # 0x333d0
leaq (%r15,%rbp), %r14
addq $0x4, %r14
movq %r14, %rdi
pushq $0x50
popq %rsi
movq %r13, %rdx
callq 0x1467c
movl -0x4(%r14), %edx
movl 0x50(%r14), %ecx
movl 0x54(%r14), %r8d
movl 0x58(%r14), %r9d
movzbl 0x5c(%r14), %eax
movl 0x60(%r14), %esi
movups 0x64(%r14), %xmm0
subq $0x20, %rsp
movups %xmm0, 0x10(%rsp)
movl %esi, 0x8(%rsp)
movl %eax, (%rsp)
movq %rbx, %rdi
leaq 0xd84a(%rip), %rsi      # 0x1fe9a
xorl %eax, %eax
callq 0x64d0
addq $0x20, %rsp
movq %rbx, %rdi
movl %r12d, %esi
movq %r13, %rdx
callq 0x1467c
addq $0x78, %rbp
jmp 0x125c1
movq 0x8(%rsp), %rdi
callq 0x6140
leaq -0x6697(%rip), %rbx     # 0xbfec
pushq $0x2
popq %rdi
movq %rbx, %rsi
callq 0x6270
pushq $0x3
popq %rdi
movq %rbx, %rsi
callq 0x6270
movq 0x17898(%rip), %rbx     # 0x29f38
movq (%rbx), %rdi
callq 0x6120
movq (%rbx), %rdi
callq 0x6200
callq 0x6510
movl 0x1c(%rsp), %edi
callq 0x12887
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq