#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 BattleTwo(int atkForce, int defForce, int *atkSurvivors,
              int *defSurvivors) {
  if (atkForce > defForce) {
    *atkSurvivors = atkForce - (defForce * (20 + rand() % 21)) / 100;
    *defSurvivors = defForce - (atkForce * (30 + rand() % 41)) / 100;
  } else {
    *atkSurvivors = atkForce - (defForce * (30 + rand() % 71)) / 100;
    *defSurvivors = defForce - (atkForce * (20 + rand() % 21)) / 100;
  }
  if (*atkSurvivors <= 0) {
    atkSurvivors = 0;
    return 0;
  } else if (*defSurvivors <= 0) {
    *defSurvivors = 0;
    return 1;
  } else
    return -1;
}


x86 assembly (clang, -O0):
<BattleTwo>:
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
cmp    -0xc(%rbp),%eax
jle    11a5 <BattleTwo+0x95>
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    $0x15,%esi
cltd
idiv   %esi
mov    -0x2c(%rbp),%eax
add    $0x14,%edx
imul   %edx,%eax
mov    $0x64,%esi
cltd
idiv   %esi
sub    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
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    $0x29,%esi
cltd
idiv   %esi
mov    -0x24(%rbp),%eax
add    $0x1e,%edx
imul   %edx,%eax
mov    $0x64,%esi
cltd
idiv   %esi
sub    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    1213 <BattleTwo+0x103>
mov    -0x8(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    -0x40(%rbp),%ecx
mov    $0x47,%esi
cltd
idiv   %esi
mov    -0x3c(%rbp),%eax
add    $0x1e,%edx
imul   %edx,%eax
mov    $0x64,%esi
cltd
idiv   %esi
sub    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    -0x38(%rbp),%ecx
mov    $0x15,%esi
cltd
idiv   %esi
mov    -0x34(%rbp),%eax
add    $0x14,%edx
imul   %edx,%eax
mov    $0x64,%esi
cltd
idiv   %esi
sub    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1234 <BattleTwo+0x124>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
jmp    125e <BattleTwo+0x14e>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1257 <BattleTwo+0x147>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    125e <BattleTwo+0x14e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BattleTwo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r12
mov    %esi,%r13d
mov    %edi,%ebx
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <rand@plt>
cmp    %r13d,%ebx
mov    $0x15,%ecx
mov    $0x47,%esi
cmovg  %ecx,%esi
cltd
idiv   %esi
lea    0x1e(%rdx),%eax
add    $0x14,%edx
cmp    %r13d,%ebx
mov    $0x29,%ebp
cmovle %ecx,%ebp
cmovle %eax,%edx
imul   %r13d,%edx
movslq %edx,%rax
imul   $0xffffffffae147ae1,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
add    %ebx,%eax
mov    %eax,(%r12)
xor    %eax,%eax
call   1030 <rand@plt>
cltd
idiv   %ebp
lea    0x14(%rdx),%eax
add    $0x1e,%edx
cmp    %r13d,%ebx
cmovle %eax,%edx
imul   %ebx,%edx
movslq %edx,%rax
imul   $0xffffffffae147ae1,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
add    %r13d,%eax
mov    %eax,(%r14)
cmpl   $0x0,(%r12)
jle    11cc <BattleTwo+0xbc>
mov    $0xffffffff,%r15d
test   %eax,%eax
jg     11cc <BattleTwo+0xbc>
movl   $0x0,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @BattleTwo(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 = icmp sgt i32 %10, %11
br i1 %12, label %13, label %32
13: ; preds = %4
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 21
%18 = add nsw i32 20, %17
%19 = mul nsw i32 %15, %18
%20 = sdiv i32 %19, 100
%21 = sub nsw i32 %14, %20
%22 = load i32*, i32** %8
store i32 %21, i32* %22
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = call i32 (...) @rand()
%26 = srem i32 %25, 41
%27 = add nsw i32 30, %26
%28 = mul nsw i32 %24, %27
%29 = sdiv i32 %28, 100
%30 = sub nsw i32 %23, %29
%31 = load i32*, i32** %9
store i32 %30, i32* %31
br label %51
32: ; preds = %4
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = call i32 (...) @rand()
%36 = srem i32 %35, 71
%37 = add nsw i32 30, %36
%38 = mul nsw i32 %34, %37
%39 = sdiv i32 %38, 100
%40 = sub nsw i32 %33, %39
%41 = load i32*, i32** %8
store i32 %40, i32* %41
%42 = load i32, i32* %7
%43 = load i32, i32* %6
%44 = call i32 (...) @rand()
%45 = srem i32 %44, 21
%46 = add nsw i32 20, %45
%47 = mul nsw i32 %43, %46
%48 = sdiv i32 %47, 100
%49 = sub nsw i32 %42, %48
%50 = load i32*, i32** %9
store i32 %49, i32* %50
br label %51
51: ; preds = %32, %13
%52 = load i32*, i32** %8
%53 = load i32, i32* %52
%54 = icmp sle i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %51
store i32* null, i32** %8
store i32 0, i32* %5
br label %63
56: ; preds = %51
%57 = load i32*, i32** %9
%58 = load i32, i32* %57
%59 = icmp sle i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = load i32*, i32** %9
store i32 0, i32* %61
store i32 1, i32* %5
br label %63
62: ; preds = %56
store i32 -1, i32* %5
br label %63
63: ; preds = %62, %60, %55
%64 = load i32, i32* %5
ret i32 %64
}

LLVM IR (-O2):
define i32 @BattleTwo(i32 %0, i32 %1, i32* nocapture %2, i32* nocapture %3) {
%5 = icmp sgt i32 %0, %1
%6 = tail call i32 (...) @rand()
%7 = select i1 %5, i32 21, i32 71
%8 = select i1 %5, i32 20, i32 30
%9 = select i1 %5, i32 41, i32 21
%10 = select i1 %5, i32 30, i32 20
%11 = srem i32 %6, %7
%12 = add nsw i32 %11, %8
%13 = mul nsw i32 %12, %1
%14 = sdiv i32 %13, -100
%15 = add i32 %14, %0
store i32 %15, i32* %2
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, %9
%18 = add nsw i32 %17, %10
%19 = mul nsw i32 %18, %0
%20 = sdiv i32 %19, -100
%21 = add i32 %20, %1
store i32 %21, i32* %3
%22 = load i32, i32* %2
%23 = icmp slt i32 %22, 1
br i1 %23, label %27, label %24
24: ; preds = %4
%25 = icmp slt i32 %21, 1
br i1 %25, label %26, label %27
26: ; preds = %24
store i32 0, i32* %3
br label %27
27: ; preds = %24, %4, %26
%28 = phi i32 [ 1, %26 ], [ 0, %4 ], [ -1, %24 ]
ret i32 %28
}