#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int rand();
int roll(int, int *, int *, int *, int *, int *);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  srand((unsigned)time(NULL));
  int dice;
  int bhealth = 1000;
  int phealth = 500;
  int absorb = 0, finished = 0, immune = 0, weakened = 0;
  printf("+===================================================================="
         "==+\n"
         "|     BossFight v1.0.0 Copyright (C) 2010  William Breathitt Gray    "
         "  |\n"
         "+===================================================================="
         "==+\n"
         "|  This program comes with ABSOLUTELY NO WARRANTY. This is free      "
         "  |\n"
         "|  software, and you are welcome to redistribute it under certain    "
         "  |\n"
         "|  conditions; for further details, please refer to the GNU General  "
         "  |\n"
         "|  Public License provided with this program.                        "
         "  |\n"
         "+===================================================================="
         "==+\n\n");
  printf("YOU HAVE ENCOUNTERED A BOSS!\n"
         "He has %d HP and must be destroyed before he kills you. You have %d "
         "HP.\n\n",
         bhealth, phealth);
  do {
    printf("Enter any character to roll the dice (q to exit)...\n");
    if (getchar() == 'q') {
      printf("GOODBYE! :)\n");
      return 0;
    } else {
      while (getchar() != '\n')
        ;
    }
    printf("\n");
    dice = rand() % 100;
    printf("You rolled a %02d.\n", dice);
    finished = roll(dice, &bhealth, &phealth, &absorb, &immune, &weakened);
  } while (!finished);
  printf("Enter any character to exit...\n");
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x3e8,-0xc(%rbp)
movl   $0x1f4,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0x1086(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0x10df(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0x71,%eax
jne    1206 <main+0xa6>
lea    0x10f3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a5 <main+0x145>
jmp    120b <main+0xab>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1223 <main+0xc3>
jmp    120b <main+0xab>
jmp    1228 <main+0xc8>
lea    0x1019(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0x10a1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
lea    -0x1c(%rbp),%r8
lea    -0x20(%rbp),%r9
call   1070 <roll@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cb <main+0x6b>
lea    0x1077(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x3e8,0x14(%rsp)
movl   $0x1f4,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
lea    0xe29(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x1f4,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10d5(%rip),%r12
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%rbx
lea    0x8(%rsp),%rbp
lea    0x4(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0x71,%al
je     12b0 <main+0x130>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
jne    1230 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
movslq %eax,%r15
imul   $0x51eb851f,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%r15d
lea    0xdf7(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%edi
lea    0x14(%rsp),%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
mov    %rbp,%r8
mov    %r14,%r9
call   1090 <roll@plt>
test   %eax,%eax
je     1210 <main+0x90>
lea    0x1056(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
jmp    12bc <main+0x13c>
lea    0x1060(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [586 x i8] c"+======================================================================+\0A| BossFight v1.0.0 Copyright (C) 2010 William Breathitt Gray |\0A+======================================================================+\0A| This program comes with ABSOLUTELY NO WARRANTY. This is free |\0A| software, and you are welcome to redistribute it under certain |\0A| conditions; for further details, please refer to the GNU General |\0A| Public License provided with this program. |\0A+======================================================================+\0A\0A\00"
@.str.1 = [103 x i8] c"YOU HAVE ENCOUNTERED A BOSS!\0AHe has %d HP and must be destroyed before he kills you. You have %d HP.\0A\0A\00"
@.str.2 = [53 x i8] c"Enter any character to roll the dice (q to exit)...\0A\00"
@.str.3 = [13 x i8] c"GOODBYE! :)\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [20 x i8] c"You rolled a %02d.\0A\00"
@.str.6 = [32 x i8] c"Enter any character to exit...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i64 @time(i32* null)
%10 = trunc i64 %9 to i32
%11 = call i32 @srand(i32 %10)
store i32 1000, i32* %3
store i32 500, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([586 x i8], [586 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14)
br label %16
16: ; preds = %38, %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%18 = call signext i8 (...) @getchar()
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 113
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %45
23: ; preds = %16
br label %24
24: ; preds = %28, %23
%25 = call signext i8 (...) @getchar()
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %24
br label %24
29: ; preds = %24
br label %30
30: ; preds = %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 (...) @rand()
%33 = srem i32 %32, 100
store i32 %33, i32* %2
%34 = load i32, i32* %2
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %2
%37 = call i32 @roll(i32 %36, i32* %3, i32* %4, i32* %5, i32* %7, i32* %8)
store i32 %37, i32* %6
br label %38
38: ; preds = %30
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
%41 = xor i1 %40, true
br i1 %41, label %16, label %42
42: ; preds = %38
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%44 = call signext i8 (...) @getchar()
store i32 0, i32* %1
br label %45
45: ; preds = %42, %21
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str.1 = [103 x i8] c"YOU HAVE ENCOUNTERED A BOSS!\0AHe has %d HP and must be destroyed before he kills you. You have %d HP.\0A\0A\00"
@.str.5 = [20 x i8] c"You rolled a %02d.\0A\00"
@str = [585 x i8] c"+======================================================================+\0A| BossFight v1.0.0 Copyright (C) 2010 William Breathitt Gray |\0A+======================================================================+\0A| This program comes with ABSOLUTELY NO WARRANTY. This is free |\0A| software, and you are welcome to redistribute it under certain |\0A| conditions; for further details, please refer to the GNU General |\0A| Public License provided with this program. |\0A+======================================================================+\0A\00"
@str.7 = [52 x i8] c"Enter any character to roll the dice (q to exit)...\00"
@str.8 = [31 x i8] c"Enter any character to exit...\00"
@str.9 = [12 x i8] c"GOODBYE! :)\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = tail call i64 @time(i32* null)
%7 = trunc i64 %6 to i32
%8 = tail call i32 @srand(i32 %7)
%9 = bitcast i32* %1 to i8*
store i32 1000, i32* %1
%10 = bitcast i32* %2 to i8*
store i32 500, i32* %2
%11 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%12 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%13 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([585 x i8], [585 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([103 x i8], [103 x i8]* @.str.1, i64 0, i64 0), i32 1000, i32 500)
br label %16
16: ; preds = %25, %0
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.7, i64 0, i64 0))
%18 = call signext i8 (...) @getchar()
%19 = icmp eq i8 %18, 113
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
br label %35
22: ; preds = %16, %22
%23 = call signext i8 (...) @getchar()
%24 = icmp eq i8 %23, 10
br i1 %24, label %25, label %22
25: ; preds = %22
%26 = call i32 @putchar(i32 10)
%27 = call i32 (...) @rand()
%28 = srem i32 %27, 100
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = call i32 @roll(i32 %28, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5)
%31 = icmp eq i32 %30, 0
br i1 %31, label %16, label %32
32: ; preds = %25
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
%34 = call signext i8 (...) @getchar()
br label %35
35: ; preds = %32, %20
ret i32 0
}