#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(unsigned int);
int throw();
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  int bet, roll, point;
  char c;
  srand((unsigned)time(NULL));
  printf("Enter your bet: $");
  scanf("%d", &bet);
  putchar('\n');
  putchar('\n');
  puts("Rolling them bones...!");
  roll = throw();
  printf("\n%d\n\n", roll);
  switch (roll) {
  case 7:
  case 11:
    printf("- You win!\n");
    bet *= 2;
    break;
  case 2:
  case 3:
  case 12:
    printf("- Craps! You loose!\n");
    bet = 0;
    break;
  default:
    point = roll;
    printf("- Your point is now %d\n", point);
    while (1) {
      roll = throw();
      printf("\tYou rolled %d, point is %d.\n", roll, point);
      if (roll == point) {
        printf("\tYou win!\n");
        bet *= 2;
        break;
      }
      if (roll == 7) {
        printf("\tSeven out, you loose!\n");
        bet = 0;
        break;
      }
    }
  }
  printf("\n\nYou have now $%d.\n", bet);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x24(%rbp),%eax
lea    0xe64(%rip),%rdi
mov    %al,-0x19(%rbp)
call   1050 <printf@plt>
lea    0xe67(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1090 <scanf@plt>
mov    $0xa,%edi
mov    %edi,-0x20(%rbp)
call   1030 <putchar@plt>
mov    -0x20(%rbp),%edi
call   1030 <putchar@plt>
lea    0xe45(%rip),%rdi
call   1040 <puts@plt>
mov    -0x19(%rbp),%al
call   1070 <throw@plt>
mov    %eax,%ecx
mov    -0x19(%rbp),%al
mov    %ecx,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe3d(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
add    $0xfffffffe,%eax
sub    $0x2,%eax
jb     125a <main+0xea>
jmp    120b <main+0x9b>
mov    -0x18(%rbp),%eax
sub    $0x7,%eax
je     123e <main+0xce>
jmp    121c <main+0xac>
mov    -0x18(%rbp),%eax
sub    $0xb,%eax
je     123e <main+0xce>
jmp    122d <main+0xbd>
mov    -0x18(%rbp),%eax
sub    $0xc,%eax
je     125a <main+0xea>
jmp    1274 <main+0x104>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12ff <main+0x18f>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x8(%rbp)
jmp    12ff <main+0x18f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <throw@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    12d1 <main+0x161>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12fa <main+0x18a>
cmpl   $0x7,-0xc(%rbp)
jne    12f5 <main+0x185>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x8(%rbp)
jmp    12fa <main+0x18a>
jmp    128b <main+0x11b>
jmp    12ff <main+0x18f>
mov    -0x8(%rbp),%esi
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    0xe73(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe77(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1090 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <throw@plt>
mov    %eax,%ebx
lea    0xe57(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xc,%ebx
ja     1218 <main+0xa8>
mov    $0x100c,%eax
bt     %ebx,%eax
jae    1205 <main+0x95>
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,0xc(%rsp)
xor    %esi,%esi
jmp    126f <main+0xff>
mov    $0x880,%eax
bt     %ebx,%eax
jae    1218 <main+0xa8>
lea    0xe7b(%rip),%rdi
jmp    1260 <main+0xf0>
lea    0xe13(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe1b(%rip),%r14
nop
xor    %eax,%eax
call   1070 <throw@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %ebx,%ebp
je     1259 <main+0xe9>
cmp    $0x7,%ebp
jne    1230 <main+0xc0>
lea    0xe45(%rip),%rdi
jmp    11f4 <main+0x84>
lea    0xe53(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%esi
add    %esi,%esi
mov    %esi,0xc(%rsp)
lea    0xdf2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Enter your bet: $\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Rolling them bones...!\00"
@.str.3 = [6 x i8] c"\0A%d\0A\0A\00"
@.str.4 = [12 x i8] c"- You win!\0A\00"
@.str.5 = [21 x i8] c"- Craps! You loose!\0A\00"
@.str.6 = [24 x i8] c"- Your point is now %d\0A\00"
@.str.7 = [30 x i8] c"\09You rolled %d, point is %d.\0A\00"
@.str.8 = [11 x i8] c"\09You win!\0A\00"
@.str.9 = [24 x i8] c"\09Seven out, you loose!\0A\00"
@.str.10 = [21 x i8] c"\0A\0AYou have now $%d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 0, i32* %1
%6 = call i64 @time(i32* null)
%7 = trunc i64 %6 to i32
%8 = call i32 @srand(i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = call i32 @putchar(i8 signext 10)
%12 = call i32 @putchar(i8 signext 10)
%13 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (...) @throw()
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %3
switch i32 %17, label %24 [
i32 7, label %18
i32 11, label %18
i32 2, label %22
i32 3, label %22
i32 12, label %22
]
18: ; preds = %0, %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32, i32* %2
%21 = mul nsw i32 %20, 2
store i32 %21, i32* %2
br label %47
22: ; preds = %0, %0, %0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %2
br label %47
24: ; preds = %0
%25 = load i32, i32* %3
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %24, %45
%29 = call i32 (...) @throw()
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %30, i32 %31)
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %40
36: ; preds = %28
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%38 = load i32, i32* %2
%39 = mul nsw i32 %38, 2
store i32 %39, i32* %2
br label %46
40: ; preds = %28
%41 = load i32, i32* %3
%42 = icmp eq i32 %41, 7
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %2
br label %46
45: ; preds = %40
br label %28
46: ; preds = %43, %36
br label %47
47: ; preds = %46, %22, %18
%48 = load i32, i32* %2
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i32 %48)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Enter your bet: $\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Rolling them bones...!\00"
@.str.3 = [6 x i8] c"\0A%d\0A\0A\00"
@.str.6 = [24 x i8] c"- Your point is now %d\0A\00"
@.str.7 = [30 x i8] c"\09You rolled %d, point is %d.\0A\00"
@.str.10 = [21 x i8] c"\0A\0AYou have now $%d.\0A\00"
@str = [20 x i8] c"- Craps! You loose!\00"
@str.11 = [11 x i8] c"- You win!\00"
@str.12 = [23 x i8] c"\09Seven out, you loose!\00"
@str.13 = [10 x i8] c"\09You win!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 @time(i32* null)
%4 = trunc i64 %3 to i32
%5 = tail call i32 @srand(i32 %4)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = call i32 @putchar(i8 signext 10)
%9 = call i32 @putchar(i8 signext 10)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (...) @throw()
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %11)
switch i32 %11, label %19 [
i32 7, label %13
i32 11, label %13
i32 2, label %17
i32 3, label %17
i32 12, label %17
]
13: ; preds = %0, %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.11, i64 0, i64 0))
%15 = load i32, i32* %1
%16 = shl nsw i32 %15, 1
store i32 %16, i32* %1
br label %33
17: ; preds = %0, %0, %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
store i32 0, i32* %1
br label %33
19: ; preds = %0
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %11)
br label %21
21: ; preds = %29, %19
%22 = call i32 (...) @throw()
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %22, i32 %11)
%24 = icmp eq i32 %22, %11
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.13, i64 0, i64 0))
%27 = load i32, i32* %1
%28 = shl nsw i32 %27, 1
store i32 %28, i32* %1
br label %33
29: ; preds = %21
%30 = icmp eq i32 %22, 7
br i1 %30, label %31, label %21
31: ; preds = %29
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.12, i64 0, i64 0))
store i32 0, i32* %1
br label %33
33: ; preds = %25, %31, %17, %13
%34 = phi i32 [ %28, %25 ], [ 0, %31 ], [ 0, %17 ], [ %16, %13 ]
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i32 %34)
ret i32 0
}