#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int foo(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  if (argc < 2)
    return 0;
  int b;
  FILE *f = fopen(argv[1], "r");
  if (f == NULL)
    return 0;
  fscanf(f, "%d", &b);
  fclose(f);
  printf("%d\n", foo(b));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    117c <main+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <main+0x95>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ab <main+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <main+0x95>
mov    -0x20(%rbp),%rdi
lea    0xe4c(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%edi
call   1060 <foo@plt>
mov    %eax,%esi
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x2,%edi
jl     11aa <main+0x5a>
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11a5 <main+0x55>
mov    %rax,%rbx
lea    0xe89(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%edi
call   1060 <foo@plt>
lea    0xe67(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
xor    %eax,%eax
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %17, label %11
11: ; preds = %5
%12 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%13 = call i32 @fclose(i32* %9)
%14 = load i32, i32* %3
%15 = call i32 @foo(i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %5, %11
br label %18
18: ; preds = %2, %17
ret i32 0
}