// File: /workspace/github_c_makefile_star2_O2/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, %r14d
movq %rdx, %r15
movq %rsi, 0x18(%rsp)
movq %rdi, %r12
testq %rdx, %rdx
je 0x9a0c
testb %r14b, %r14b
je 0x9a13
movl $0x2000, %esi           # imm = 0x2000
movq %r15, %rdi
callq 0x934a
leaq 0x23e5f(%rip), %rcx     # 0x2d840
movq (%rcx), %rcx
testq %rcx, %rcx
setne %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x9a3e
movsbl 0x48(%r15), %eax
cmpl %eax, 0x28(%rcx)
jne 0x9a3e
leaq 0x10(%r15), %rbp
movl 0x2c(%rcx), %r13d
movl 0x30(%rcx), %eax
movl %eax, 0xc(%rsp)
jmp 0x9a63
leaq 0x40(%r12), %rbp
jmp 0x9a58
leaq 0x8(%r15), %rbp
xorl %r13d, %r13d
cmpl $0x2f, 0x20(%r15)
jne 0x9a5b
cmpl $0x1, 0x28(%r15)
jne 0x9a5b
cmpl $0x0, 0x34(%r15)
jne 0x9a5b
movl $0x306430, 0x8(%r15)    # imm = 0x306430
andq $0x0, 0x2c(%r15)
jmp 0x9a5b
movl $0x2000, %esi           # imm = 0x2000
movq %r15, %rdi
callq 0x934a
xorb $0x1, %al
movzbl %al, %eax
leaq (%r15,%rax,8), %rbp
addq $0x8, %rbp
xorl %r13d, %r13d
movl $0x0, 0xc(%rsp)
movq 0x18(%rsp), %rax
addq $0x2c, %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x24(%rsp)
movl %r14d, 0x2c(%rsp)
movq %r15, 0x40(%rsp)
movl %r13d, 0x28(%rsp)
movl %r13d, %eax
movl $0x0, %ebx
testq %r15, %r15
je 0x9aa0
movl 0x2c(%r15), %eax
addl %r13d, %eax
movl 0x30(%r15), %ebx
movl %eax, 0x10(%rsp)
addl 0xc(%rsp), %ebx
leaq 0x242a1(%rip), %rax     # 0x2dd50
cmpq %r12, (%rax)
jne 0x9ae1
leaq 0x23d85(%rip), %rax     # 0x2d840
cmpq %r15, (%rax)
jne 0x9ae1
xorl %edi, %edi
pushq $0x8
popq %rsi
callq 0x11f88
testb %al, %al
pushq $0x1
popq %r15
je 0x9aeb
leaq 0x24267(%rip), %rax     # 0x2dd40
movq (%rax), %rax
addl 0x34(%rax), %ebx
jmp 0x9b0e
movl %ebx, 0x14(%rsp)
pushq $0x1
popq %r15
jmp 0x9b5a
xorl %edi, %edi
pushq $0x7
popq %rsi
callq 0x11f88
testb %al, %al
je 0x9b0e
leaq 0x24240(%rip), %rax     # 0x2dd40
movq (%rax), %rax
movl 0x10(%rsp), %ecx
addl 0x34(%rax), %ecx
movl %ecx, 0x10(%rsp)
movl %r15d, %edi
pushq $0x8
popq %rsi
callq 0x11f88
testb %al, %al
je 0x9b31
leaq 0x2421c(%rip), %rax     # 0x2dd40
movq 0x8(%rax), %rax
addl 0x34(%rax), %ebx
movl %ebx, 0x14(%rsp)
jmp 0x9b5a
movl %r15d, %edi
pushq $0x7
popq %rsi
callq 0x11f88
testb %al, %al
movl %ebx, 0x14(%rsp)
je 0x9b5a
leaq 0x241f5(%rip), %rax     # 0x2dd40
movq 0x8(%rax), %rax
movl 0x10(%rsp), %ecx
addl 0x34(%rax), %ecx
movl %ecx, 0x10(%rsp)
movq %rbp, %rdi
callq 0x6490
movl %eax, %ebx
movq %rbp, %rdi
pushq $0x64
popq %rsi
callq 0xaa96
testq %rax, %rax
je 0x9cd2
movq %rax, %rbp
incq %rbp
movq %rbp, %rdi
callq 0x6490
movl %eax, 0x30(%rsp)
movq 0x18(%rsp), %rax
leaq 0x241ba(%rip), %rcx     # 0x2dd50
cmpq %rax, (%rcx)
je 0x9ba5
movq 0x38(%rsp), %rax
movl (%rax), %r13d
jmp 0x9bf7
leaq 0x23c9c(%rip), %rax     # 0x2d848
movq (%rax), %rax
leaq 0x34(%rax), %rcx
testq %rax, %rax
cmoveq 0x38(%rsp), %rcx
movl (%rcx), %r13d
xorl %edi, %edi
xorl %esi, %esi
callq 0x11f88
testb %al, %al
je 0x9bda
leaq 0x2416d(%rip), %rax     # 0x2dd40
movq (%rax), %rax
subl 0x34(%rax), %r13d
movl %r15d, %edi
xorl %esi, %esi
callq 0x11f88
testb %al, %al
je 0x9bf7
leaq 0x24151(%rip), %rax     # 0x2dd40
movq 0x8(%rax), %rax
subl 0x34(%rax), %r13d
movl %ebx, 0x34(%rsp)
testb %r14b, %r14b
je 0x9c13
movq %r12, %rdi
movl %r15d, %esi
callq 0x11364
movl 0x10(%rsp), %ebx
addl %eax, %ebx
jmp 0x9c17
movl 0x10(%rsp), %ebx
addl 0x28(%r12), %r13d
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x11364
movl %eax, %r15d
movq %r12, %rdi
callq 0x113fb
movl %eax, %r14d
pushq $0x14
popq %rdi
xorl %eax, %eax
callq 0xc004
addl %r13d, %r15d
pushq $0x15
popq %rcx
subl %r15d, %ecx
addl %ebx, %r14d
addl %r14d, %eax
incl %eax
cmpl %ecx, %eax
movq 0x40(%rsp), %r15
jl 0x9cb0
movl 0x34(%rsp), %edi
movl 0x30(%rsp), %esi
callq 0xc025
movl %eax, %ebx
movq %r12, %rdi
callq 0x1145b
movl %eax, %r13d
pushq $0x8
popq %rdi
callq 0x933b
movb $0x1, %cl
movl %ecx, 0x24(%rsp)
testb %al, %al
jne 0x9c97
movq 0x18(%rsp), %rax
leaq 0x240be(%rip), %rcx     # 0x2dd50
cmpq %rax, (%rcx)
je 0x9cb0
addl 0x14(%rsp), %ebx
addl %r13d, %ebx
testl %ebx, %ebx
movl $0x0, %eax
cmovlel %eax, %ebx
movq 0x18(%rsp), %rax
subl %ebx, 0x30(%rax)
movq %rbp, %rdi
pushq $0x2f
popq %rsi
callq 0xaa96
leaq 0x1(%rax), %rbp
testq %rax, %rax
movl 0x2c(%rsp), %r14d
movl 0x28(%rsp), %r13d
jne 0x9a88
movl 0x24(%rsp), %eax
andb $0x1, %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq