#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 EOF;
int /*<<< orphan*/ exit(int);
int fprintf(int /*<<< orphan*/, char *, ...);
int scanf(char *, int *);
int /*<<< orphan*/ stderr;
int getint(char *prompt) {
  char *terminate = "\n";
  int result;
  int i = 0;
  while (fprintf(stderr, "%s%s", prompt, terminate), result = scanf("%d", &i),
         result != 1 && result != EOF) {
    fprintf(stderr, "Sorry, I didn't understand that...\n");
  }
  if (result == 1) {
    return i;
  } else {
    fprintf(stderr, "Giving up ... can't read input\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<getint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xee7(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe9a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
lea    0xe91(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x14(%rbp)
mov    %al,-0x19(%rbp)
je     11a1 <getint+0x71>
mov    -0x14(%rbp),%eax
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11b1 <getint+0x81>
jmp    11cd <getint+0x9d>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    114e <getint+0x1e>
cmpl   $0x1,-0x14(%rbp)
jne    11e0 <getint+0xb0>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<getint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
movl   $0x0,0x4(%rsp)
mov    0x2e8b(%rip),%r14
mov    (%r14),%edi
lea    0xea9(%rip),%rsi
lea    0xecc(%rip),%rcx
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xe96(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     11ef <getint+0xbf>
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%eax
je     11ef <getint+0xbf>
lea    0xe70(%rip),%r15
lea    0xe93(%rip),%r12
lea    0xe67(%rip),%r13
lea    0x4(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14),%edi
lea    0xe4e(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     11ef <getint+0xbf>
mov    0x2dfd(%rip),%rcx
cmp    (%rcx),%eax
jne    11b0 <getint+0x80>
cmp    $0x1,%eax
jne    1207 <getint+0xd7>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%edi
lea    0xe1b(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i32 0
@.str.3 = [36 x i8] c"Sorry, I didn't understand that...\0A\00"
@.str.4 = [32 x i8] c"Giving up ... can't read input\0A\00"
define i32 @getint(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
store i32 0, i32* %5
br label %6
6: ; preds = %20, %1
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %2
%9 = load i8*, i8** %3
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %9)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %6
%15 = load i32, i32* %4
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br label %18
18: ; preds = %14, %6
%19 = phi i1 [ false, %6 ], [ %17, %14 ]
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %6
23: ; preds = %18
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = load i32, i32* %5
ret i32 %27
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i32 0
@.str.3 = [36 x i8] c"Sorry, I didn't understand that...\0A\00"
@.str.4 = [32 x i8] c"Giving up ... can't read input\0A\00"
define i32 @getint(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = load i32, i32* @stderr
%5 = call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%7 = icmp ne i32 %6, 1
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %6, %8
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %11, label %21
11: ; preds = %1, %11
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%17 = icmp ne i32 %16, 1
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %16, %18
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %11, label %21
21: ; preds = %11, %1
%22 = phi i32 [ %6, %1 ], [ %16, %11 ]
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i32, i32* %2
ret i32 %25
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
}