#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 play(int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int bank = 10000, player = 100, bet, gr, i;
  while (1) {
    printf("Bank %d\tYour money %d\n Your bet = ", bank, player);
    scanf("%d", &bet);
    if (bet > player) {
      bet = player;
      printf("You don't have enough money, so your bet is %d\n", bet);
    } else {
      if (bet > bank) {
        bet = bank;
        printf("Bank don't have enough money, so your bet is %d\n", bet);
      }
    }
    gr = play(bank, player, bet);
    if (gr == 0) {
      player -= bet;
      bank += bet;
    } else {
      if (gr == 1) {
        player += bet;
        bank -= bet;
      }
    }
    bet = 0;
    if (player > 0) {
      printf("If you want to bet again write 1, otherwise any other number\n");
      scanf("%d", &i);
      if (i != 1)
        break;
    } else {
      printf("You don't have enough money to play again\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2710,-0x8(%rbp)
movl   $0x64,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1199 <main+0x69>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <main+0x91>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    11bc <main+0x8c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <main+0x91>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <play@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11f5 <main+0xc5>
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1218 <main+0xe8>
cmpl   $0x1,-0x14(%rbp)
jne    1213 <main+0xe3>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    1218 <main+0xe8>
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    125b <main+0x12b>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xde5(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x1,-0x18(%rbp)
je     1256 <main+0x126>
jmp    1273 <main+0x143>
jmp    126e <main+0x13e>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1273 <main+0x143>
jmp    114d <main+0x1d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x2710,%ebx
mov    $0x64,%ebp
lea    0xec7(%rip),%r15
mov    %rsp,%r12
lea    0xf4b(%rip),%r13
lea    0x4(%rsp),%r14
jmp    1195 <main+0x55>
nopl   (%rax)
movl   $0x0,(%rsp)
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <scanf@plt>
cmpl   $0x1,0x4(%rsp)
jne    1232 <main+0xf2>
lea    0xe64(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
mov    (%rsp),%eax
cmp    %ebp,%eax
jle    11d0 <main+0x90>
mov    %ebp,(%rsp)
lea    0xe63(%rip),%rdi
mov    %ebp,%esi
jmp    11e0 <main+0xa0>
nopw   0x0(%rax,%rax,1)
cmp    %ebx,%eax
jle    11e7 <main+0xa7>
mov    %ebx,(%rsp)
lea    0xe78(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <play@plt>
test   %eax,%eax
je     1210 <main+0xd0>
cmp    $0x1,%eax
jne    1170 <main+0x30>
mov    (%rsp),%eax
add    %eax,%ebp
sub    %eax,%ebx
jmp    1217 <main+0xd7>
nopl   0x0(%rax)
mov    (%rsp),%eax
sub    %eax,%ebp
add    %eax,%ebx
movl   $0x0,(%rsp)
test   %ebp,%ebp
jg     1177 <main+0x37>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Bank %d\09Your money %d\0A Your bet = \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [48 x i8] c"You don't have enough money, so your bet is %d\0A\00"
@.str.3 = [49 x i8] c"Bank don't have enough money, so your bet is %d\0A\00"
@.str.4 = [62 x i8] c"If you want to bet again write 1, otherwise any other number\0A\00"
@.str.5 = [43 x i8] c"You don't have enough money to play again\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 10000, i32* %2
store i32 100, i32* %3
br label %7
7: ; preds = %0, %65
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = icmp sgt i32 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %7
%16 = load i32, i32* %3
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %28
19: ; preds = %7
%20 = load i32, i32* %4
%21 = load i32, i32* %2
%22 = icmp sgt i32 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* %2
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %23, %19
br label %28
28: ; preds = %27, %15
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = call i32 @play(i32 %29, i32 %30, i32 %31)
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %28
%36 = load i32, i32* %4
%37 = load i32, i32* %3
%38 = sub nsw i32 %37, %36
store i32 %38, i32* %3
%39 = load i32, i32* %4
%40 = load i32, i32* %2
%41 = add nsw i32 %40, %39
store i32 %41, i32* %2
br label %53
42: ; preds = %28
%43 = load i32, i32* %5
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %52
45: ; preds = %42
%46 = load i32, i32* %4
%47 = load i32, i32* %3
%48 = add nsw i32 %47, %46
store i32 %48, i32* %3
%49 = load i32, i32* %4
%50 = load i32, i32* %2
%51 = sub nsw i32 %50, %49
store i32 %51, i32* %2
br label %52
52: ; preds = %45, %42
br label %53
53: ; preds = %52, %35
store i32 0, i32* %4
%54 = load i32, i32* %3
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %63
56: ; preds = %53
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.4, i64 0, i64 0))
%58 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%59 = load i32, i32* %6
%60 = icmp ne i32 %59, 1
br i1 %60, label %61, label %62
61: ; preds = %56
br label %66
62: ; preds = %56
br label %65
63: ; preds = %53
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
br label %66
65: ; preds = %62
br label %7
66: ; preds = %63, %61
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"Bank %d\09Your money %d\0A Your bet = \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [48 x i8] c"You don't have enough money, so your bet is %d\0A\00"
@.str.3 = [49 x i8] c"Bank don't have enough money, so your bet is %d\0A\00"
@str = [42 x i8] c"You don't have enough money to play again\00"
@str.6 = [61 x i8] c"If you want to bet again write 1, otherwise any other number\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
br label %5
5: ; preds = %34, %0
%6 = phi i32 [ 100, %0 ], [ %36, %34 ]
%7 = phi i32 [ 10000, %0 ], [ %35, %34 ]
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %6)
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, %6
br i1 %11, label %12, label %14
12: ; preds = %5
store i32 %6, i32* %1
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %6)
br label %18
14: ; preds = %5
%15 = icmp sgt i32 %10, %7
br i1 %15, label %16, label %18
16: ; preds = %14
store i32 %7, i32* %1
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %7)
br label %18
18: ; preds = %14, %16, %12
%19 = load i32, i32* %1
%20 = call i32 @play(i32 %7, i32 %6, i32 %19)
switch i32 %20, label %21 [
i32 0, label %22
i32 1, label %26
]
21: ; preds = %18
store i32 0, i32* %1
br label %34
22: ; preds = %18
%23 = load i32, i32* %1
%24 = sub nsw i32 %6, %23
%25 = add nsw i32 %23, %7
br label %30
26: ; preds = %18
%27 = load i32, i32* %1
%28 = add nsw i32 %27, %6
%29 = sub nsw i32 %7, %27
br label %30
30: ; preds = %26, %22
%31 = phi i32 [ %24, %22 ], [ %28, %26 ]
%32 = phi i32 [ %25, %22 ], [ %29, %26 ]
store i32 0, i32* %1
%33 = icmp sgt i32 %31, 0
br i1 %33, label %34, label %41
34: ; preds = %21, %30
%35 = phi i32 [ %7, %21 ], [ %32, %30 ]
%36 = phi i32 [ %6, %21 ], [ %31, %30 ]
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.6, i64 0, i64 0))
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%39 = load i32, i32* %2
%40 = icmp eq i32 %39, 1
br i1 %40, label %5, label %43
41: ; preds = %30
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %43
43: ; preds = %34, %41
ret i32 0
}