#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*/ scanf(char *, int *);
int take_wager(int available_credits, int previous_wager) {
  int wager, total_wager;
  printf("How many of your %d credits would you like to wager?  ",
         available_credits);
  scanf("%d", &wager);
  if (wager < 1) {
    printf("Nice try, but you must wager a positive number!\n");
    return -1;
  }
  total_wager = previous_wager + wager;
  if (total_wager > available_credits) {
    printf("Your total wager of %d is more than you have!\n", total_wager);
    printf("You only have %d available credits, try again.\n",
           available_credits);
    return -1;
  }
  return wager;
}


x86 assembly (clang, -O0):
<take_wager>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%esi
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0x10(%rbp)
jge    1173 <take_wager+0x53>
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <take_wager+0x9c>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    11b6 <take_wager+0x96>
mov    -0x14(%rbp),%esi
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xef7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <take_wager+0x9c>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<take_wager>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xec2(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee9(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    1188 <take_wager+0x58>
add    %eax,%ebp
cmp    %ebx,%ebp
jle    1199 <take_wager+0x69>
lea    0xecd(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeec(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1194 <take_wager+0x64>
lea    0xf0a(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"How many of your %d credits would you like to wager? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [49 x i8] c"Nice try, but you must wager a positive number!\0A\00"
@.str.3 = [47 x i8] c"Your total wager of %d is more than you have!\0A\00"
@.str.4 = [48 x i8] c"You only have %d available credits, try again.\0A\00"
define i32 @take_wager(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
15: ; preds = %2
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = add nsw i32 %16, %17
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = load i32, i32* %4
%21 = icmp sgt i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %15
%23 = load i32, i32* %7
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %25)
store i32 -1, i32* %3
br label %29
27: ; preds = %15
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %27, %22, %13
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [55 x i8] c"How many of your %d credits would you like to wager? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [47 x i8] c"Your total wager of %d is more than you have!\0A\00"
@.str.4 = [48 x i8] c"You only have %d available credits, try again.\0A\00"
@str = [48 x i8] c"Nice try, but you must wager a positive number!\00"
define i32 @take_wager(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
br label %17
11: ; preds = %2
%12 = add nsw i32 %7, %1
%13 = icmp sgt i32 %12, %0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %17
17: ; preds = %11, %14, %9
%18 = phi i32 [ -1, %9 ], [ -1, %14 ], [ %7, %11 ]
ret i32 %18
}