#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 atoi(char *);
scalar_t__ clash(int *, int *);
int /*<<< orphan*/ draw_dice(int *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ isalpha(char);
int /*<<< orphan*/ printf(char *, ...);
int roll();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char tolower(char);
int main(int argc, char *argv[]) {
  int ak, df, c, dloss, aloss;
  int adice[3], ddice[2];
  char yesno;
  srand(time(NULL));
  do {
    if (argc == 3) {
      ak = atoi(argv[1]);
      df = atoi(argv[2]);
      argc = 1;
    } else {
      printf("\nHow many in the attacking army? ");
      scanf("%d", &ak);
      printf("\nHow many in the defending army? ");
      scanf("%d", &df);
    }
    yesno = 'y';
    while (ak > 0 && df > 0 && tolower(yesno) != 'n') {
      aloss = dloss = 0;
      printf("\nAttacker's Roll : ");
      for (c = 0; c < 3; c++)
        if (ak > c)
          adice[c] = roll();
        else
          adice[c] = 0;
      draw_dice(adice, (ak > 3) ? 3 : ak);
      printf("\nDefender's Roll : ");
      for (c = 0; c < 2; c++)
        if (df > c)
          ddice[c] = roll();
        else
          ddice[c] = 0;
      draw_dice(ddice, (df > 2) ? 2 : df);
      (clash(adice, ddice)) ? dloss++ : aloss++;
      if (ak > 1 && df > 1)
        (clash(adice, ddice)) ? dloss++ : aloss++;
      printf("\nAttacker loses %d, Defender loses %d\n", aloss, dloss);
      ak -= aloss;
      df -= dloss;
      printf("\n%d attacking\n%d defending\n", ak, df);
      if (ak <= 10 && df > 0 && ak > 0) {
        printf("\nDoes the Attacker wish to continue? (y/n) ");
        do {
          yesno = getchar();
        } while (!isalpha(yesno));
      }
    }
    printf("\nFinal results:\nAttacker %d\nDefender %d", ak, df);
    printf("\n\nAgain? (y/n) ");
    do {
      yesno = getchar();
    } while (!isalpha(yesno));
  } while (tolower(yesno) == 'y');
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
cmpl   $0x3,-0x8(%rbp)
jne    121c <main+0x5c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x8(%rbp)
jmp    1258 <main+0x98>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecf(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   10b0 <scanf@plt>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <scanf@plt>
movb   $0x79,-0x39(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x3a(%rbp)
jle    128f <main+0xcf>
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x3a(%rbp)
jle    128f <main+0xcf>
movsbl -0x39(%rbp),%edi
call   1090 <tolower@plt>
movsbl %al,%eax
cmp    $0x6e,%eax
setne  %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
test   $0x1,%al
jne    129f <main+0xdf>
jmp    14d6 <main+0x316>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    130d <main+0x14d>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    12ee <main+0x12e>
mov    $0x0,%al
call   10e0 <roll@plt>
mov    %eax,%ecx
movslq -0x1c(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
jmp    12fa <main+0x13a>
movslq -0x1c(%rbp),%rax
movl   $0x0,-0x30(%rbp,%rax,4)
jmp    12ff <main+0x13f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12c2 <main+0x102>
lea    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpl   $0x3,-0x14(%rbp)
jle    132c <main+0x16c>
mov    $0x3,%eax
mov    %eax,-0x4c(%rbp)
jmp    1332 <main+0x172>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x4c(%rbp),%esi
call   1030 <draw_dice@plt>
lea    0xd13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    139e <main+0x1de>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    137f <main+0x1bf>
mov    $0x0,%al
call   10e0 <roll@plt>
mov    %eax,%ecx
movslq -0x1c(%rbp),%rax
mov    %ecx,-0x38(%rbp,%rax,4)
jmp    138b <main+0x1cb>
movslq -0x1c(%rbp),%rax
movl   $0x0,-0x38(%rbp,%rax,4)
jmp    1390 <main+0x1d0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1353 <main+0x193>
lea    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpl   $0x2,-0x18(%rbp)
jle    13bd <main+0x1fd>
mov    $0x2,%eax
mov    %eax,-0x5c(%rbp)
jmp    13c3 <main+0x203>
mov    -0x18(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x5c(%rbp),%esi
call   1030 <draw_dice@plt>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <clash@plt>
cmp    $0x0,%rax
je     13f4 <main+0x234>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    13fd <main+0x23d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    143f <main+0x27f>
cmpl   $0x1,-0x18(%rbp)
jle    143f <main+0x27f>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <clash@plt>
cmp    $0x0,%rax
je     1436 <main+0x276>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    143f <main+0x27f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xc20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xc1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0xa,-0x14(%rbp)
jg     14d1 <main+0x311>
cmpl   $0x0,-0x18(%rbp)
jle    14d1 <main+0x311>
cmpl   $0x0,-0x14(%rbp)
jle    14d1 <main+0x311>
lea    0xc0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x39(%rbp)
movsbl -0x39(%rbp),%edi
call   10a0 <isalpha@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    14a9 <main+0x2e9>
jmp    14d1 <main+0x311>
jmp    125c <main+0x9c>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xbf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x39(%rbp)
movsbl -0x39(%rbp),%edi
call   10a0 <isalpha@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    14f8 <main+0x338>
jmp    1520 <main+0x360>
movsbl -0x39(%rbp),%edi
call   1090 <tolower@plt>
movsbl %al,%eax
cmp    $0x79,%eax
je     11e6 <main+0x26>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x20(%rsp)
mov    %edi,0x8(%rsp)
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0x14(%rsp),%r13
lea    0xc(%rsp),%r14
nop
cmpl   $0x3,0x8(%rsp)
je     1250 <main+0x90>
lea    0xe02(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xef4(%rip),%rbx
mov    %rbx,%rdi
mov    %rsp,%rsi
call   10b0 <scanf@plt>
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
lea    0x4(%rsp),%rsi
call   10b0 <scanf@plt>
mov    (%rsp),%r12d
mov    0x4(%rsp),%edx
test   %r12d,%r12d
jg     1284 <main+0xc4>
jmp    1478 <main+0x2b8>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x20(%rsp),%rbx
mov    0x8(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r12d
mov    %eax,(%rsp)
mov    0x10(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edx
mov    %eax,0x4(%rsp)
movl   $0x1,0x8(%rsp)
test   %r12d,%r12d
jle    1478 <main+0x2b8>
test   %edx,%edx
jle    1478 <main+0x2b8>
mov    $0x79,%r15b
nop
movsbl %r15b,%edi
call   1090 <tolower@plt>
cmp    $0x6e,%al
je     1470 <main+0x2b0>
lea    0xd9c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%esi
test   %esi,%esi
jle    12f0 <main+0x130>
xor    %eax,%eax
call   10e0 <roll@plt>
mov    (%rsp),%esi
mov    %eax,0x14(%rsp)
cmp    $0x1,%esi
jle    12f8 <main+0x138>
xor    %ebx,%ebx
xor    %eax,%eax
call   10e0 <roll@plt>
mov    (%rsp),%esi
mov    %eax,0x18(%rsp)
cmp    $0x3,%esi
jl     1302 <main+0x142>
xor    %eax,%eax
call   10e0 <roll@plt>
mov    %eax,%ebx
mov    (%rsp),%esi
jmp    1302 <main+0x142>
nopl   0x0(%rax)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x18(%rsp)
xor    %ebx,%ebx
mov    %ebx,0x1c(%rsp)
cmp    $0x3,%esi
mov    $0x3,%eax
cmovge %eax,%esi
mov    %r13,%rdi
call   1030 <draw_dice@plt>
lea    0xd38(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    1360 <main+0x1a0>
xor    %ebx,%ebx
xor    %eax,%eax
call   10e0 <roll@plt>
mov    0x4(%rsp),%esi
mov    %eax,0xc(%rsp)
cmp    $0x2,%esi
jl     136a <main+0x1aa>
xor    %eax,%eax
call   10e0 <roll@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%esi
jmp    136a <main+0x1aa>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movl   $0x0,0xc(%rsp)
xor    %ebx,%ebx
mov    %ebx,0x10(%rsp)
cmp    $0x2,%esi
mov    $0x2,%eax
cmovge %eax,%esi
mov    %r14,%rdi
call   1030 <draw_dice@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1070 <clash@plt>
xor    %ebx,%ebx
xor    %ebp,%ebp
test   %rax,%rax
sete   %bl
setne  %bpl
cmpl   $0x2,(%rsp)
jl     13e0 <main+0x220>
cmpl   $0x2,0x4(%rsp)
jl     13e0 <main+0x220>
mov    %rax,%r12
mov    %r13,%rdi
mov    %r14,%rsi
call   1070 <clash@plt>
test   %rax,%rax
je     13c8 <main+0x208>
cmp    $0x1,%r12
mov    $0x2,%ebp
sbb    $0x0,%ebp
jmp    13e0 <main+0x220>
cmp    $0x1,%r12
mov    $0x1,%ebx
adc    $0x0,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xc85(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%esi
sub    %ebx,%esi
mov    %esi,(%rsp)
mov    0x4(%rsp),%edx
sub    %ebp,%edx
mov    %edx,0x4(%rsp)
lea    0xc88(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%r12d
mov    0x4(%rsp),%edx
test   %r12d,%r12d
jle    145e <main+0x29e>
cmp    $0xa,%r12d
jg     145e <main+0x29e>
test   %edx,%edx
jle    145e <main+0x29e>
lea    0xc7f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%r15d
movsbl %al,%edi
call   10a0 <isalpha@plt>
test   %eax,%eax
je     1440 <main+0x280>
mov    (%rsp),%r12d
mov    0x4(%rsp),%edx
test   %r12d,%r12d
jle    1478 <main+0x2b8>
test   %edx,%edx
jg     1290 <main+0xd0>
jmp    1478 <main+0x2b8>
nopl   (%rax)
mov    (%rsp),%r12d
mov    0x4(%rsp),%edx
lea    0xc5c(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc73(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
movsbl %al,%ebx
mov    %ebx,%edi
call   10a0 <isalpha@plt>
test   %eax,%eax
je     14a0 <main+0x2e0>
mov    %ebx,%edi
call   1090 <tolower@plt>
cmp    $0x79,%al
je     11f0 <main+0x30>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"\0AHow many in the attacking army? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"\0AHow many in the defending army? \00"
@.str.3 = [20 x i8] c"\0AAttacker's Roll : \00"
@.str.4 = [20 x i8] c"\0ADefender's Roll : \00"
@.str.5 = [39 x i8] c"\0AAttacker loses %d, Defender loses %d\0A\00"
@.str.6 = [28 x i8] c"\0A%d attacking\0A%d defending\0A\00"
@.str.7 = [44 x i8] c"\0ADoes the Attacker wish to continue? (y/n) \00"
@.str.8 = [40 x i8] c"\0AFinal results:\0AAttacker %d\0ADefender %d\00"
@.str.9 = [16 x i8] c"\0A\0AAgain? (y/n) \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [3 x i32]
%12 = alloca [2 x i32]
%13 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 @time(i32* null)
%15 = call i32 @srand(i32 %14)
br label %16
16: ; preds = %185, %2
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 3
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
store i32 1, i32* %4
br label %33
28: ; preds = %16
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
br label %33
33: ; preds = %28, %19
store i8 121, i8* %13
br label %34
34: ; preds = %171, %33
%35 = load i32, i32* %6
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %34
%38 = load i32, i32* %7
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load i8, i8* %13
%42 = call signext i8 @tolower(i8 signext %41)
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 110
br label %45
45: ; preds = %40, %37, %34
%46 = phi i1 [ false, %37 ], [ false, %34 ], [ %44, %40 ]
br i1 %46, label %47, label %172
47: ; preds = %45
store i32 0, i32* %9
store i32 0, i32* %10
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %8
br label %49
49: ; preds = %66, %47
%50 = load i32, i32* %8
%51 = icmp slt i32 %50, 3
br i1 %51, label %52, label %69
52: ; preds = %49
%53 = load i32, i32* %6
%54 = load i32, i32* %8
%55 = icmp sgt i32 %53, %54
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = call i32 (...) @roll()
%58 = load i32, i32* %8
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 %59
store i32 %57, i32* %60
br label %65
61: ; preds = %52
%62 = load i32, i32* %8
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 %63
store i32 0, i32* %64
br label %65
65: ; preds = %61, %56
br label %66
66: ; preds = %65
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
br label %49
69: ; preds = %49
%70 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 0
%71 = load i32, i32* %6
%72 = icmp sgt i32 %71, 3
br i1 %72, label %73, label %74
73: ; preds = %69
br label %76
74: ; preds = %69
%75 = load i32, i32* %6
br label %76
76: ; preds = %74, %73
%77 = phi i32 [ 3, %73 ], [ %75, %74 ]
%78 = call i32 @draw_dice(i32* %70, i32 %77)
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %8
br label %80
80: ; preds = %97, %76
%81 = load i32, i32* %8
%82 = icmp slt i32 %81, 2
br i1 %82, label %83, label %100
83: ; preds = %80
%84 = load i32, i32* %7
%85 = load i32, i32* %8
%86 = icmp sgt i32 %84, %85
br i1 %86, label %87, label %92
87: ; preds = %83
%88 = call i32 (...) @roll()
%89 = load i32, i32* %8
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 %90
store i32 %88, i32* %91
br label %96
92: ; preds = %83
%93 = load i32, i32* %8
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 %94
store i32 0, i32* %95
br label %96
96: ; preds = %92, %87
br label %97
97: ; preds = %96
%98 = load i32, i32* %8
%99 = add nsw i32 %98, 1
store i32 %99, i32* %8
br label %80
100: ; preds = %80
%101 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%102 = load i32, i32* %7
%103 = icmp sgt i32 %102, 2
br i1 %103, label %104, label %105
104: ; preds = %100
br label %107
105: ; preds = %100
%106 = load i32, i32* %7
br label %107
107: ; preds = %105, %104
%108 = phi i32 [ 2, %104 ], [ %106, %105 ]
%109 = call i32 @draw_dice(i32* %101, i32 %108)
%110 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 0
%111 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%112 = call i64 @clash(i32* %110, i32* %111)
%113 = icmp ne i64 %112, 0
br i1 %113, label %114, label %117
114: ; preds = %107
%115 = load i32, i32* %9
%116 = add nsw i32 %115, 1
store i32 %116, i32* %9
br label %120
117: ; preds = %107
%118 = load i32, i32* %10
%119 = add nsw i32 %118, 1
store i32 %119, i32* %10
br label %120
120: ; preds = %117, %114
%121 = phi i32 [ %115, %114 ], [ %118, %117 ]
%122 = load i32, i32* %6
%123 = icmp sgt i32 %122, 1
br i1 %123, label %124, label %140
124: ; preds = %120
%125 = load i32, i32* %7
%126 = icmp sgt i32 %125, 1
br i1 %126, label %127, label %140
127: ; preds = %124
%128 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 0
%129 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%130 = call i64 @clash(i32* %128, i32* %129)
%131 = icmp ne i64 %130, 0
br i1 %131, label %132, label %135
132: ; preds = %127
%133 = load i32, i32* %9
%134 = add nsw i32 %133, 1
store i32 %134, i32* %9
br label %138
135: ; preds = %127
%136 = load i32, i32* %10
%137 = add nsw i32 %136, 1
store i32 %137, i32* %10
br label %138
138: ; preds = %135, %132
%139 = phi i32 [ %133, %132 ], [ %136, %135 ]
br label %140
140: ; preds = %138, %124, %120
%141 = load i32, i32* %10
%142 = load i32, i32* %9
%143 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %141, i32 %142)
%144 = load i32, i32* %10
%145 = load i32, i32* %6
%146 = sub nsw i32 %145, %144
store i32 %146, i32* %6
%147 = load i32, i32* %9
%148 = load i32, i32* %7
%149 = sub nsw i32 %148, %147
store i32 %149, i32* %7
%150 = load i32, i32* %6
%151 = load i32, i32* %7
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %150, i32 %151)
%153 = load i32, i32* %6
%154 = icmp sle i32 %153, 10
br i1 %154, label %155, label %171
155: ; preds = %140
%156 = load i32, i32* %7
%157 = icmp sgt i32 %156, 0
br i1 %157, label %158, label %171
158: ; preds = %155
%159 = load i32, i32* %6
%160 = icmp sgt i32 %159, 0
br i1 %160, label %161, label %171
161: ; preds = %158
%162 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0))
br label %163
163: ; preds = %165, %161
%164 = call signext i8 (...) @getchar()
store i8 %164, i8* %13
br label %165
165: ; preds = %163
%166 = load i8, i8* %13
%167 = call i32 @isalpha(i8 signext %166)
%168 = icmp ne i32 %167, 0
%169 = xor i1 %168, true
br i1 %169, label %163, label %170
170: ; preds = %165
br label %171
171: ; preds = %170, %158, %155, %140
br label %34
172: ; preds = %45
%173 = load i32, i32* %6
%174 = load i32, i32* %7
%175 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i32 %173, i32 %174)
%176 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
br label %177
177: ; preds = %179, %172
%178 = call signext i8 (...) @getchar()
store i8 %178, i8* %13
br label %179
179: ; preds = %177
%180 = load i8, i8* %13
%181 = call i32 @isalpha(i8 signext %180)
%182 = icmp ne i32 %181, 0
%183 = xor i1 %182, true
br i1 %183, label %177, label %184
184: ; preds = %179
br label %185
185: ; preds = %184
%186 = load i8, i8* %13
%187 = call signext i8 @tolower(i8 signext %186)
%188 = sext i8 %187 to i32
%189 = icmp eq i32 %188, 121
br i1 %189, label %16, label %190
190: ; preds = %185
%191 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [34 x i8] c"\0AHow many in the attacking army? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"\0AHow many in the defending army? \00"
@.str.3 = [20 x i8] c"\0AAttacker's Roll : \00"
@.str.4 = [20 x i8] c"\0ADefender's Roll : \00"
@.str.5 = [39 x i8] c"\0AAttacker loses %d, Defender loses %d\0A\00"
@.str.6 = [28 x i8] c"\0A%d attacking\0A%d defending\0A\00"
@.str.7 = [44 x i8] c"\0ADoes the Attacker wish to continue? (y/n) \00"
@.str.8 = [40 x i8] c"\0AFinal results:\0AAttacker %d\0ADefender %d\00"
@.str.9 = [16 x i8] c"\0A\0AAgain? (y/n) \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [3 x i32]
%6 = alloca [2 x i32]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast [3 x i32]* %5 to i8*
%10 = bitcast [2 x i32]* %6 to i8*
%11 = tail call i32 @time(i32* null)
%12 = tail call i32 @srand(i32 %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
br label %21
21: ; preds = %149, %2
%22 = phi i32 [ %0, %2 ], [ %39, %149 ]
%23 = icmp eq i32 %22, 3
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i8*, i8** %13
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %3
%27 = load i8*, i8** %14
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %4
br label %36
29: ; preds = %21
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%34 = load i32, i32* %3
%35 = load i32, i32* %4
br label %36
36: ; preds = %29, %24
%37 = phi i32 [ %28, %24 ], [ %35, %29 ]
%38 = phi i32 [ %26, %24 ], [ %34, %29 ]
%39 = phi i32 [ 1, %24 ], [ %22, %29 ]
%40 = icmp sgt i32 %38, 0
%41 = icmp sgt i32 %37, 0
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %43, label %140
43: ; preds = %36, %133
%44 = phi i8 [ %136, %133 ], [ 121, %36 ]
%45 = call signext i8 @tolower(i8 signext %44)
%46 = icmp eq i8 %45, 110
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* %3
%49 = load i32, i32* %4
br label %140
50: ; preds = %43
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32, i32* %3
%53 = icmp sgt i32 %52, 0
br i1 %53, label %55, label %54
54: ; preds = %50
store i32 0, i32* %15
br label %59
55: ; preds = %50
%56 = call i32 (...) @roll()
%57 = load i32, i32* %3
store i32 %56, i32* %15
%58 = icmp sgt i32 %57, 1
br i1 %58, label %61, label %59
59: ; preds = %54, %55
%60 = phi i32 [ %57, %55 ], [ %52, %54 ]
store i32 0, i32* %17
br label %68
61: ; preds = %55
%62 = call i32 (...) @roll()
%63 = load i32, i32* %3
store i32 %62, i32* %18
%64 = icmp sgt i32 %63, 2
br i1 %64, label %65, label %68
65: ; preds = %61
%66 = call i32 (...) @roll()
%67 = load i32, i32* %3
br label %68
68: ; preds = %61, %59, %65
%69 = phi i32 [ %67, %65 ], [ %60, %59 ], [ %63, %61 ]
%70 = phi i32 [ %66, %65 ], [ 0, %59 ], [ 0, %61 ]
store i32 %70, i32* %19
%71 = icmp slt i32 %69, 3
%72 = select i1 %71, i32 %69, i32 3
%73 = call i32 @draw_dice(i32* %15, i32 %72)
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%75 = load i32, i32* %4
%76 = icmp sgt i32 %75, 0
br i1 %76, label %78, label %77
77: ; preds = %68
store i32 0, i32* %16
br label %85
78: ; preds = %68
%79 = call i32 (...) @roll()
%80 = load i32, i32* %4
store i32 %79, i32* %16
%81 = icmp sgt i32 %80, 1
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = call i32 (...) @roll()
%84 = load i32, i32* %4
br label %85
85: ; preds = %78, %77, %82
%86 = phi i32 [ %84, %82 ], [ %75, %77 ], [ %80, %78 ]
%87 = phi i32 [ %83, %82 ], [ 0, %77 ], [ 0, %78 ]
store i32 %87, i32* %20
%88 = icmp slt i32 %86, 2
%89 = select i1 %88, i32 %86, i32 2
%90 = call i32 @draw_dice(i32* %16, i32 %89)
%91 = call i64 @clash(i32* %15, i32* %16)
%92 = icmp eq i64 %91, 0
%93 = xor i1 %92, true
%94 = zext i1 %93 to i32
%95 = zext i1 %92 to i32
%96 = load i32, i32* %3
%97 = icmp sgt i32 %96, 1
%98 = load i32, i32* %4
%99 = icmp sgt i32 %98, 1
%100 = select i1 %97, i1 %99, i1 false
br i1 %100, label %101, label %108
101: ; preds = %85
%102 = call i64 @clash(i32* %15, i32* %16)
%103 = icmp eq i64 %102, 0
br i1 %103, label %106, label %104
104: ; preds = %101
%105 = select i1 %92, i32 1, i32 2
br label %108
106: ; preds = %101
%107 = select i1 %92, i32 2, i32 1
br label %108
108: ; preds = %104, %106, %85
%109 = phi i32 [ %105, %104 ], [ %94, %106 ], [ %94, %85 ]
%110 = phi i32 [ %95, %104 ], [ %107, %106 ], [ %95, %85 ]
%111 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %110, i32 %109)
%112 = load i32, i32* %3
%113 = sub nsw i32 %112, %110
store i32 %113, i32* %3
%114 = load i32, i32* %4
%115 = sub nsw i32 %114, %109
store i32 %115, i32* %4
%116 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %113, i32 %115)
%117 = load i32, i32* %3
%118 = icmp slt i32 %117, 11
%119 = load i32, i32* %4
%120 = icmp sgt i32 %119, 0
%121 = select i1 %118, i1 %120, i1 false
%122 = icmp sgt i32 %117, 0
%123 = and i1 %122, %121
br i1 %123, label %124, label %133
124: ; preds = %108
%125 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0))
br label %126
126: ; preds = %126, %124
%127 = call signext i8 (...) @getchar()
%128 = call i32 @isalpha(i8 signext %127)
%129 = icmp eq i32 %128, 0
br i1 %129, label %126, label %130
130: ; preds = %126
%131 = load i32, i32* %3
%132 = load i32, i32* %4
br label %133
133: ; preds = %130, %108
%134 = phi i32 [ %119, %108 ], [ %132, %130 ]
%135 = phi i32 [ %117, %108 ], [ %131, %130 ]
%136 = phi i8 [ %44, %108 ], [ %127, %130 ]
%137 = icmp sgt i32 %135, 0
%138 = icmp sgt i32 %134, 0
%139 = select i1 %137, i1 %138, i1 false
br i1 %139, label %43, label %140
140: ; preds = %133, %47, %36
%141 = phi i32 [ %37, %36 ], [ %49, %47 ], [ %134, %133 ]
%142 = phi i32 [ %38, %36 ], [ %48, %47 ], [ %135, %133 ]
%143 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i32 %142, i32 %141)
%144 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
br label %145
145: ; preds = %145, %140
%146 = call signext i8 (...) @getchar()
%147 = call i32 @isalpha(i8 signext %146)
%148 = icmp eq i32 %147, 0
br i1 %148, label %145, label %149
149: ; preds = %145
%150 = call signext i8 @tolower(i8 signext %146)
%151 = icmp eq i8 %150, 121
br i1 %151, label %21, label %152
152: ; preds = %149
%153 = call i32 @exit(i32 0)
unreachable
}