#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 */
scalar_t__ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ recv_all(int, int);
int /*<<< orphan*/ send_udp(int, int);
int tap_open(char *);
int main(int argc, char **argv) {
  int fdt, fdr;
  if (argc != 3)
    error(1, 0, "Usage: %s <tap_tx> <tap_rx>\n", argv[0]);
  fdt = tap_open(argv[1]);
  fdr = tap_open(argv[2]);
  send_udp(fdt, 1);
  recv_all(fdr, 100);
  send_udp(fdt, 4000);
  recv_all(fdr, 100);
  if (close(fdr))
    error(1, errno, "close tun r");
  if (close(fdt))
    error(1, errno, "close tun t");
  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)
cmpl   $0x3,-0x8(%rbp)
je     118c <main+0x3c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe7b(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <tap_open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <tap_open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1030 <send_udp@plt>
mov    -0x18(%rbp),%edi
mov    $0x64,%esi
call   1040 <recv_all@plt>
mov    -0x14(%rbp),%edi
mov    $0xfa0,%esi
call   1030 <send_udp@plt>
mov    -0x18(%rbp),%edi
mov    $0x64,%esi
call   1040 <recv_all@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
je     120e <main+0xbe>
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe16(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
je     123c <main+0xec>
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xdf4(%rip),%rdx
mov    $0x0,%al
call   1060 <error@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
je     1173 <main+0x23>
mov    (%rbx),%rcx
lea    0xe9b(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <error@plt>
mov    0x8(%rbx),%rdi
call   1070 <tap_open@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   1070 <tap_open@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <send_udp@plt>
mov    %ebx,%edi
mov    $0x64,%esi
call   1040 <recv_all@plt>
mov    %ebp,%edi
mov    $0xfa0,%esi
call   1030 <send_udp@plt>
mov    %ebx,%edi
mov    $0x64,%esi
call   1040 <recv_all@plt>
mov    %ebx,%edi
call   1050 <close@plt>
test   %rax,%rax
je     11e1 <main+0x91>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    0xe48(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1060 <error@plt>
mov    %ebp,%edi
call   1050 <close@plt>
test   %rax,%rax
je     1209 <main+0xb9>
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
lea    0xe2c(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1060 <error@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Usage: %s <tap_tx> <tap_rx>\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"close tun r\00"
@.str.2 = [12 x i8] c"close tun t\00"
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 ne i32 %8, 3
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %10, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @tap_open(i8* %18)
store i32 %19, i32* %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @tap_open(i8* %22)
store i32 %23, i32* %7
%24 = load i32, i32* %6
%25 = call i32 @send_udp(i32 %24, i32 1)
%26 = load i32, i32* %7
%27 = call i32 @recv_all(i32 %26, i32 100)
%28 = load i32, i32* %6
%29 = call i32 @send_udp(i32 %28, i32 4000)
%30 = load i32, i32* %7
%31 = call i32 @recv_all(i32 %30, i32 100)
%32 = load i32, i32* %7
%33 = call i64 @close(i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %15
%36 = load i32, i32* @errno
%37 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %35, %15
%39 = load i32, i32* %6
%40 = call i64 @close(i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i32, i32* @errno
%44 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %43, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %42, %38
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"Usage: %s <tap_tx> <tap_rx>\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"close tun r\00"
@.str.2 = [12 x i8] c"close tun t\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i32, i32, i8*, ...) @error(i32 1, i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %7
7: ; preds = %4, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @tap_open(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @tap_open(i8* %12)
%14 = tail call i32 @send_udp(i32 %10, i32 1)
%15 = tail call i32 @recv_all(i32 %13, i32 100)
%16 = tail call i32 @send_udp(i32 %10, i32 4000)
%17 = tail call i32 @recv_all(i32 %13, i32 100)
%18 = tail call i64 @close(i32 %13)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %7
%21 = load i32, i32* @errno
%22 = tail call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %20, %7
%24 = tail call i64 @close(i32 %10)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* @errno
%28 = tail call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %26, %23
ret i32 0
}