#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int PATH_MAX;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ packet_capture(int, int, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int main(int argc, char **argv) {
  int iffd1, iffd2;
  char ifpath1[PATH_MAX], ifpath2[PATH_MAX];
  if (argc < 3) {
    printf("Usage: %s IFNAME1 IFNAME2\n", argv[0]);
    return 1;
  }
  snprintf(ifpath1, sizeof ifpath1, "/net/eth/%s", argv[1]);
  snprintf(ifpath2, sizeof ifpath2, "/net/eth/%s", argv[2]);
  iffd1 = open(ifpath1, O_RDONLY);
  iffd2 = open(ifpath2, O_RDONLY);
  if (iffd1 < 0 || iffd2 < 0) {
    perror("open");
    exit(EXIT_FAILURE);
  }
  packet_capture(iffd1, iffd2, argv[1], argv[2]);
  close(iffd1);
  close(iffd2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0x58(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1208 <main+0x98>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe10(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    12d5 <main+0x165>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xdfa(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xddc(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x50(%rbp),%rdi
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,-0x14(%rbp)
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1282 <main+0x112>
cmpl   $0x0,-0x18(%rbp)
jge    129c <main+0x12c>
lea    0xd9e(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
call   1030 <packet_capture@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e68(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%rbx
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
cmp    $0x2,%edi
jg     11c1 <main+0x51>
mov    (%r14),%rsi
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
jmp    1238 <main+0xc8>
mov    0x8(%r14),%rcx
lea    0xe4f(%rip),%r13
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r13,%rdx
call   1050 <snprintf@plt>
mov    0x10(%r14),%rcx
mov    %r15,%rdi
mov    %r12d,%esi
mov    %r13,%rdx
call   1050 <snprintf@plt>
mov    0x2ded(%rip),%r13
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
mov    %eax,%r12d
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1070 <open@plt>
mov    %eax,%ebx
or     %r12d,%eax
js     1247 <main+0xd7>
mov    0x8(%r14),%rdx
mov    0x10(%r14),%rcx
mov    %r12d,%edi
mov    %ebx,%esi
call   1030 <packet_capture@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd9(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [27 x i8] c"Usage: %s IFNAME1 IFNAME2\0A\00"
@.str.1 = [12 x i8] c"/net/eth/%s\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@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 i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @PATH_MAX
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
%16 = load i32, i32* @PATH_MAX
%17 = zext i32 %16 to i64
%18 = alloca i8, i64 %17
store i64 %17, i64* %10
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %26
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %24)
store i32 1, i32* %3
store i32 1, i32* %11
br label %64
26: ; preds = %2
%27 = trunc i64 %13 to i32
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @snprintf(i8* %15, i32 %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = trunc i64 %17 to i32
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @snprintf(i8* %18, i32 %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @O_RDONLY
%38 = call i32 @open(i8* %15, i32 %37)
store i32 %38, i32* %6
%39 = load i32, i32* @O_RDONLY
%40 = call i32 @open(i8* %18, i32 %39)
store i32 %40, i32* %7
%41 = load i32, i32* %6
%42 = icmp slt i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %26
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %43, %26
%47 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %43
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 2
%58 = load i8*, i8** %57
%59 = call i32 @packet_capture(i32 %51, i32 %52, i8* %55, i8* %58)
%60 = load i32, i32* %6
%61 = call i32 @close(i32 %60)
%62 = load i32, i32* %7
%63 = call i32 @close(i32 %62)
store i32 0, i32* %3
store i32 1, i32* %11
br label %64
64: ; preds = %50, %21
%65 = load i8*, i8** %8
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [27 x i8] c"Usage: %s IFNAME1 IFNAME2\0A\00"
@.str.1 = [12 x i8] c"/net/eth/%s\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = alloca i8, i64 %4
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %34
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @snprintf(i8* %5, i32 %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @snprintf(i8* %6, i32 %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %5, i32 %18)
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %6, i32 %20)
%22 = or i32 %21, %19
%23 = icmp sgt i32 %22, -1
br i1 %23, label %28, label %24
24: ; preds = %11
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %11
%29 = load i8*, i8** %12
%30 = load i8*, i8** %15
%31 = call i32 @packet_capture(i32 %19, i32 %21, i8* %29, i8* %30)
%32 = call i32 @close(i32 %19)
%33 = call i32 @close(i32 %21)
br label %34
34: ; preds = %28, %8
%35 = phi i32 [ 1, %8 ], [ 0, %28 ]
ret i32 %35
}