// File: /workspace/github_c_makefile_star2_O1/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, 0x18(%rsp)
leaq -0x695b(%rip), %rbx     # 0xc715
movl $0x2, %edi
movq %rbx, %rsi
callq 0x6280
movl $0x3, %edi
movq %rbx, %rsi
callq 0x6280
cmpl $0x1, %r15d
je 0x1309f
cmpl $0x2, %r15d
je 0x13110
leaq 0xed67(%rip), %rbx      # 0x21e04
jmp 0x130a6
leaq 0xed47(%rip), %rbx      # 0x21ded
movq 0x16e83(%rip), %r14     # 0x29f30
movq (%r14), %rdi
movq 0x16ef9(%rip), %rax     # 0x29fb0
movl (%rax), %esi
decl %esi
xorl %edx, %edx
callq 0x6490
cmpl $-0x1, %eax
je 0x130db
movq (%r14), %rdi
leaq 0x1726f(%rip), %rsi     # 0x2a340
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6550
movq (%r14), %rdi
callq 0x6200
movq (%r14), %rdi
leaq 0x1ada3(%rip), %rsi     # 0x2de90
movl $0x50, %edx
callq 0x63e0
leaq 0x1a76e(%rip), %rax     # 0x2d86c
movl (%rax), %eax
movl %eax, 0x1fdba(%rip)     # 0x32ec0
xorl %edi, %edi
movq %rbx, %rsi
callq 0x13523
leaq 0x1af09(%rip), %rdi     # 0x2e020
movl $0x42, %esi
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x6450
testl %eax, %eax
js 0x13512
movl %eax, %r13d
movl %r15d, 0xc(%rsp)
movl %ebp, 0x10(%rsp)
leaq 0xda8b(%rip), %rsi      # 0x20bce
movl %eax, %edi
callq 0x63d0
movq %rax, %rbp
leaq 0x1fd7c(%rip), %rbx     # 0x32ed0
movq %rbx, %r14
xorl %r12d, %r12d
movl $0x0, (%r12,%rbx)
movl $0x4, %r15d
movl $0xff, %edi
xorl %eax, %eax
callq 0xc72d
movb %al, (%r14,%r15)
incq %r15
cmpq $0x54, %r15
jne 0x13168
movl $0xff, %edi
xorl %eax, %eax
callq 0xc72d
movl %eax, 0x54(%r12,%rbx)
movl $0xff, %edi
xorl %eax, %eax
callq 0xc72d
movl %eax, 0x58(%r12,%rbx)
movl $0xff, %edi
xorl %eax, %eax
callq 0xc72d
movb %al, 0x60(%r12,%rbx)
movl $0xff, %edi
xorl %eax, %eax
callq 0xc72d
movl %eax, 0x5c(%r12,%rbx)
movl $0xff, %edi
xorl %eax, %eax
callq 0xc72d
cltq
movq %rax, 0x70(%r12,%rbx)
leaq 0x78(%r12), %rax
addq $0x78, %r14
cmpq $0x3c1, %r12            # imm = 0x3C1
movq %rax, %r12
jb 0x1315a
movq 0x16d38(%rip), %rbx     # 0x29f30
movq (%rbx), %rdi
movq 0x16dae(%rip), %rax     # 0x29fb0
movl (%rax), %esi
decl %esi
xorl %edx, %edx
callq 0x6490
cmpl $-0x1, %eax
je 0x13226
movq (%rbx), %rdi
leaq 0x17124(%rip), %rsi     # 0x2a340
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6550
movq %rbp, 0x20(%rsp)
movq (%rbx), %rdi
callq 0x6200
movq (%rbx), %rdi
leaq 0x1ac53(%rip), %rsi     # 0x2de90
movl $0x50, %edx
callq 0x63e0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xc8d1
testb %al, %al
jne 0x13260
leaq 0x1a642(%rip), %rax     # 0x2d89d
cmpb $0x1, (%rax)
jne 0x1327a
leaq 0x1ac29(%rip), %rdi     # 0x2de90
leaq 0xebae(%rip), %rsi      # 0x21e1c
callq 0x6250
xorl %ebx, %ebx
testl %eax, %eax
sete %bl
movl %ebx, 0x14(%rsp)
leaq 0x1fc4b(%rip), %r14     # 0x32ed0
leaq 0x200f4(%rip), %rbx     # 0x33380
xorl %r15d, %r15d
leaq (%r14,%r15), %r12
leaq (%r15,%r14), %rdi
addq $0x4, %rdi
movl $0x50, %esi
movl %r13d, %edx
callq 0x15700
movq %rbx, %rdi
movl $0x64, %esi
movl %r13d, %edx
callq 0x15700
leaq (%r15,%r14), %rcx
addq $0x54, %rcx
leaq 0x58(%r15,%r14), %r8
leaq 0x5c(%r15,%r14), %r9
leaq 0x64(%r15,%r14), %r10
leaq 0x68(%r15,%r14), %r11
leaq 0x70(%r15,%r14), %rbp
movq %rbx, %rdi
leaq 0xeb3f(%rip), %rsi      # 0x21e22
movq %r12, %rdx
xorl %eax, %eax
pushq %rbp
pushq %r11
pushq %r10
leaq 0x34(%rsp), %r10
pushq %r10
callq 0x6360
addq $0x20, %rsp
movb 0x1c(%rsp), %al
movb %al, -0x10(%rbp)
addq $0x78, %r15
cmpq $0x4b0, %r15            # imm = 0x4B0
jne 0x1328f
leaq 0x1a584(%rip), %rax     # 0x2d8a0
cmpb $0x0, (%rax)
movq 0x20(%rsp), %rbp
movl 0x18(%rsp), %r8d
jne 0x133ed
xorl %r12d, %r12d
cmpl %r8d, (%r12,%r14)
jl 0x1334e
leaq 0x78(%r12), %rax
cmpq $0x3c0, %r12            # imm = 0x3C0
movq %rax, %r12
jbe 0x13332
jmp 0x133ed
cmpq $0x437, %r12            # imm = 0x437
ja 0x13379
leaq (%r14,%r12), %rdx
leaq 0x1ffa6(%rip), %rdi     # 0x33308
leaq -0x78(%rdi), %rax
movl $0xf, %ecx
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
cmpq %rdx, %rax
ja 0x13362
leaq (%r12,%r14), %rbx
addq $0x4, %rbx
movl %r8d, -0x4(%rbx)
leaq 0x1ab54(%rip), %rsi     # 0x2dee0
movq %rbx, %rdi
callq 0x60e0
movl 0xc(%rsp), %eax
movl %eax, 0x50(%rbx)
cmpl $0x2, %eax
jne 0x133a9
leaq 0x16f55(%rip), %rax     # 0x2a2fc
jmp 0x133b0
leaq 0x16f40(%rip), %rax     # 0x2a2f0
movl (%rax), %eax
leaq (%r12,%r14), %rdi
addq $0x70, %rdi
movl %eax, -0x18(%rdi)
movl 0x10(%rsp), %eax
movb %al, -0x10(%rdi)
leaq 0x1aa95(%rip), %rax     # 0x2de60
movl (%rax), %eax
movl %eax, -0x14(%rdi)
leaq 0x1a989(%rip), %rax     # 0x2dd60
movq (%rax), %rax
movl 0x28(%rax), %ecx
movl %ecx, -0xc(%rdi)
movq 0x20(%rax), %rax
movq %rax, -0x8(%rdi)
callq 0x62e0
xorl %eax, %eax
callq 0x14178
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x63a0
leaq 0x1ff79(%rip), %rbx     # 0x33380
leaq 0xea14(%rip), %r15      # 0x21e22
xorl %r13d, %r13d
xorps %xmm0, %xmm0
movaps %xmm0, 0x1ffb5(%rip)    # 0x333d0
movaps %xmm0, 0x1ff9e(%rip)    # 0x333c0
movaps %xmm0, 0x1ff87(%rip)    # 0x333b0
movaps %xmm0, 0x1ff70(%rip)    # 0x333a0
movaps %xmm0, 0x1ff59(%rip)    # 0x33390
movaps %xmm0, 0x1ff42(%rip)    # 0x33380
movl $0x0, 0x1ff98(%rip)     # 0x333e0
leaq 0x4(%r13,%r14), %r12
movq %r12, %rdi
movl $0x50, %esi
movq %rbp, %rdx
callq 0x156a0
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 0x156a0
addq $0x78, %r13
cmpq $0x4b0, %r13            # imm = 0x4B0
jne 0x13411
movq %rbp, %rdi
callq 0x6140
leaq -0x6dbe(%rip), %rbx     # 0xc715
movl $0x2, %edi
movq %rbx, %rsi
callq 0x6280
movl $0x3, %edi
movq %rbx, %rsi
callq 0x6280
movq 0x16a3c(%rip), %rbx     # 0x29f30
movq (%rbx), %rdi
callq 0x6120
movq (%rbx), %rdi
callq 0x6200
callq 0x6530
movl 0x14(%rsp), %edi
callq 0x136ea
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq