#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ether_recv(int);
int /*<<< orphan*/ ether_send(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int fd;
  if (argc < 2) {
    usage(argv[0]);
  }
  fd = open("//net/el3:0", O_RDWR);
  if (!strcmp(argv[1], "-r")) {
    ether_recv(fd);
  } else if (!strcmp(argv[1], "-s")) {
    ether_send(fd);
  } else {
    usage(argv[0]);
  }
  close(fd);
}


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    118c <main+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    0xe64(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe59(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11ce <main+0x6e>
mov    -0x14(%rbp),%edi
call   1030 <ether_recv@plt>
jmp    1209 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe32(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11f8 <main+0x98>
mov    -0x14(%rbp),%edi
call   1080 <ether_send@plt>
jmp    1204 <main+0xa4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
jmp    1209 <main+0xa9>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1174 <main+0x14>
mov    (%rbx),%rdi
call   1060 <usage@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
lea    0xe7c(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r14d
mov    0x8(%rbx),%rbp
lea    0xe75(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11c0 <main+0x60>
lea    0xe65(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11ca <main+0x6a>
mov    (%rbx),%rdi
call   1060 <usage@plt>
jmp    11d2 <main+0x72>
mov    %r14d,%edi
call   1030 <ether_recv@plt>
jmp    11d2 <main+0x72>
mov    %r14d,%edi
call   1080 <ether_send@plt>
mov    %r14d,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"//net/el3:0\00"
@O_RDWR = global i32 0
@.str.1 = [3 x i8] c"-r\00"
@.str.2 = [3 x i8] c"-s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @usage(i8* %12)
br label %14
14: ; preds = %9, %2
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %14
%23 = load i32, i32* %6
%24 = call i32 @ether_recv(i32 %23)
br label %40
25: ; preds = %14
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %25
%32 = load i32, i32* %6
%33 = call i32 @ether_send(i32 %32)
br label %39
34: ; preds = %25
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @usage(i8* %37)
br label %39
39: ; preds = %34, %31
br label %40
40: ; preds = %39, %22
%41 = load i32, i32* %6
%42 = call i32 @close(i32 %41)
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [12 x i8] c"//net/el3:0\00"
@O_RDWR = global i32 0
@.str.1 = [3 x i8] c"-r\00"
@.str.2 = [3 x i8] c"-s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
br label %7
7: ; preds = %4, %2
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = tail call i32 @ether_recv(i32 %9)
br label %24
16: ; preds = %7
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @ether_send(i32 %9)
br label %24
21: ; preds = %16
%22 = load i8*, i8** %1
%23 = tail call i32 @usage(i8* %22)
br label %24
24: ; preds = %19, %21, %14
%25 = tail call i32 @close(i32 %9)
ret i32 0
}