// File: /workspace/github_c_makefile_star2_O3/ajpaulson[P]srogue11/fight.c
// Function: roll_em
bool roll_em(struct stats *att,struct stats *def,struct object *weap,bool hurl)
{
	char *cp;
	int ndice, nsides, def_arm, prop_hplus, prop_dplus;
	bool did_hit = FALSE;
	char *mindex(char *cp,char c);

	prop_hplus = prop_dplus = 0;
	if (weap == NULL) {
		cp = att->s_dmg;
	}
	else if (hurl) {
		if (o_on(weap,ISMISL) && cur_weapon != NULL &&
		  cur_weapon->o_which == weap->o_launch) {
			cp = weap->o_hurldmg;
			prop_hplus = cur_weapon->o_hplus;
			prop_dplus = cur_weapon->o_dplus;
		}
		else
			cp = (o_on(weap,ISMISL) ? weap->o_damage : weap->o_hurldmg);
	}
	else {
		cp = weap->o_damage;
		/*
		 * Drain a staff of striking
		 */
		if (weap->o_type == STICK && weap->o_which == WS_HIT
		  && weap->o_charges == 0) {
			strcpy(weap->o_damage, "0d0");
			weap->o_hplus = weap->o_dplus = 0;
		}
    }
	while(1) {
		int damage;
		int hplus = prop_hplus + (weap == NULL ? 0 : weap->o_hplus);
		int dplus = prop_dplus + (weap == NULL ? 0 : weap->o_dplus);

		if (att == him && weap == cur_weapon) {
			if (isring(LEFT, R_ADDDAM))
				dplus += cur_ring[LEFT]->o_ac;
			else if (isring(LEFT, R_ADDHIT))
				hplus += cur_ring[LEFT]->o_ac;
			if (isring(RIGHT, R_ADDDAM))
				dplus += cur_ring[RIGHT]->o_ac;
			else if (isring(RIGHT, R_ADDHIT))
				hplus += cur_ring[RIGHT]->o_ac;
		}
		ndice = atoi(cp);
		if ((cp = mindex(cp, 'd')) == NULL)
			break;
		nsides = atoi(++cp);

		if (def == him) {			/* defender is hero */
			if (cur_armor != NULL)
				def_arm = cur_armor->o_ac;
			else
				def_arm = def->s_arm;
			if (isring(LEFT, R_PROTECT))
				def_arm -= cur_ring[LEFT]->o_ac;
			if (isring(RIGHT, R_PROTECT))
				def_arm -= cur_ring[RIGHT]->o_ac;
		}
		else						/* defender is monster */
			def_arm = def->s_arm;
		if (hurl)
			hplus += getpdex(att,TRUE);
		if (swing(att->s_lvl, def_arm + getpdex(def, FALSE),
		  hplus + str_plus(att))) {
			int proll;

			proll = roll(ndice, nsides);
			damage = dplus + proll + add_dam(att);
			if (pl_off(ISINVINC) || def != him)
				def->s_hpt -= max(0, damage);
			did_hit = TRUE;
		}
		if ((cp = mindex(cp, '/')) == NULL)
			break;
		cp++;
	}
	return did_hit;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %r14d
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
testq %rdx, %rdx
je 0x9cfd
testb %r14b, %r14b
je 0x9d04
movl $0x2000, %esi           # imm = 0x2000
movq %rbx, %rdi
callq 0x9531
leaq 0x23b7b(%rip), %rcx     # 0x2d850
movq (%rcx), %rcx
testq %rcx, %rcx
setne %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x9d2d
movsbl 0x48(%rbx), %eax
cmpl %eax, 0x28(%rcx)
jne 0x9d2d
leaq 0x10(%rbx), %r13
movl 0x2c(%rcx), %eax
movl 0x30(%rcx), %ecx
movl %ecx, (%rsp)
jmp 0x9d50
leaq 0x40(%r12), %r13
jmp 0x9d47
leaq 0x8(%rbx), %r13
xorl %eax, %eax
cmpl $0x2f, 0x20(%rbx)
jne 0x9d49
cmpl $0x1, 0x28(%rbx)
jne 0x9d49
cmpl $0x0, 0x34(%rbx)
jne 0x9d49
movl $0x306430, 0x8(%rbx)    # imm = 0x306430
movq $0x0, 0x2c(%rbx)
jmp 0x9d49
movl $0x2000, %esi           # imm = 0x2000
movq %rbx, %rdi
callq 0x9531
xorb $0x1, %al
movzbl %al, %eax
leaq (%rbx,%rax,8), %r13
addq $0x8, %r13
xorl %eax, %eax
movl $0x0, (%rsp)
leaq 0x2c(%r15), %rcx
movq %rcx, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movl %r14d, 0xc(%rsp)
movl %eax, 0x8(%rsp)
movq %rbx, 0x30(%rsp)
movq %r12, 0x28(%rsp)
movl %eax, %ebp
movl $0x0, %ecx
testq %rbx, %rbx
je 0x9d89
movl 0x2c(%rbx), %ebp
addl %eax, %ebp
movl 0x30(%rbx), %ecx
addl (%rsp), %ecx
leaq 0x23fcd(%rip), %rax     # 0x2dd60
cmpq %r12, (%rax)
movl %ecx, 0x4(%rsp)
jne 0x9e40
leaq 0x23aa9(%rip), %rax     # 0x2d850
cmpq %rbx, (%rax)
jne 0x9e40
xorl %edi, %edi
movl $0x8, %esi
callq 0x12c17
testb %al, %al
je 0x9dd7
leaq 0x23f89(%rip), %rax     # 0x2dd50
movq (%rax), %rax
movl 0x4(%rsp), %ecx
addl 0x34(%rax), %ecx
movl %ecx, 0x4(%rsp)
jmp 0x9df4
xorl %edi, %edi
movl $0x7, %esi
callq 0x12c17
testb %al, %al
je 0x9df4
leaq 0x23f62(%rip), %rax     # 0x2dd50
movq (%rax), %rax
addl 0x34(%rax), %ebp
movl $0x1, %edi
movl $0x8, %esi
callq 0x12c17
testb %al, %al
je 0x9e1f
leaq 0x23f42(%rip), %rax     # 0x2dd50
movq 0x8(%rax), %rax
movl 0x4(%rsp), %ecx
addl 0x34(%rax), %ecx
movl %ecx, 0x4(%rsp)
jmp 0x9e40
movl $0x1, %edi
movl $0x7, %esi
callq 0x12c17
testb %al, %al
je 0x9e40
leaq 0x23f17(%rip), %rax     # 0x2dd50
movq 0x8(%rax), %rax
addl 0x34(%rax), %ebp
movq %r13, %rdi
callq 0x64b0
movl $0x3, %edx
movq %r13, %rcx
xorl %r13d, %r13d
cmpb $0x64, (%rcx)
setne %r13b
addq %rcx, %r13
decl %edx
jne 0x9e4d
cmpb $0x64, (%r13)
jne 0x9fd9
movl %eax, 0x14(%rsp)
incq %r13
movq %r13, %rdi
callq 0x64b0
movl %eax, 0x10(%rsp)
leaq 0x23eda(%rip), %rax     # 0x2dd60
cmpq %r15, (%rax)
je 0x9e94
movq 0x20(%rsp), %rax
movl (%rax), %ebx
jmp 0x9ee5
leaq 0x239bd(%rip), %rax     # 0x2d858
movq (%rax), %rax
leaq 0x34(%rax), %rcx
testq %rax, %rax
cmoveq 0x20(%rsp), %rcx
movl (%rcx), %ebx
xorl %edi, %edi
xorl %esi, %esi
callq 0x12c17
testb %al, %al
je 0x9ec7
leaq 0x23e8f(%rip), %rax     # 0x2dd50
movq (%rax), %rax
subl 0x34(%rax), %ebx
movl $0x1, %edi
xorl %esi, %esi
callq 0x12c17
testb %al, %al
je 0x9ee5
leaq 0x23e72(%rip), %rax     # 0x2dd50
movq 0x8(%rax), %rax
subl 0x34(%rax), %ebx
testb %r14b, %r14b
je 0x9ef9
movq %r12, %rdi
movl $0x1, %esi
callq 0x11f6b
addl %eax, %ebp
addl 0x28(%r12), %ebx
movq %r15, %rdi
xorl %esi, %esi
callq 0x11f6b
movq %r12, %rdi
movq %r15, %r12
movl %eax, %r15d
callq 0x1200c
movl %eax, %r14d
movl $0x14, %edi
xorl %eax, %eax
callq 0xc674
addl %ebx, %r15d
movl $0x15, %ecx
subl %r15d, %ecx
movq %r12, %r15
addl %ebp, %r14d
addl %r14d, %eax
incl %eax
cmpl %ecx, %eax
jl 0x9f8f
movl 0x14(%rsp), %edi
movl 0x10(%rsp), %esi
callq 0xc695
movl %eax, %ebx
movq 0x28(%rsp), %rdi
callq 0x1206f
movl %eax, %ebp
movl $0x8, %edi
callq 0x9522
movb $0x1, %cl
movq %rcx, 0x18(%rsp)
testb %al, %al
jne 0x9f7b
leaq 0x23dea(%rip), %rax     # 0x2dd60
cmpq %r15, (%rax)
je 0x9f8f
addl 0x4(%rsp), %ebx
addl %ebp, %ebx
testl %ebx, %ebx
movl $0x0, %eax
cmovlel %eax, %ebx
subl %ebx, 0x30(%r15)
movl $0x3, %eax
movq %r13, %rcx
xorl %r13d, %r13d
cmpb $0x2f, (%rcx)
setne %r13b
addq %rcx, %r13
decl %eax
jne 0x9f94
cmpb $0x2f, (%r13)
movl $0x0, %eax
cmovneq %rax, %r13
leaq 0x1(%r13), %rax
testq %r13, %r13
movq %rax, %r13
movl 0xc(%rsp), %r14d
movq 0x30(%rsp), %rbx
movq 0x28(%rsp), %r12
movl 0x8(%rsp), %eax
jne 0x9d75
movq 0x18(%rsp), %rax
andb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq