#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*/ int64_t;

/* Variables and functions */
#define EOF 128
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int scanf(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strerror(int /*<<< orphan*/);
int64_t read_int() {
  int64_t n;
  switch (scanf("%ld", &n)) {
  case 0:
    fprintf(stderr, "read_int failed: expected integer\n");
    break;
  case EOF:
    fprintf(stderr, "read_int failed: %s\n",
            (ferror(stdin) ? strerror(errno) : "EOF"));
    break;
  default:
    return n;
  }
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
test   %eax,%eax
je     118d <read_int+0x3d>
jmp    117a <read_int+0x2a>
mov    -0x8(%rbp),%eax
sub    $0x80,%eax
je     11a9 <read_int+0x59>
jmp    120d <read_int+0xbd>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1216 <read_int+0xc6>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%eax
je     11e3 <read_int+0x93>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,-0x18(%rbp)
jmp    11f3 <read_int+0xa3>
lea    0xe52(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11f3 <read_int+0xa3>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rdx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1216 <read_int+0xc6>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<read_int>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
cmp    $0x80,%eax
je     117b <read_int+0x2b>
test   %eax,%eax
je     119f <read_int+0x4f>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e56(%rip),%rax
mov    (%rax),%ebx
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
test   %eax,%eax
jne    11b8 <read_int+0x68>
lea    0xe9f(%rip),%rdx
jmp    11c9 <read_int+0x79>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d9 <read_int+0x89>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rdx
lea    0xe57(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"read_int failed: expected integer\0A\00"
@.str.2 = [21 x i8] c"read_int failed: %s\0A\00"
@stdin = global i32 0
@errno = global i32 0
@.str.3 = [4 x i8] c"EOF\00"
@EXIT_FAILURE = global i32 0
define i32 @read_int() {
%1 = alloca i32
%2 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
switch i32 %2, label %18 [
i32 0, label %3
i32 128, label %6
]
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %20
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = load i32, i32* @stdin
%9 = call i32 @ferror(i32 %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
br label %15
14: ; preds = %6
br label %15
15: ; preds = %14, %11
%16 = phi i8* [ %13, %11 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %14 ]
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %20
18: ; preds = %0
%19 = load i32, i32* %1
ret i32 %19
20: ; preds = %15, %3
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"read_int failed: expected integer\0A\00"
@.str.2 = [21 x i8] c"read_int failed: %s\0A\00"
@stdin = global i32 0
@errno = global i32 0
@.str.3 = [4 x i8] c"EOF\00"
@EXIT_FAILURE = global i32 0
define i32 @read_int() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
switch i32 %3, label %18 [
i32 0, label %4
i32 128, label %7
]
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %20
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* @stdin
%10 = call i32 @ferror(i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
br label %15
15: ; preds = %7, %12
%16 = phi i8* [ %14, %12 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %7 ]
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %20
18: ; preds = %0
%19 = load i32, i32* %1
ret i32 %19
20: ; preds = %15, %4
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
}