#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 */
unsigned long UINT_MAX;
unsigned int get_random_whole_number();
char *get_string();
unsigned long strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
unsigned int get_whole_number(void) {
  char *text;
  unsigned long input;
  text = get_string();
  if (text == NULL)
    return get_random_whole_number();
  input = strtoul(text, NULL, 0);
  if (input > UINT_MAX)
    return get_random_whole_number();
  return ((unsigned int)(input));
}


x86 assembly (clang, -O0):
<get_whole_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <get_string@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115d <get_whole_number+0x2d>
mov    $0x0,%al
call   1040 <get_random_whole_number@plt>
mov    %eax,-0x4(%rbp)
jmp    119a <get_whole_number+0x6a>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
jbe    1193 <get_whole_number+0x63>
mov    $0x0,%al
call   1040 <get_random_whole_number@plt>
mov    %eax,-0x4(%rbp)
jmp    119a <get_whole_number+0x6a>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_whole_number>:
push   %rax
xor    %eax,%eax
call   1030 <get_string@plt>
test   %rax,%rax
je     1155 <get_whole_number+0x25>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    0x2e98(%rip),%rcx
cmp    (%rcx),%rax
jbe    115d <get_whole_number+0x2d>
xor    %eax,%eax
pop    %rcx
jmp    1040 <get_random_whole_number@plt>
pop    %rcx
ret

LLVM IR (-O0):
@UINT_MAX = global i64 0
define i32 @get_whole_number() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = call i8* (...) @get_string()
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (...) @get_random_whole_number()
store i32 %8, i32* %1
br label %20
9: ; preds = %0
%10 = load i8*, i8** %2
%11 = call i64 @strtoul(i8* %10, i32* null, i32 0)
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = load i64, i64* @UINT_MAX
%14 = icmp ugt i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (...) @get_random_whole_number()
store i32 %16, i32* %1
br label %20
17: ; preds = %9
%18 = load i64, i64* %3
%19 = trunc i64 %18 to i32
store i32 %19, i32* %1
br label %20
20: ; preds = %17, %15, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@UINT_MAX = global i64 0
define i32 @get_whole_number() {
%1 = tail call i8* (...) @get_string()
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 (...) @get_random_whole_number()
br label %13
5: ; preds = %0
%6 = tail call i64 @strtoul(i8* nocapture %1, i32* null, i32 0)
%7 = load i64, i64* @UINT_MAX
%8 = icmp ugt i64 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 (...) @get_random_whole_number()
br label %13
11: ; preds = %5
%12 = trunc i64 %6 to i32
br label %13
13: ; preds = %11, %9, %3
%14 = phi i32 [ %4, %3 ], [ %10, %9 ], [ %12, %11 ]
ret i32 %14
}