#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 /*<<< orphan*/ foo(int, long);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, long *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc < 2)
    return 0;
  FILE *f = fopen(argv[1], "r");
  if (f == NULL)
    return 0;
  long x;
  fscanf(f, "%ld", &x);
  fclose(f);
  printf("%ld\n", foo(100, x));
  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    11eb <main+0x9b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <main+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    11eb <main+0x9b>
mov    -0x18(%rbp),%rdi
lea    0xe4c(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rsi
mov    $0x64,%edi
call   1060 <foo@plt>
mov    %eax,%esi
lea    0xe27(%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>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jl     11ab <main+0x5b>
mov    0x8(%rsi),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ab <main+0x5b>
mov    %rax,%rbx
lea    0xe89(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x8(%rsp),%rsi
mov    $0x64,%edi
call   1060 <foo@plt>
lea    0xe62(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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