#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int method1(int);
int method2(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("[Usage] %s filename\n", argv[0]);
    return 1;
  }
  for (unsigned i = 1; i < argc; ++i) {
    printf("File: %s\n", argv[i]);
    int f = open(argv[i], O_RDONLY);
    if (f == -1) {
      printf("Can't open.\n");
      continue;
    }
    uint16_t ret1 = method1(f);
    printf("method1: %04x\n", ret1);
    lseek(f, 0, SEEK_SET);
    uint16_t ret2 = method2(f);
    printf("method2: %04x\n", ret2);
    close(f);
  }
  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    11a1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126e <main+0x10e>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1267 <main+0x107>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1206 <main+0xa6>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1259 <main+0xf9>
mov    -0x18(%rbp),%edi
call   1030 <method1@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    0x2dac(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    -0x18(%rbp),%edi
call   1070 <method2@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <main+0x48>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jge    119e <main+0x2e>
mov    (%rbx),%rsi
lea    0xe73(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    1242 <main+0xd2>
mov    %edi,%r15d
mov    $0x1,%r12d
lea    0xe67(%rip),%r14
mov    0x2e33(%rip),%r13
jmp    1212 <main+0xa2>
nopw   0x0(%rax,%rax,1)
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <method1@plt>
lea    0xe4f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %ebp,%edi
call   1080 <method2@plt>
lea    0xe35(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
add    $0x1,%r12
cmp    %r12,%r15
je     1240 <main+0xd0>
mov    (%rbx,%r12,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx,%r12,8),%rdi
mov    0x0(%r13),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x50>
lea    0xe04(%rip),%rdi
call   1030 <puts@plt>
jmp    1209 <main+0x99>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"[Usage] %s filename\0A\00"
@.str.1 = [10 x i8] c"File: %s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [13 x i8] c"Can't open.\0A\00"
@.str.3 = [15 x i8] c"method1: %04x\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [15 x i8] c"method2: %04x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %58
17: ; preds = %2
store i32 1, i32* %6
br label %18
18: ; preds = %54, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %57
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = load i32, i32* %6
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i8**, i8*** %5
%30 = load i32, i32* %6
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = load i32, i32* @O_RDONLY
%35 = call i32 @open(i8* %33, i32 %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %22
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %54
40: ; preds = %22
%41 = load i32, i32* %7
%42 = call i32 @method1(i32 %41)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %7
%46 = load i32, i32* @SEEK_SET
%47 = call i32 @lseek(i32 %45, i32 0, i32 %46)
%48 = load i32, i32* %7
%49 = call i32 @method2(i32 %48)
store i32 %49, i32* %9
%50 = load i32, i32* %9
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %7
%53 = call i32 @close(i32 %52)
br label %54
54: ; preds = %40, %38
%55 = load i32, i32* %6
%56 = add i32 %55, 1
store i32 %56, i32* %6
br label %18
57: ; preds = %18
store i32 0, i32* %3
br label %58
58: ; preds = %57, %12
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [21 x i8] c"[Usage] %s filename\0A\00"
@.str.1 = [10 x i8] c"File: %s\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [15 x i8] c"method1: %04x\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [15 x i8] c"method2: %04x\0A\00"
@str = [12 x i8] c"Can't open.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %31
9: ; preds = %4, %28
%10 = phi i64 [ 1, %4 ], [ %29, %28 ]
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %11
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* %14, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %28
20: ; preds = %9
%21 = tail call i32 @method1(i32 %16)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @SEEK_SET
%24 = tail call i32 @lseek(i32 %16, i32 0, i32 %23)
%25 = tail call i32 @method2(i32 %16)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = tail call i32 @close(i32 %16)
br label %28
28: ; preds = %20, %18
%29 = add nuw nsw i64 %10, 1
%30 = icmp eq i64 %29, %5
br i1 %30, label %31, label %9
31: ; preds = %28, %6
%32 = phi i32 [ 1, %6 ], [ 0, %28 ]
ret i32 %32
}