#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ write_log(char *);
pid_t start_ssh_tunnel(char *hostname, char *port, char *proxy_port) {
  write_log("Starting ssh process.");
  char *argv[] = {"ssh",      "-T", "-n", "-N",     "-D",
                  proxy_port, "-p", port, hostname, NULL};
  int process_id = fork();
  if (process_id < 0) {
    write_log("Error while trying to fork ssh process. Exiting.");
    exit(EXIT_FAILURE);
  }
  if (process_id == 0) {
    if (execvp("ssh", argv) == -1) {
      write_log("Error while trying to exec ssh process. Exiting.");
      exit(EXIT_FAILURE);
    }
  }
  return process_id;
}


x86 assembly (clang, -O0):
<start_ssh_tunnel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xea2(%rip),%rdi
call   1030 <write_log@plt>
lea    0xeac(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xe95(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe8d(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jge    11f3 <start_ssh_tunnel+0xb3>
lea    0xe49(%rip),%rdi
call   1030 <write_log@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x74(%rbp)
jne    1235 <start_ssh_tunnel+0xf5>
lea    -0x70(%rbp),%rsi
lea    0xe0e(%rip),%rdi
call   1040 <execvp@plt>
cmp    $0xffffffff,%eax
jne    1230 <start_ssh_tunnel+0xf0>
lea    0xe3d(%rip),%rdi
call   1030 <write_log@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    1235 <start_ssh_tunnel+0xf5>
mov    -0x74(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_ssh_tunnel>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xea7(%rip),%rdi
call   1030 <write_log@plt>
lea    0xeb1(%rip),%rax
mov    %rax,(%rsp)
lea    0xeaa(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xea1(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe98(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe8f(%rip),%rax
mov    %rax,0x20(%rsp)
mov    %rbx,0x28(%rsp)
lea    0xe81(%rip),%rax
mov    %rax,0x30(%rsp)
mov    %r14,0x38(%rsp)
mov    %r15,0x40(%rsp)
movq   $0x0,0x48(%rsp)
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
js     11ec <start_ssh_tunnel+0xac>
mov    %eax,%ebx
jne    11e0 <start_ssh_tunnel+0xa0>
lea    0xe43(%rip),%rdi
mov    %rsp,%rsi
call   1040 <execvp@plt>
cmp    $0xffffffff,%eax
je     11f5 <start_ssh_tunnel+0xb5>
mov    %ebx,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe36(%rip),%rdi
jmp    11fc <start_ssh_tunnel+0xbc>
lea    0xe5e(%rip),%rdi
call   1030 <write_log@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Starting ssh process.\00"
@.str.1 = [4 x i8] c"ssh\00"
@.str.2 = [3 x i8] c"-T\00"
@.str.3 = [3 x i8] c"-n\00"
@.str.4 = [3 x i8] c"-N\00"
@.str.5 = [3 x i8] c"-D\00"
@.str.6 = [3 x i8] c"-p\00"
@.str.7 = [49 x i8] c"Error while trying to fork ssh process. Exiting.\00"
@EXIT_FAILURE = global i32 0
@.str.8 = [49 x i8] c"Error while trying to exec ssh process. Exiting.\00"
define i32 @start_ssh_tunnel(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [10 x i8*]
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = call i32 @write_log(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds i8*, i8** %10, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds i8*, i8** %11, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds i8*, i8** %12, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds i8*, i8** %13, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %6
store i8* %16, i8** %15
%17 = getelementptr inbounds i8*, i8** %15, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %5
store i8* %19, i8** %18
%20 = getelementptr inbounds i8*, i8** %18, i64 1
%21 = load i8*, i8** %4
store i8* %21, i8** %20
%22 = getelementptr inbounds i8*, i8** %20, i64 1
store i8* null, i8** %22
%23 = call i32 (...) @fork()
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %3
%27 = call i32 @write_log(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %3
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%35 = call i32 @execvp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = call i32 @write_log(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %33
br label %42
42: ; preds = %41, %30
%43 = load i32, i32* %8
ret i32 %43
}

LLVM IR (-O2):
@.str = [22 x i8] c"Starting ssh process.\00"
@.str.1 = [4 x i8] c"ssh\00"
@.str.2 = [3 x i8] c"-T\00"
@.str.3 = [3 x i8] c"-n\00"
@.str.4 = [3 x i8] c"-N\00"
@.str.5 = [3 x i8] c"-D\00"
@.str.6 = [3 x i8] c"-p\00"
@.str.7 = [49 x i8] c"Error while trying to fork ssh process. Exiting.\00"
@EXIT_FAILURE = global i32 0
@.str.8 = [49 x i8] c"Error while trying to exec ssh process. Exiting.\00"
define i32 @start_ssh_tunnel(i8* %0, i8* %1, i8* %2) {
%4 = alloca [10 x i8*]
%5 = tail call i32 @write_log(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = bitcast [10 x i8*]* %4 to i8*
%7 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 5
store i8* %2, i8** %12
%13 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 6
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 7
store i8* %1, i8** %14
%15 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 8
store i8* %0, i8** %15
%16 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 9
store i8* null, i8** %16
%17 = tail call i32 (...) @fork()
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = tail call i32 @write_log(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %3
%24 = icmp eq i32 %17, 0
br i1 %24, label %25, label %32
25: ; preds = %23
%26 = call i32 @execvp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %7)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = call i32 @write_log(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %25, %23
ret i32 %17
}