#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int parse_int(int, int *);
int /*<<< orphan*/ stderr;
int try_parse_int(int fd, int *val, const char *pname) {
  int err;
  err = parse_int(fd, val);
  if (err)
    do {
      fprintf(stderr, "ERROR: ");
      fprintf(stderr, "error while parsing %s (%s)", pname,
              err == -1   ? "end of file"
              : err == -2 ? "not a number"
                          : "number too big");
      fprintf(stderr, "\n");
    } while (0);
  return err;
}


x86 assembly (clang, -O0):
<try_parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <parse_int@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11e7 <try_parse_int+0xc7>
jmp    1151 <try_parse_int+0x31>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1196 <try_parse_int+0x76>
lea    0xe97(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    11b2 <try_parse_int+0x92>
mov    -0x1c(%rbp),%edx
lea    0xe9d(%rip),%rax
lea    0xe89(%rip),%rcx
cmp    $0xfffffffe,%edx
cmove  %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%edi
mov    -0x38(%rbp),%rcx
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11e7 <try_parse_int+0xc7>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<try_parse_int>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
call   1040 <parse_int@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1193 <try_parse_int+0x73>
mov    0x2ea6(%rip),%r15
mov    (%r15),%edi
lea    0xebc(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
cmp    $0xfffffffe,%ebx
lea    0xed8(%rip),%rax
lea    0xede(%rip),%rdx
cmove  %rax,%rdx
cmp    $0xffffffff,%ebx
lea    0xeb7(%rip),%rcx
cmovne %rdx,%rcx
lea    0xe90(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
lea    0xec0(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [8 x i8] c"ERROR: \00"
@.str.1 = [28 x i8] c"error while parsing %s (%s)\00"
@.str.2 = [12 x i8] c"end of file\00"
@.str.3 = [13 x i8] c"not a number\00"
@.str.4 = [15 x i8] c"number too big\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @try_parse_int(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%8 = load i32, i32* %4
%9 = load i32*, i32** %5
%10 = call i32 @parse_int(i32 %8, i32* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %33
13: ; preds = %3
br label %14
14: ; preds = %13
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %14
br label %27
22: ; preds = %14
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, -2
%25 = zext i1 %24 to i64
%26 = select i1 %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0)
br label %27
27: ; preds = %22, %21
%28 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %21 ], [ %26, %22 ]
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %28)
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %27
br label %33
33: ; preds = %32, %3
%34 = load i32, i32* %7
ret i32 %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [8 x i8] c"ERROR: \00"
@.str.1 = [28 x i8] c"error while parsing %s (%s)\00"
@.str.2 = [12 x i8] c"end of file\00"
@.str.3 = [13 x i8] c"not a number\00"
@.str.4 = [15 x i8] c"number too big\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @try_parse_int(i32 %0, i32* %1, i8* %2) {
%4 = tail call i32 @parse_int(i32 %0, i32* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = icmp eq i32 %4, -1
%11 = icmp eq i32 %4, -2
%12 = select i1 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0)
%13 = select i1 %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %12
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %13)
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %17
17: ; preds = %6, %3
ret i32 %4
}