#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int parseheader(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int status = 0;
  if (argc == 1 ||
      (argc == 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")))) {
    printf("Usage: %s filename\nThis function parses the header of filename "
           "assuming filename is a pvp file.\n",
           argv[0]);
    return status;
  }
  int arg;
  for (arg = 1; arg < argc; arg++) {
    printf("%s\n", argv[arg]);
    FILE *fid = fopen(argv[arg], "r");
    if (fid == NULL) {
      fprintf(stderr, "Unable to open \"%s\": %s\n", argv[arg],
              strerror(errno));
      status = 1;
    } else {
      int status1 = parseheader(fid);
      if (status1 != 0)
        status = 1;
      fclose(fid);
    }
  }
  status = status == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
  return status;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11db <main+0x6b>
cmpl   $0x2,-0x8(%rbp)
jne    11f9 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe50(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11db <main+0x6b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11f9 <main+0x89>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1303 <main+0x193>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12d0 <main+0x160>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe34(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1297 <main+0x127>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xde7(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    12bd <main+0x14d>
mov    -0x20(%rbp),%rdi
call   1070 <parseheader@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     12b4 <main+0x144>
movl   $0x1,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    12c2 <main+0x152>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1200 <main+0x90>
cmpl   $0x0,-0x14(%rbp)
jne    12eb <main+0x17b>
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
jmp    12f7 <main+0x187>
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%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,%r13
cmp    $0x1,%edi
je     11b4 <main+0x44>
mov    %edi,%ebp
cmp    $0x2,%edi
jne    11cb <main+0x5b>
mov    0x8(%r13),%r14
lea    0xe6b(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11b4 <main+0x44>
lea    0xe5f(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    11d1 <main+0x61>
mov    0x0(%r13),%rsi
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    1286 <main+0x116>
jl     127d <main+0x10d>
mov    %ebp,%r12d
xor    %ebx,%ebx
mov    $0x1,%r14d
lea    0xe88(%rip),%r15
jmp    1216 <main+0xa6>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <parseheader@plt>
test   %eax,%eax
mov    $0x1,%eax
cmovne %eax,%ebx
mov    %rbp,%rdi
call   1030 <fclose@plt>
add    $0x1,%r14
cmp    %r14,%r12
je     1270 <main+0x100>
mov    0x0(%r13,%r14,8),%rsi
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
mov    0x0(%r13,%r14,8),%rdi
mov    %r15,%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    11f0 <main+0x80>
mov    0x2da0(%rip),%rax
mov    (%rax),%ebp
mov    0x0(%r13,%r14,8),%rbx
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %ebp,%edi
lea    0xe0f(%rip),%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    $0x1,%ebx
jmp    120d <main+0x9d>
test   %ebx,%ebx
je     127d <main+0x10d>
mov    0x2d55(%rip),%rax
jmp    1284 <main+0x114>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [97 x i8] c"Usage: %s filename\0AThis function parses the header of filename assuming filename is a pvp file.\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.5 = [25 x i8] c"Unable to open \22%s\22: %s\0A\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
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
store i32 0, i32* %6
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %27, label %12
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %33
15: ; preds = %12
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %21, %15, %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @printf(i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %6
store i32 %32, i32* %3
br label %86
33: ; preds = %21, %12
store i32 1, i32* %7
br label %34
34: ; preds = %73, %33
%35 = load i32, i32* %7
%36 = load i32, i32* %4
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %76
38: ; preds = %34
%39 = load i8**, i8*** %5
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %43)
%45 = load i8**, i8*** %5
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %50, i32** %8
%51 = load i32*, i32** %8
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %63
53: ; preds = %38
%54 = load i32, i32* @stderr
%55 = load i8**, i8*** %5
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %59, i8* %61)
store i32 1, i32* %6
br label %72
63: ; preds = %38
%64 = load i32*, i32** %8
%65 = call i32 @parseheader(i32* %64)
store i32 %65, i32* %9
%66 = load i32, i32* %9
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %63
store i32 1, i32* %6
br label %69
69: ; preds = %68, %63
%70 = load i32*, i32** %8
%71 = call i32 @fclose(i32* %70)
br label %72
72: ; preds = %69, %53
br label %73
73: ; preds = %72
%74 = load i32, i32* %7
%75 = add nsw i32 %74, 1
store i32 %75, i32* %7
br label %34
76: ; preds = %34
%77 = load i32, i32* %6
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %76
%80 = load i32, i32* @EXIT_SUCCESS
br label %83
81: ; preds = %76
%82 = load i32, i32* @EXIT_FAILURE
br label %83
83: ; preds = %81, %79
%84 = phi i32 [ %80, %79 ], [ %82, %81 ]
store i32 %84, i32* %6
%85 = load i32, i32* %6
store i32 %85, i32* %3
br label %86
86: ; preds = %83, %27
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [97 x i8] c"Usage: %s filename\0AThis function parses the header of filename assuming filename is a pvp file.\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.5 = [25 x i8] c"Unable to open \22%s\22: %s\0A\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %14 [
i32 1, label %11
i32 2, label %3
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32 @strcmp(i8* dereferenceable(1) %5, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %5, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2, %8, %3
%12 = load i8*, i8** %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %47
14: ; preds = %2
%15 = icmp sgt i32 %0, 1
br i1 %15, label %16, label %45
16: ; preds = %8, %14
%17 = zext i32 %0 to i64
br label %18
18: ; preds = %16, %38
%19 = phi i64 [ 1, %16 ], [ %40, %38 ]
%20 = phi i32 [ 0, %16 ], [ %39, %38 ]
%21 = getelementptr inbounds i8*, i8** %1, i64 %19
%22 = load i8*, i8** %21
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %21
%25 = tail call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %33
27: ; preds = %18
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %21
%30 = load i32, i32* @errno
%31 = tail call i8* @strerror(i32 %30)
%32 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %29, i8* %31)
br label %38
33: ; preds = %18
%34 = tail call i32 @parseheader(i32* %25)
%35 = icmp eq i32 %34, 0
%36 = select i1 %35, i32 %20, i32 1
%37 = tail call i32 @fclose(i32* %25)
br label %38
38: ; preds = %33, %27
%39 = phi i32 [ 1, %27 ], [ %36, %33 ]
%40 = add nuw nsw i64 %19, 1
%41 = icmp eq i64 %40, %17
br i1 %41, label %42, label %18
42: ; preds = %38
%43 = icmp eq i32 %39, 0
%44 = load i32, i32* @EXIT_FAILURE
br i1 %43, label %45, label %47
45: ; preds = %14, %42
%46 = load i32, i32* @EXIT_SUCCESS
br label %47
47: ; preds = %45, %42, %11
%48 = phi i32 [ 0, %11 ], [ %46, %45 ], [ %44, %42 ]
ret i32 %48
}