#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 dice();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sleep(int);
int play(int bank, int player, int bet) {
  int scores = 0, result, i, a1, a2;
  while (1) {
    a1 = dice();
    sleep(1);
    a2 = dice();
    scores += a1 + a2;
    if (scores < 20) {
      printf("Scores = %d\n If you want to continue write 1, otherwise any "
             "other number\n",
             scores);
      scanf("%d", &i);
      if (i != 1) {
        result = 2;
        break;
      }
    } else {
      if (scores == 20) {
        printf("You win\n");
        result = 1;
        break;
      } else {
        printf("You lose\n");
        result = 0;
        break;
      }
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<play>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <dice@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    $0x0,%al
call   1030 <dice@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x14,-0x10(%rbp)
jge    11c8 <play+0x88>
mov    -0x10(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x1,-0x18(%rbp)
je     11c3 <play+0x83>
movl   $0x2,-0x14(%rbp)
jmp    120b <play+0xcb>
jmp    1206 <play+0xc6>
cmpl   $0x14,-0x10(%rbp)
jne    11ec <play+0xac>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    120b <play+0xcb>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
jmp    120b <play+0xcb>
jmp    1158 <play+0x18>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<play>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9d(%rip),%r14
lea    0xee0(%rip),%r15
lea    0xc(%rsp),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <dice@plt>
mov    %eax,%ebx
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <dice@plt>
add    %ebx,%ebp
add    %eax,%ebp
cmp    $0x13,%ebp
jg     11c8 <play+0x78>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
cmpl   $0x1,0xc(%rsp)
je     1180 <play+0x30>
mov    $0x2,%ebx
jmp    11e7 <play+0x97>
xor    %ebx,%ebx
cmp    $0x14,%ebp
sete   %bl
lea    0xe7f(%rip),%rax
lea    0xe6f(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [74 x i8] c"Scores = %d\0A If you want to continue write 1, otherwise any other number\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"You win\0A\00"
@.str.3 = [10 x i8] c"You lose\0A\00"
define i32 @play(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %12
12: ; preds = %3, %38
%13 = call i32 (...) @dice()
store i32 %13, i32* %10
%14 = call i32 @sleep(i32 1)
%15 = call i32 (...) @dice()
store i32 %15, i32* %11
%16 = load i32, i32* %10
%17 = load i32, i32* %11
%18 = add nsw i32 %16, %17
%19 = load i32, i32* %7
%20 = add nsw i32 %19, %18
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 20
br i1 %22, label %23, label %31
23: ; preds = %12
%24 = load i32, i32* %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%27 = load i32, i32* %9
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 2, i32* %8
br label %39
30: ; preds = %23
br label %38
31: ; preds = %12
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 20
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %8
br label %39
36: ; preds = %31
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %8
br label %39
38: ; preds = %30
br label %12
39: ; preds = %36, %34, %29
%40 = load i32, i32* %8
ret i32 %40
}

LLVM IR (-O2):
@.str = [74 x i8] c"Scores = %d\0A If you want to continue write 1, otherwise any other number\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@str = [9 x i8] c"You lose\00"
@str.4 = [8 x i8] c"You win\00"
define i32 @play(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
br label %6
6: ; preds = %14, %3
%7 = phi i32 [ 0, %3 ], [ %12, %14 ]
%8 = call i32 (...) @dice()
%9 = call i32 @sleep(i32 1)
%10 = call i32 (...) @dice()
%11 = add i32 %8, %7
%12 = add i32 %11, %10
%13 = icmp slt i32 %12, 20
br i1 %13, label %14, label %19
14: ; preds = %6
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i32 %12)
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %6, label %24
19: ; preds = %6
%20 = icmp eq i32 %12, 20
%21 = select i1 %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0)
%22 = zext i1 %20 to i32
%23 = call i32 @puts(i8* dereferenceable(1) %21)
br label %24
24: ; preds = %14, %19
%25 = phi i32 [ %22, %19 ], [ 2, %14 ]
ret i32 %25
}