// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movl %ecx, %r15d
movq %rdx, %r12
movq %rsi, 0x10(%rsp)
movq %rdi, %rbp
testq %rdx, %rdx
je 0x9d7f
testb %r15b, %r15b
je 0x9d85
movl $0x2000, %esi           # imm = 0x2000
movq %r12, %rdi
callq 0x95b3
leaq 0x23afe(%rip), %rcx     # 0x2d850
movq (%rcx), %rcx
testq %rcx, %rcx
setne %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x9db9
movsbl 0x48(%r12), %eax
cmpl %eax, 0x28(%rcx)
jne 0x9db9
leaq 0x10(%r12), %r13
movl 0x2c(%rcx), %r14d
movl 0x30(%rcx), %eax
movl %eax, 0x8(%rsp)
jmp 0x9dde
leaq 0x40(%rbp), %r13
jmp 0x9dd3
leaq 0x8(%r12), %r13
xorl %r14d, %r14d
cmpl $0x2f, 0x20(%r12)
jne 0x9dd6
cmpl $0x1, 0x28(%r12)
jne 0x9dd6
cmpl $0x0, 0x34(%r12)
jne 0x9dd6
movl $0x306430, 0x8(%r12)    # imm = 0x306430
movq $0x0, 0x2c(%r12)
jmp 0x9dd6
movl $0x2000, %esi           # imm = 0x2000
movq %r12, %rdi
callq 0x95b3
xorb $0x1, %al
movzbl %al, %eax
leaq (%r12,%rax,8), %r13
addq $0x8, %r13
xorl %r14d, %r14d
movl $0x0, 0x8(%rsp)
movq 0x10(%rsp), %rax
addq $0x2c, %rax
movq %rax, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movl %r15d, 0x24(%rsp)
movq %r12, 0x40(%rsp)
movq %rbp, 0x18(%rsp)
movl %r14d, 0x20(%rsp)
movl $0x0, %ebx
testq %r12, %r12
je 0x9e18
movl 0x2c(%r12), %ebx
testq %r12, %r12
je 0x9e24
movl 0x30(%r12), %eax
jmp 0x9e26
xorl %eax, %eax
addl 0x8(%rsp), %eax
movl %eax, 0xc(%rsp)
addl %r14d, %ebx
leaq 0x23f28(%rip), %rax     # 0x2dd60
cmpq %rbp, (%rax)
jne 0x9ee1
leaq 0x23a08(%rip), %rax     # 0x2d850
cmpq %r12, (%rax)
jne 0x9ee1
xorl %edi, %edi
movl $0x8, %esi
callq 0x12d7f
testb %al, %al
je 0x9e78
leaq 0x23ee8(%rip), %rax     # 0x2dd50
movq (%rax), %rax
movl 0xc(%rsp), %ecx
addl 0x34(%rax), %ecx
movl %ecx, 0xc(%rsp)
jmp 0x9e95
xorl %edi, %edi
movl $0x7, %esi
callq 0x12d7f
testb %al, %al
je 0x9e95
leaq 0x23ec1(%rip), %rax     # 0x2dd50
movq (%rax), %rax
addl 0x34(%rax), %ebx
movl $0x1, %edi
movl $0x8, %esi
callq 0x12d7f
testb %al, %al
je 0x9ec0
leaq 0x23ea1(%rip), %rax     # 0x2dd50
movq 0x8(%rax), %rax
movl 0xc(%rsp), %ecx
addl 0x34(%rax), %ecx
movl %ecx, 0xc(%rsp)
jmp 0x9ee1
movl $0x1, %edi
movl $0x7, %esi
callq 0x12d7f
testb %al, %al
je 0x9ee1
leaq 0x23e76(%rip), %rax     # 0x2dd50
movq 0x8(%rax), %rax
addl 0x34(%rax), %ebx
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 0x9eee
cmpb $0x64, (%r13)
jne 0x9f34
movl %eax, 0x2c(%rsp)
incq %r13
movq %r13, %rdi
callq 0x64b0
movl %eax, 0x28(%rsp)
movq 0x10(%rsp), %r12
leaq 0x23e38(%rip), %rax     # 0x2dd60
cmpq %r12, (%rax)
je 0x9f3e
movl 0x2c(%r12), %ebp
jmp 0x9f8f
xorl %eax, %eax
xorl %r13d, %r13d
jmp 0xa08f
leaq 0x23913(%rip), %rax     # 0x2d858
movq (%rax), %rax
leaq 0x34(%rax), %rcx
testq %rax, %rax
cmoveq 0x38(%rsp), %rcx
movl (%rcx), %ebp
xorl %edi, %edi
xorl %esi, %esi
callq 0x12d7f
testb %al, %al
je 0x9f71
leaq 0x23de5(%rip), %rax     # 0x2dd50
movq (%rax), %rax
subl 0x34(%rax), %ebp
movl $0x1, %edi
xorl %esi, %esi
callq 0x12d7f
testb %al, %al
je 0x9f8f
leaq 0x23dc8(%rip), %rax     # 0x2dd50
movq 0x8(%rax), %rax
subl 0x34(%rax), %ebp
testb %r15b, %r15b
je 0x9faa
movq 0x18(%rsp), %r14
movq %r14, %rdi
movl $0x1, %esi
callq 0x120fa
addl %eax, %ebx
jmp 0x9faf
movq 0x18(%rsp), %r14
addl 0x28(%r14), %ebp
movq %r12, %rdi
xorl %esi, %esi
callq 0x120fa
movl %eax, %r15d
movq %r14, %rdi
callq 0x1219b
movl %eax, %r12d
movl $0x14, %edi
xorl %eax, %eax
callq 0xc72d
addl %ebp, %r15d
movl $0x15, %ecx
subl %r15d, %ecx
addl %ebx, %r12d
addl %r12d, %eax
incl %eax
cmpl %ecx, %eax
movq 0x40(%rsp), %r12
movl 0x20(%rsp), %r14d
jl 0xa051
movl 0x2c(%rsp), %edi
movl 0x28(%rsp), %esi
callq 0xc74e
movl %eax, %ebx
movq 0x18(%rsp), %rdi
callq 0x121fe
movl %eax, %ebp
movl $0x8, %edi
callq 0x95a4
movb $0x1, %cl
movq %rcx, 0x30(%rsp)
testb %al, %al
jne 0xa039
movq 0x10(%rsp), %rax
leaq 0x23d2c(%rip), %rcx     # 0x2dd60
cmpq %rax, (%rcx)
je 0xa051
addl 0xc(%rsp), %ebx
addl %ebp, %ebx
testl %ebx, %ebx
movl $0x0, %eax
cmovlel %eax, %ebx
movq 0x10(%rsp), %rax
subl %ebx, 0x30(%rax)
movl $0x3, %eax
movq %r13, %rcx
xorl %r13d, %r13d
cmpb $0x2f, (%rcx)
setne %r13b
addq %rcx, %r13
decl %eax
jne 0xa056
movb (%r13), %al
cmpb $0x2f, %al
movl $0x0, %ecx
cmovneq %rcx, %r13
incq %r13
cmpb $0x2f, %al
sete %al
cmovneq %rcx, %r13
movl 0x24(%rsp), %r15d
movq 0x18(%rsp), %rbp
testb %al, %al
jne 0x9e09
movq 0x30(%rsp), %rax
andb $0x1, %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq