#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*/ STDIN_FILENO;
int atoi(char *);
int /*<<< orphan*/ forward(int /*<<< orphan*/, int, int);
int get_interface(char *);
int get_tunnel(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int main(int argc, char **argv) {
  if (argc < 3) {
    printf("Usage: %s <tunN> <port>\n", argv[0]);
    return 2;
  }
  int interface = get_interface(argv[1]);
  if (interface < 0)
    return 1;
  int tunnel = -1;
  int port = atoi(argv[2]);
  if (port) {
    tunnel = get_tunnel(port);
  }
  if (tunnel < 0)
    return 1;
  puts("Connected.");
  puts("Forwarding. Press Enter to stop.");
  forward(STDIN_FILENO, tunnel, interface);
  perror("Finished");
  return 1;
}


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)
jge    11af <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1256 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <get_interface@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d5 <main+0x65>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0xe6>
movl   $0xffffffff,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1201 <main+0x91>
mov    -0x1c(%rbp),%edi
call   1040 <get_tunnel@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1217 <main+0xa7>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0xe6>
lea    0xdfb(%rip),%rdi
call   1030 <puts@plt>
lea    0xdfa(%rip),%rdi
call   1030 <puts@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1060 <forward@plt>
lea    0xdfb(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x2,%edi
jg     1196 <main+0x26>
mov    0x0(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1050 <printf@plt>
mov    $0x2,%ebx
jmp    11c3 <main+0x53>
mov    0x8(%rbp),%rdi
call   1090 <get_interface@plt>
mov    $0x1,%ebx
test   %eax,%eax
js     11c3 <main+0x53>
mov    %eax,%r15d
mov    0x10(%rbp),%rdi
call   1080 <atoi@plt>
test   %eax,%eax
je     11c3 <main+0x53>
mov    %eax,%edi
call   1040 <get_tunnel@plt>
test   %eax,%eax
jns    11d0 <main+0x60>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r14d
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    %r14d,%esi
mov    %r15d,%edx
call   1060 <forward@plt>
lea    0xe3f(%rip),%rdi
call   1070 <perror@plt>
jmp    11c3 <main+0x53>

LLVM IR (-O0):
@.str = [25 x i8] c"Usage: %s <tunN> <port>\0A\00"
@.str.1 = [11 x i8] c"Connected.\00"
@.str.2 = [33 x i8] c"Forwarding. Press Enter to stop.\00"
@STDIN_FILENO = global i32 0
@.str.3 = [9 x i8] c"Finished\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* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 2, i32* %3
br label %46
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @get_interface(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 1, i32* %3
br label %46
24: ; preds = %16
store i32 -1, i32* %7
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = load i32, i32* %8
%33 = call i32 @get_tunnel(i32 %32)
store i32 %33, i32* %7
br label %34
34: ; preds = %31, %24
%35 = load i32, i32* %7
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 1, i32* %3
br label %46
38: ; preds = %34
%39 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* @STDIN_FILENO
%42 = load i32, i32* %7
%43 = load i32, i32* %6
%44 = call i32 @forward(i32 %41, i32 %42, i32 %43)
%45 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %46
46: ; preds = %38, %37, %23, %11
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [25 x i8] c"Usage: %s <tunN> <port>\0A\00"
@.str.1 = [11 x i8] c"Connected.\00"
@.str.2 = [33 x i8] c"Forwarding. Press Enter to stop.\00"
@STDIN_FILENO = global i32 0
@.str.3 = [9 x i8] c"Finished\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %26
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @get_interface(i8* %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %26, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %12
%18 = tail call i32 @get_tunnel(i32 %15)
%19 = icmp slt i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @STDIN_FILENO
%24 = tail call i32 @forward(i32 %23, i32 %18, i32 %10)
%25 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %12, %7, %17, %20, %4
%27 = phi i32 [ 2, %4 ], [ 1, %20 ], [ 1, %17 ], [ 1, %7 ], [ 1, %12 ]
ret i32 %27
}