#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;
char getchar();
int /*<<< orphan*/ reg_set(int, int, int);
int /*<<< orphan*/ scanf(char *, int *);
void sys_get_int(int reg) {
  int in;
  scanf("%d", &in);
  reg_set(0x1, reg, in);
  char ch;
  while ((ch = getchar()) != '\n' && ch != EOF)
    ;
  reg_set(0x0, 0x1, 0x0);
}


x86 assembly (clang, -O0):
<sys_get_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    $0x1,%edi
call   1040 <reg_set@plt>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0xa(%rbp)
je     118c <sys_get_int+0x5c>
movsbl -0x9(%rbp),%eax
mov    0x2e67(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
test   $0x1,%al
jne    119c <sys_get_int+0x6c>
jmp    11a1 <sys_get_int+0x71>
jmp    115b <sys_get_int+0x2b>
xor    %edx,%edx
mov    $0x1,%esi
mov    %edx,%edi
call   1040 <reg_set@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_get_int>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xec2(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%edx
mov    $0x1,%edi
mov    %ebx,%esi
call   1040 <reg_set@plt>
mov    0x2e89(%rip),%rbx
nop
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     116f <sys_get_int+0x3f>
cmp    (%rbx),%al
jne    1160 <sys_get_int+0x30>
xor    %edi,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <reg_set@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@EOF = global i8 0
define void @sys_get_int(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %2
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%6 = load i32, i32* %2
%7 = load i32, i32* %3
%8 = call i32 @reg_set(i32 1, i32 %6, i32 %7)
br label %9
9: ; preds = %21, %1
%10 = call signext i8 (...) @getchar()
store i8 %10, i8* %4
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 10
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i8, i8* %4
%15 = sext i8 %14 to i32
%16 = load i8, i8* @EOF
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %15, %17
br label %19
19: ; preds = %13, %9
%20 = phi i1 [ false, %9 ], [ %18, %13 ]
br i1 %20, label %21, label %22
21: ; preds = %19
br label %9
22: ; preds = %19
%23 = call i32 @reg_set(i32 0, i32 1, i32 0)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@EOF = global i8 0
define void @sys_get_int(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%5 = load i32, i32* %2
%6 = call i32 @reg_set(i32 1, i32 %0, i32 %5)
br label %7
7: ; preds = %7, %1
%8 = call signext i8 (...) @getchar()
%9 = icmp ne i8 %8, 10
%10 = load i8, i8* @EOF
%11 = icmp ne i8 %8, %10
%12 = select i1 %9, i1 %11, i1 false
br i1 %12, label %7, label %13
13: ; preds = %7
%14 = call i32 @reg_set(i32 0, i32 1, i32 0)
ret void
}