#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*/ bpf_asm_compile(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  FILE *fp = stdin;
  bool cstyle = false;
  int i;
  for (i = 1; i < argc; i++) {
    if (!strncmp("-c", argv[i], 2)) {
      cstyle = true;
      continue;
    }
    fp = fopen(argv[i], "r");
    if (!fp) {
      fp = stdin;
      continue;
    }
    break;
  }
  bpf_asm_compile(fp, cstyle);
  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)
mov    0x2e9b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ed <main+0xbd>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe7f(%rip),%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11a0 <main+0x70>
movl   $0x1,-0x1c(%rbp)
jmp    11df <main+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe50(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11da <main+0xaa>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11df <main+0xaf>
jmp    11ed <main+0xbd>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1162 <main+0x32>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <bpf_asm_compile@plt>
xor    %eax,%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    0x2ea6(%rip),%rax
mov    (%rax),%rbx
xor    %r14d,%r14d
cmp    $0x2,%edi
jl     11ba <main+0x8a>
mov    %rsi,%rbp
mov    %edi,%r12d
xor    %r14d,%r14d
mov    $0x1,%r13d
lea    0xe9d(%rip),%r15
jmp    117f <main+0x4f>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%r14d
add    $0x1,%r13
cmp    %r13,%r12
je     11ba <main+0x8a>
mov    0x0(%rbp,%r13,8),%rsi
mov    %r15,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1170 <main+0x40>
mov    0x0(%rbp,%r13,8),%rdi
lea    0xe62(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
jne    11b7 <main+0x87>
mov    0x2e36(%rip),%rax
mov    (%rax),%rbx
jmp    1176 <main+0x46>
mov    %rax,%rbx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <bpf_asm_compile@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32* null
@.str = [3 x i8] c"-c\00"
@.str.1 = [2 x i8] c"r\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32*, i32** @stdin
store i32* %9, i32** %6
store i32 0, i32* %7
store i32 1, i32* %8
br label %10
10: ; preds = %35, %2
%11 = load i32, i32* %8
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %38
14: ; preds = %10
%15 = load i8**, i8*** %5
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19, i32 2)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %14
store i32 1, i32* %7
br label %35
23: ; preds = %14
%24 = load i8**, i8*** %5
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %6
%30 = load i32*, i32** %6
%31 = icmp ne i32* %30, null
br i1 %31, label %34, label %32
32: ; preds = %23
%33 = load i32*, i32** @stdin
store i32* %33, i32** %6
br label %35
34: ; preds = %23
br label %38
35: ; preds = %32, %22
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %10
38: ; preds = %34, %10
%39 = load i32*, i32** %6
%40 = load i32, i32* %7
%41 = call i32 @bpf_asm_compile(i32* %39, i32 %40)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [3 x i8] c"-c\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32*, i32** @stdin
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %26
5: ; preds = %2
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %21
%8 = phi i64 [ 1, %5 ], [ %24, %21 ]
%9 = phi i32 [ 0, %5 ], [ %23, %21 ]
%10 = phi i32* [ %3, %5 ], [ %22, %21 ]
%11 = getelementptr inbounds i8*, i8** %1, i64 %8
%12 = load i8*, i8** %11
%13 = tail call i32 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12, i32 2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %7
%16 = load i8*, i8** %11
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i32*, i32** @stdin
br label %21
21: ; preds = %7, %19
%22 = phi i32* [ %20, %19 ], [ %10, %7 ]
%23 = phi i32 [ %9, %19 ], [ 1, %7 ]
%24 = add nuw nsw i64 %8, 1
%25 = icmp eq i64 %24, %6
br i1 %25, label %26, label %7
26: ; preds = %21, %15, %2
%27 = phi i32 [ 0, %2 ], [ %9, %15 ], [ %23, %21 ]
%28 = phi i32* [ %3, %2 ], [ %17, %15 ], [ %22, %21 ]
%29 = tail call i32 @bpf_asm_compile(i32* %28, i32 %27)
ret i32 0
}