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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int read_number(const char *fn) {
  char lin[80];
  FILE *fp;
  if ((fp = fopen(fn, "r")) == NULL)
    return (0);
  if (fgets(lin, 80, fp) == NULL) {
    fclose(fp);
    return (0);
  }
  fclose(fp);
  return (atoi(lin));
}


x86 assembly (clang, -O0):
<read_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jne    1176 <read_number+0x36>
movl   $0x0,-0x4(%rbp)
jmp    11bc <read_number+0x7c>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x50,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11a7 <read_number+0x67>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    11bc <read_number+0x7c>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x60(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_number>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1188 <read_number+0x48>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %r14,%r14
je     1188 <read_number+0x48>
mov    %rsp,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @read_number(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [80 x i8]
%5 = alloca i32*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %23
10: ; preds = %1
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%12 = load i32*, i32** %5
%13 = call i32* @fgets(i8* %11, i32 80, i32* %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32*, i32** %5
%17 = call i32 @fclose(i32* %16)
store i32 0, i32* %2
br label %23
18: ; preds = %10
%19 = load i32*, i32** %5
%20 = call i32 @fclose(i32* %19)
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %2
br label %23
23: ; preds = %18, %15, %9
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @read_number(i8* nocapture %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = call i32* @fgets(i8* %3, i32 80, i32* %4)
%8 = icmp eq i32* %7, null
%9 = call i32 @fclose(i32* %4)
br i1 %8, label %12, label %10
10: ; preds = %6
%11 = call i32 @atoi(i8* %3)
br label %12
12: ; preds = %6, %1, %10
%13 = phi i32 [ %11, %10 ], [ 0, %1 ], [ 0, %6 ]
ret i32 %13
}