#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 EINVAL;
int bpf_decode(int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
char *strerror(int);
int main(int argc, char *argv[]) {
  int rc;
  FILE *file;
  if (argc > 2) {
    fprintf(stderr, "usage: %s [<bpf_file>]\n", argv[0]);
    return EINVAL;
  }
  if (argc == 2) {
    file = fopen(argv[1], "r");
    if (file == NULL) {
      fprintf(stderr, "error: unable to open \"%s\" (%s)\n", argv[1],
              strerror(errno));
      return errno;
    }
  } else
    file = stdin;
  rc = bpf_decode(file);
  fclose(file);
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    119f <main+0x4f>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1249 <main+0xf9>
cmpl   $0x2,-0x8(%rbp)
jne    1220 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe60(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121b <main+0xcb>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1249 <main+0xf9>
jmp    122e <main+0xde>
mov    0x2dc1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <bpf_decode@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x3,%edi
jl     1181 <main+0x31>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe91(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
jmp    11f3 <main+0xa3>
cmp    $0x2,%edi
jne    11d5 <main+0x85>
mov    0x8(%r14),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11df <main+0x8f>
mov    0x2e33(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r14),%r14
mov    0x2e1e(%rip),%rbp
mov    0x0(%rbp),%edi
call   1070 <strerror@plt>
lea    0xe59(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%eax
jmp    11f3 <main+0xa3>
mov    0x2e0c(%rip),%rax
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1040 <bpf_decode@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"usage: %s [<bpf_file>]\0A\00"
@EINVAL = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"error: unable to open \22%s\22 (%s)\0A\00"
@errno = global i32 0
@stdin = global i32* null
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 sgt i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EINVAL
store i32 %16, i32* %3
br label %45
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %37
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %7
%25 = load i32*, i32** %7
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %36
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %33)
%35 = load i32, i32* @errno
store i32 %35, i32* %3
br label %45
36: ; preds = %20
br label %39
37: ; preds = %17
%38 = load i32*, i32** @stdin
store i32* %38, i32** %7
br label %39
39: ; preds = %37, %36
%40 = load i32*, i32** %7
%41 = call i32 @bpf_decode(i32* %40)
store i32 %41, i32* %6
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* %6
store i32 %44, i32* %3
br label %45
45: ; preds = %39, %27, %10
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"usage: %s [<bpf_file>]\0A\00"
@EINVAL = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"error: unable to open \22%s\22 (%s)\0A\00"
@errno = global i32 0
@stdin = global i32* null
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EINVAL
br label %29
9: ; preds = %2
%10 = icmp eq i32 %0, 2
br i1 %10, label %11, label %23
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %25
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %18, i8* %20)
%22 = load i32, i32* @errno
br label %29
23: ; preds = %9
%24 = load i32*, i32** @stdin
br label %25
25: ; preds = %11, %23
%26 = phi i32* [ %14, %11 ], [ %24, %23 ]
%27 = tail call i32 @bpf_decode(i32* %26)
%28 = tail call i32 @fclose(i32* %26)
br label %29
29: ; preds = %25, %16, %4
%30 = phi i32 [ %8, %4 ], [ %22, %16 ], [ %27, %25 ]
ret i32 %30
}