#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int rand();
int BattleThree(int atkForce, int defForce, int *atkSurvivors,
                int *defSurvivors) {
  if (atkForce > 2 * defForce) {
    *defSurvivors = defForce - (atkForce * (rand() % 11)) / 100;
    return 1;
  } else if (atkForce > defForce) {
    *atkSurvivors = atkForce - (defForce * (10 + rand() % 241)) / 100;
    if ((*atkSurvivors <= 0) && (defForce > 5)) {
      defForce = 5;
      return 0;
    } else
      return 1;
  } else if (defForce >= 2 * atkForce) {
    *atkSurvivors = atkForce - (defForce * (rand() % 11)) / 100;
    return 0;
  } else {
    *defSurvivors = defForce - (atkForce * (10 + rand() % 241)) / 100;
    if ((*defSurvivors <= 0) && (atkForce > 5)) {
      atkForce = 5;
      return 1;
    } else
      return 0;
  }
}


x86 assembly (clang, -O0):
<BattleThree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jle    1177 <BattleThree+0x67>
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    -0x28(%rbp),%ecx
mov    $0xb,%esi
cltd
idiv   %esi
mov    -0x24(%rbp),%eax
imul   %edx,%eax
mov    $0x64,%esi
cltd
idiv   %esi
sub    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12a9 <BattleThree+0x199>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11f0 <BattleThree+0xe0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    -0x30(%rbp),%ecx
mov    $0xf1,%esi
cltd
idiv   %esi
mov    -0x2c(%rbp),%eax
add    $0xa,%edx
imul   %edx,%eax
mov    $0x64,%esi
cltd
idiv   %esi
sub    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jg     11e4 <BattleThree+0xd4>
cmpl   $0x5,-0xc(%rbp)
jle    11e4 <BattleThree+0xd4>
movl   $0x5,-0xc(%rbp)
movl   $0x0,-0x4(%rbp)
jmp    12a9 <BattleThree+0x199>
movl   $0x1,-0x4(%rbp)
jmp    12a9 <BattleThree+0x199>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jl     1241 <BattleThree+0x131>
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    -0x38(%rbp),%ecx
mov    $0xb,%esi
cltd
idiv   %esi
mov    -0x34(%rbp),%eax
imul   %edx,%eax
mov    $0x64,%esi
cltd
idiv   %esi
sub    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    12a9 <BattleThree+0x199>
mov    -0xc(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    -0x40(%rbp),%ecx
mov    $0xf1,%esi
cltd
idiv   %esi
mov    -0x3c(%rbp),%eax
add    $0xa,%edx
imul   %edx,%eax
mov    $0x64,%esi
cltd
idiv   %esi
sub    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jg     12a2 <BattleThree+0x192>
cmpl   $0x5,-0x8(%rbp)
jle    12a2 <BattleThree+0x192>
movl   $0x5,-0x8(%rbp)
movl   $0x1,-0x4(%rbp)
jmp    12a9 <BattleThree+0x199>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BattleThree>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r12
mov    %esi,%ebx
mov    %edi,%r14d
lea    (%rbx,%rbx,1),%eax
cmp    %edi,%eax
jge    1173 <BattleThree+0x63>
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x2e8ba2e9,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rcx,%rdx,2),%ecx
sub    %ecx,%eax
imul   %r14d,%eax
cltq
imul   $0xffffffffae147ae1,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
add    %ebx,%eax
mov    %eax,(%r12)
mov    $0x1,%al
jmp    1278 <BattleThree+0x168>
mov    %rdx,%r15
cmp    %ebx,%r14d
jle    11d6 <BattleThree+0xc6>
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x10fef011,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x24,%rcx
add    %edx,%ecx
imul   $0xf1,%ecx,%ecx
neg    %ecx
add    %ecx,%eax
add    $0xa,%eax
imul   %ebx,%eax
cltq
imul   $0xffffffffae147ae1,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
add    %r14d,%eax
mov    %eax,(%r15)
test   %eax,%eax
setg   %cl
cmp    $0x6,%ebx
setl   %al
or     %cl,%al
jmp    1278 <BattleThree+0x168>
lea    (%r14,%r14,1),%ebp
xor    %eax,%eax
call   1030 <rand@plt>
cmp    %ebx,%ebp
jle    1239 <BattleThree+0x129>
movslq %eax,%rcx
imul   $0x10fef011,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x24,%rcx
add    %edx,%ecx
imul   $0xf1,%ecx,%ecx
neg    %ecx
add    %ecx,%eax
add    $0xa,%eax
imul   %r14d,%eax
cltq
imul   $0xffffffffae147ae1,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
add    %ebx,%eax
mov    %eax,(%r12)
test   %eax,%eax
setle  %cl
cmp    $0x6,%r14d
setge  %al
and    %cl,%al
jmp    1278 <BattleThree+0x168>
cltq
imul   $0x2e8ba2e9,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rcx,%rdx,2),%ecx
sub    %ecx,%eax
imul   %ebx,%eax
cltq
imul   $0xffffffffae147ae1,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
add    %r14d,%eax
mov    %eax,(%r15)
xor    %eax,%eax
movzbl %al,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @BattleThree(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%10 = load i32, i32* %6
%11 = load i32, i32* %7
%12 = mul nsw i32 2, %11
%13 = icmp sgt i32 %10, %12
br i1 %13, label %14, label %23
14: ; preds = %4
%15 = load i32, i32* %7
%16 = load i32, i32* %6
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 11
%19 = mul nsw i32 %16, %18
%20 = sdiv i32 %19, 100
%21 = sub nsw i32 %15, %20
%22 = load i32*, i32** %9
store i32 %21, i32* %22
store i32 1, i32* %5
br label %77
23: ; preds = %4
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %45
27: ; preds = %23
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = call i32 (...) @rand()
%31 = srem i32 %30, 241
%32 = add nsw i32 10, %31
%33 = mul nsw i32 %29, %32
%34 = sdiv i32 %33, 100
%35 = sub nsw i32 %28, %34
%36 = load i32*, i32** %8
store i32 %35, i32* %36
%37 = load i32*, i32** %8
%38 = load i32, i32* %37
%39 = icmp sle i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %27
%41 = load i32, i32* %7
%42 = icmp sgt i32 %41, 5
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 5, i32* %7
store i32 0, i32* %5
br label %77
44: ; preds = %40, %27
store i32 1, i32* %5
br label %77
45: ; preds = %23
%46 = load i32, i32* %7
%47 = load i32, i32* %6
%48 = mul nsw i32 2, %47
%49 = icmp sge i32 %46, %48
br i1 %49, label %50, label %59
50: ; preds = %45
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = call i32 (...) @rand()
%54 = srem i32 %53, 11
%55 = mul nsw i32 %52, %54
%56 = sdiv i32 %55, 100
%57 = sub nsw i32 %51, %56
%58 = load i32*, i32** %8
store i32 %57, i32* %58
store i32 0, i32* %5
br label %77
59: ; preds = %45
%60 = load i32, i32* %7
%61 = load i32, i32* %6
%62 = call i32 (...) @rand()
%63 = srem i32 %62, 241
%64 = add nsw i32 10, %63
%65 = mul nsw i32 %61, %64
%66 = sdiv i32 %65, 100
%67 = sub nsw i32 %60, %66
%68 = load i32*, i32** %9
store i32 %67, i32* %68
%69 = load i32*, i32** %9
%70 = load i32, i32* %69
%71 = icmp sle i32 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %59
%73 = load i32, i32* %6
%74 = icmp sgt i32 %73, 5
br i1 %74, label %75, label %76
75: ; preds = %72
store i32 5, i32* %6
store i32 1, i32* %5
br label %77
76: ; preds = %72, %59
store i32 0, i32* %5
br label %77
77: ; preds = %76, %75, %50, %44, %43, %14
%78 = load i32, i32* %5
ret i32 %78
}

LLVM IR (-O2):
define i32 @BattleThree(i32 %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = shl nsw i32 %1, 1
%6 = icmp slt i32 %5, %0
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 11
%10 = mul nsw i32 %9, %0
%11 = sdiv i32 %10, -100
%12 = add i32 %11, %1
store i32 %12, i32* %3
br label %43
13: ; preds = %4
%14 = icmp sgt i32 %0, %1
br i1 %14, label %15, label %25
15: ; preds = %13
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, 241
%18 = add nsw i32 %17, 10
%19 = mul nsw i32 %18, %1
%20 = sdiv i32 %19, -100
%21 = add i32 %20, %0
store i32 %21, i32* %2
%22 = icmp sgt i32 %21, 0
%23 = icmp slt i32 %1, 6
%24 = or i1 %23, %22
br label %43
25: ; preds = %13
%26 = shl nsw i32 %0, 1
%27 = icmp sgt i32 %26, %1
%28 = tail call i32 (...) @rand()
br i1 %27, label %34, label %29
29: ; preds = %25
%30 = srem i32 %28, 11
%31 = mul nsw i32 %30, %1
%32 = sdiv i32 %31, -100
%33 = add i32 %32, %0
store i32 %33, i32* %2
br label %43
34: ; preds = %25
%35 = srem i32 %28, 241
%36 = add nsw i32 %35, 10
%37 = mul nsw i32 %36, %0
%38 = sdiv i32 %37, -100
%39 = add i32 %38, %1
store i32 %39, i32* %3
%40 = icmp slt i32 %39, 1
%41 = icmp sgt i32 %0, 5
%42 = and i1 %41, %40
br label %43
43: ; preds = %34, %15, %29, %7
%44 = phi i1 [ true, %7 ], [ false, %29 ], [ %24, %15 ], [ %42, %34 ]
%45 = zext i1 %44 to i32
ret i32 %45
}