#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
long strtol(char *, char **, int);
int readInt() {
  char buf[BUFSIZ];
  char *p;
  long int i;
  if (fgets(buf, sizeof(buf), stdin) != NULL) {
    i = strtol(buf, &p, 10);
    if (buf[0] != '\n' && (*p == '\n' || *p == '\0'))
      return i;
  }
}


x86 assembly (clang, -O0):
<readInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    %eax,%esi
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11cf <readInt+0xaf>
mov    -0x38(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,-0x28(%rbp)
movsbl (%rax),%eax
cmp    $0xa,%eax
je     11ca <readInt+0xaa>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     11b7 <readInt+0x97>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ca <readInt+0xaa>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11d6 <readInt+0xb6>
jmp    11cf <readInt+0xaf>
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readInt>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e9e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1030 <fgets@plt>
test   %rax,%rax
je     117e <readInt+0x5e>
lea    -0x10(%rbp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
cmpb   $0xa,(%rbx)
je     117e <readInt+0x5e>
mov    -0x10(%rbp),%rcx
mov    (%rcx),%cl
cmp    $0xa,%cl
je     117e <readInt+0x5e>
test   %cl,%cl
jmp    117e <readInt+0x5e>
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@stdin = global i32 0
define i32 @readInt() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %2
%10 = alloca i8, i64 %8
store i64 %8, i64* %3
%11 = trunc i64 %8 to i32
%12 = load i32, i32* @stdin
%13 = call i32* @fgets(i8* %10, i32 %11, i32 %12)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %35
15: ; preds = %0
%16 = call i64 @strtol(i8* %10, i8** %4, i32 10)
store i64 %16, i64* %5
%17 = getelementptr inbounds i8, i8* %10, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 10
br i1 %20, label %21, label %34
21: ; preds = %15
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26, %21
%32 = load i64, i64* %5
%33 = trunc i64 %32 to i32
store i32 %33, i32* %1
store i32 1, i32* %6
br label %36
34: ; preds = %26, %15
br label %35
35: ; preds = %34, %0
store i32 0, i32* %6
br label %36
36: ; preds = %35, %31
%37 = load i8*, i8** %2
%38 = load i32, i32* %6
switch i32 %38, label %41 [
i32 0, label %39
i32 1, label %39
]
39: ; preds = %36, %36
%40 = load i32, i32* %1
ret i32 %40
41: ; preds = %36
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stdin = global i32 0
define i32 @readInt() {
%1 = alloca i8*
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = bitcast i8** %1 to i8*
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %4, i32 %2, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %18, label %9
9: ; preds = %0
%10 = call i64 @strtol(i8* %4, i8** %1, i32 10)
%11 = load i8, i8* %4
%12 = icmp eq i8 %11, 10
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = load i8*, i8** %1
%15 = load i8, i8* %14
switch i8 %15, label %18 [
i8 10, label %16
i8 0, label %16
]
16: ; preds = %13, %13
%17 = trunc i64 %10 to i32
br label %18
18: ; preds = %0, %9, %13, %16
%19 = phi i32 [ %17, %16 ], [ undef, %13 ], [ undef, %9 ], [ undef, %0 ]
ret i32 %19
}