#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 BattleOne(int, int, int *);
int BattleThree(int, int, int *, int *);
int BattleTwo(int, int, int *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int Battle(int atkForce, int defForce, int *atkSurvivors, int *defSurvivors) {
  int won;
  srand(time(NULL));
  won = BattleOne(atkForce, defForce, defSurvivors);
  if (won < 0)
    won = BattleTwo(*atkSurvivors, *defSurvivors, atkSurvivors, defSurvivors);
  if (won < 0)
    won = BattleThree(*atkSurvivors, *defSurvivors, atkSurvivors, defSurvivors);
  return won;
}


x86 assembly (clang, -O0):
<Battle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <BattleOne@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ae <Battle+0x5e>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1050 <BattleTwo@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11d4 <Battle+0x84>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <BattleThree@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Battle>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r15,%rdx
call   1060 <BattleOne@plt>
test   %eax,%eax
jns    1194 <Battle+0x44>
mov    (%r14),%edi
mov    (%r15),%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <BattleTwo@plt>
test   %eax,%eax
js     119f <Battle+0x4f>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%edi
mov    (%r15),%esi
mov    %r14,%rdx
mov    %r15,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <BattleThree@plt>

LLVM IR (-O0):
define i32 @Battle(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* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = load i32*, i32** %8
%15 = call i32 @BattleOne(i32 %12, i32 %13, i32* %14)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %4
%19 = load i32*, i32** %7
%20 = load i32, i32* %19
%21 = load i32*, i32** %8
%22 = load i32, i32* %21
%23 = load i32*, i32** %7
%24 = load i32*, i32** %8
%25 = call i32 @BattleTwo(i32 %20, i32 %22, i32* %23, i32* %24)
store i32 %25, i32* %9
br label %26
26: ; preds = %18, %4
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = load i32*, i32** %7
%31 = load i32, i32* %30
%32 = load i32*, i32** %8
%33 = load i32, i32* %32
%34 = load i32*, i32** %7
%35 = load i32*, i32** %8
%36 = call i32 @BattleThree(i32 %31, i32 %33, i32* %34, i32* %35)
store i32 %36, i32* %9
br label %37
37: ; preds = %29, %26
%38 = load i32, i32* %9
ret i32 %38
}

LLVM IR (-O2):
define i32 @Battle(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = tail call i32 @BattleOne(i32 %0, i32 %1, i32* %3)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %4
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = tail call i32 @BattleTwo(i32 %10, i32 %11, i32* %2, i32* %3)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = tail call i32 @BattleThree(i32 %15, i32 %16, i32* %2, i32* %3)
br label %18
18: ; preds = %4, %14, %9
%19 = phi i32 [ %17, %14 ], [ %12, %9 ], [ %7, %4 ]
ret i32 %19
}