#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 */
char EOF;
int INT_MIN;
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void read_stdin_int(int *val, char *msg, int neg) {
  char c;
  int i = INT_MIN;
  if (msg != NULL)
    printf("%s", msg);
  do {
    printf(">");
    scanf("%d", &i);
    while ((c = getchar()) != '\n' && c != EOF) {
    }
  } while (i == INT_MIN && !neg && i < 0);
  *val = i;
}


x86 assembly (clang, -O0):
<read_stdin_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116c <read_stdin_int+0x3c>
mov    -0x10(%rbp),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1171 <read_stdin_int+0x41>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7f(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1d(%rbp)
je     11c0 <read_stdin_int+0x90>
movsbl -0x15(%rbp),%eax
mov    0x2e33(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11d0 <read_stdin_int+0xa0>
jmp    11d5 <read_stdin_int+0xa5>
jmp    118f <read_stdin_int+0x5f>
jmp    11da <read_stdin_int+0xaa>
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
mov    0x2dfa(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1e(%rbp)
jne    120a <read_stdin_int+0xda>
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x1e(%rbp)
jne    120a <read_stdin_int+0xda>
cmpl   $0x0,-0x1c(%rbp)
setl   %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    1171 <read_stdin_int+0x41>
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_stdin_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rdi,%r14
mov    0x2e89(%rip),%r13
mov    0x0(%r13),%eax
mov    %eax,0x4(%rsp)
test   %rsi,%rsi
je     1172 <read_stdin_int+0x32>
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8a(%rip),%r15
lea    0x4(%rsp),%r12
mov    0x2e63(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x3e,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     11c0 <read_stdin_int+0x80>
cmp    0x0(%rbp),%al
jne    11b0 <read_stdin_int+0x70>
mov    0x4(%rsp),%eax
test   %eax,%eax
jns    11d2 <read_stdin_int+0x92>
test   %ebx,%ebx
jne    11d2 <read_stdin_int+0x92>
cmp    0x0(%r13),%eax
je     1190 <read_stdin_int+0x50>
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@INT_MIN = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c">\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i8 0
define void @read_stdin_int(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* @INT_MIN
store i32 %9, i32* %8
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %3
br label %16
16: ; preds = %43, %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
br label %19
19: ; preds = %31, %16
%20 = call signext i8 (...) @getchar()
store i8 %20, i8* %7
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i8, i8* %7
%25 = sext i8 %24 to i32
%26 = load i8, i8* @EOF
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %25, %27
br label %29
29: ; preds = %23, %19
%30 = phi i1 [ false, %19 ], [ %28, %23 ]
br i1 %30, label %31, label %32
31: ; preds = %29
br label %19
32: ; preds = %29
br label %33
33: ; preds = %32
%34 = load i32, i32* %8
%35 = load i32, i32* @INT_MIN
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %43
37: ; preds = %33
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %37
%41 = load i32, i32* %8
%42 = icmp slt i32 %41, 0
br label %43
43: ; preds = %40, %37, %33
%44 = phi i1 [ false, %37 ], [ false, %33 ], [ %42, %40 ]
br i1 %44, label %16, label %45
45: ; preds = %43
%46 = load i32, i32* %8
%47 = load i32*, i32** %4
store i32 %46, i32* %47
ret void
}

LLVM IR (-O2):
@INT_MIN = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i8 0
define void @read_stdin_int(i32* nocapture writeonly %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = load i32, i32* @INT_MIN
store i32 %6, i32* %4
%7 = icmp eq i8* %1, null
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %10
10: ; preds = %8, %3
%11 = icmp eq i32 %2, 0
br label %12
12: ; preds = %21, %10
%13 = call i32 @putchar(i32 62)
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
br label %15
15: ; preds = %15, %12
%16 = call signext i8 (...) @getchar()
%17 = icmp ne i8 %16, 10
%18 = load i8, i8* @EOF
%19 = icmp ne i8 %16, %18
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %15, label %21
21: ; preds = %15
%22 = load i32, i32* %4
%23 = load i32, i32* @INT_MIN
%24 = icmp eq i32 %22, %23
%25 = and i1 %11, %24
%26 = icmp slt i32 %22, 0
%27 = and i1 %26, %25
br i1 %27, label %12, label %28
28: ; preds = %21
store i32 %22, i32* %0
ret void
}