#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 atoi(char *);
char *file_read(char const *);
scalar_t__ file_size(char const *);
int /*<<< orphan*/ free(char *);
int file_readnum(const char *fname, int def) {
  char *s;
  int ret;
  if (!(file_size(fname) >= 0))
    return def;
  s = file_read(fname);
  if (!s)
    return def;
  ret = atoi(s);
  free(s);
  return ret;
}


x86 assembly (clang, -O0):
<file_readnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <file_size@plt>
cmp    $0x0,%rax
jge    116d <file_readnum+0x2d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <file_readnum+0x6b>
mov    -0x10(%rbp),%rdi
call   1050 <file_read@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1190 <file_readnum+0x50>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <file_readnum+0x6b>
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_readnum>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <file_size@plt>
test   %rax,%rax
js     1174 <file_readnum+0x34>
mov    %rbx,%rdi
call   1050 <file_read@plt>
test   %rax,%rax
je     1174 <file_readnum+0x34>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @file_readnum(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = call i64 @file_size(i8* %8)
%10 = icmp sge i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = load i32, i32* %5
store i32 %12, i32* %3
br label %26
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i8* @file_read(i8* %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = load i32, i32* %5
store i32 %19, i32* %3
br label %26
20: ; preds = %13
%21 = load i8*, i8** %6
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %7
%23 = load i8*, i8** %6
%24 = call i32 @free(i8* %23)
%25 = load i32, i32* %7
store i32 %25, i32* %3
br label %26
26: ; preds = %20, %18, %11
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @file_readnum(i8* %0, i32 %1) {
%3 = tail call i64 @file_size(i8* %0)
%4 = icmp sgt i64 %3, -1
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = tail call i8* @file_read(i8* %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i32 @atoi(i8* %6)
%10 = tail call i32 @free(i8* %6)
br label %11
11: ; preds = %5, %2, %8
%12 = phi i32 [ %9, %8 ], [ %1, %2 ], [ %1, %5 ]
ret i32 %12
}