#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct stat {
  int /*<<< orphan*/ st_size;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  char *h_name;
};
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ off_t;
typedef int /*<<< orphan*/ client_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fstat(int, struct stat *);
struct hostent *gethostbyaddr(char const *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(unsigned short);
char *inet_ntoa(TYPE_1__);
scalar_t__ isEOM(char *);
scalar_t__ listen(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sendfile(int, int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              void const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *, int);
int main(int argc, char **argv) {
  static const char *base_path = "/tmp/mock-server/trans";
  int optval = 1, n, reading = 1, connection_counter;
  off_t sendfile_offset;
  int fd, fd_parent, fd_child, clientlen, mock_port;
  struct sockaddr_in server_addr, client_addr;
  struct hostent *hostp;
  struct stat stat_buf;
  char buffer_in[1024], buffer_out[1024], file_path[128];
  char *hostaddrp, *stage;
  if (argc != 3) {
    error("0> ERROR not enough parameters");
  }
  mock_port = atoi(argv[1]);
  stage = argv[2];
  printf("0> tunnel: %i - stage: %s\n", mock_port, stage);
  fd_parent = socket(AF_INET, SOCK_STREAM, 0);
  if (fd_parent < 0) {
    error("0> ERROR opening socket");
  }
  setsockopt(fd_parent, SOL_SOCKET, SO_REUSEADDR, (const void *)&optval,
             sizeof(int));
  bzero((char *)&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  server_addr.sin_port = htons((unsigned short)10005);
  if (bind(fd_parent, (struct sockaddr *)&server_addr, sizeof(server_addr)) <
      0) {
    error("0> ERROR on binding");
  }
  if (listen(fd_parent, 5) < 0) {
    error("0> ERROR on listen");
  }
  clientlen = sizeof(client_addr);
  connection_counter = 0;
  while (1) {
    connection_counter++;
    fd_child = accept(fd_parent, (struct sockaddr *)&client_addr, &clientlen);
    if (fd_child < 0)
      error("0> ERROR on accept");
    hostp = gethostbyaddr((const char *)&client_addr.sin_addr.s_addr,
                          sizeof(client_addr.sin_addr.s_addr), AF_INET);
    if (hostp == NULL) {
      perror("ERROR on gethostbyaddr");
    }
    hostaddrp = inet_ntoa(client_addr.sin_addr);
    if (hostaddrp == NULL) {
      error("ERROR on inet_ntoa\n");
    }
    printf("%i> server established connection with %s (%s)\n",
           connection_counter, hostp->h_name, hostaddrp);
    reading = 1;
    while (reading) {
      bzero(buffer_in, 1024);
      n = read(fd_child, buffer_in, 1024);
      if (n == 0) {
        printf("%i> end of message\n", connection_counter);
        reading = 0;
        continue;
      }
      if (n < 0) {
        printf("%i> ERROR reading from socket", connection_counter);
        reading = 0;
        continue;
      }
      if (isEOM(buffer_in)) {
        printf("%i> EOM: retrieving file\n", connection_counter);
        sprintf(file_path, "%s/%s/%i.in.dump", base_path, stage,
                connection_counter);
        printf("%i> filepath = %s\n", connection_counter, file_path);
        fd = open(file_path, O_RDONLY);
        if (fd == -1) {
          printf("%i> ERROR failed to open file\n", connection_counter);
          continue;
        }
        fstat(fd, &stat_buf);
        sendfile_offset = 0;
        sendfile(fd_child, fd, &sendfile_offset, stat_buf.st_size);
        reading = 0;
      }
    }
    printf("%i> Closing connection\n", connection_counter);
    close(fd_child);
    printf("- - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x900,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     128d <main+0x3d>
lea    0xd8f(%rip),%rdi
call   10e0 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x900(%rbp)
mov    -0x38(%rbp),%esi
mov    -0x900(%rbp),%rdx
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
mov    0x2cec(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    12f6 <main+0xa6>
lea    0xd60(%rip),%rdi
call   10e0 <error@plt>
mov    -0x2c(%rbp),%edi
mov    0x2ce8(%rip),%rax
mov    (%rax),%esi
mov    0x2caf(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    -0x48(%rbp),%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x48(%rbp)
mov    $0x2715,%edi
call   1050 <htons@plt>
mov    %eax,-0x44(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    1379 <main+0x129>
lea    0xcf5(%rip),%rdi
call   10e0 <error@plt>
mov    -0x2c(%rbp),%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
jge    139c <main+0x14c>
lea    0xce6(%rip),%rdi
call   10e0 <error@plt>
movl   $0xc,-0x34(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x58(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1120 <accept@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    13dc <main+0x18c>
lea    0xcb9(%rip),%rdi
call   10e0 <error@plt>
lea    -0x58(%rbp),%rdi
mov    0x2bf9(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1140 <gethostbyaddr@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    140e <main+0x1be>
lea    0xc9a(%rip),%rdi
call   1100 <perror@plt>
mov    -0x58(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x8f8(%rbp)
cmpq   $0x0,-0x8f8(%rbp)
jne    1437 <main+0x1e7>
lea    0xc88(%rip),%rdi
call   10e0 <error@plt>
mov    -0x20(%rbp),%esi
mov    -0x60(%rbp),%rax
mov    (%rax),%rdx
mov    -0x8f8(%rbp),%rcx
lea    0xc7f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     15aa <main+0x35a>
lea    -0x470(%rbp),%rdi
mov    $0x400,%esi
call   1110 <bzero@plt>
mov    -0x30(%rbp),%edi
lea    -0x470(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    14b6 <main+0x266>
mov    -0x20(%rbp),%esi
lea    0xc5b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x1c(%rbp)
jmp    145d <main+0x20d>
cmpl   $0x0,-0x18(%rbp)
jge    14dd <main+0x28d>
mov    -0x20(%rbp),%esi
lea    0xc48(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x1c(%rbp)
jmp    145d <main+0x20d>
lea    -0x470(%rbp),%rdi
call   1090 <isEOM@plt>
cmp    $0x0,%rax
je     15a5 <main+0x355>
mov    -0x20(%rbp),%esi
lea    0xc33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x8f0(%rbp),%rdi
mov    0x2bb6(%rip),%rdx
mov    -0x900(%rbp),%rcx
mov    -0x20(%rbp),%r8d
lea    0xc26(%rip),%rsi
call   1150 <sprintf@plt>
mov    -0x20(%rbp),%esi
lea    -0x8f0(%rbp),%rdx
lea    0xc21(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x8f0(%rbp),%rdi
mov    0x2a89(%rip),%rax
mov    (%rax),%esi
call   10f0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1579 <main+0x329>
mov    -0x20(%rbp),%esi
lea    0xc01(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    145d <main+0x20d>
mov    -0x28(%rbp),%edi
lea    -0x68(%rbp),%rsi
call   1160 <fstat@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x68(%rbp),%ecx
lea    -0x24(%rbp),%rdx
call   10c0 <sendfile@plt>
movl   $0x0,-0x1c(%rbp)
jmp    145d <main+0x20d>
mov    -0x20(%rbp),%esi
lea    0xbd9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%edi
call   1080 <close@plt>
lea    0xbdb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13aa <main+0x15a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4c8,%rsp
mov    %rsi,%rbx
movl   $0x1,0x14(%rsp)
cmp    $0x3,%edi
je     128d <main+0x2d>
lea    0xd8f(%rip),%rdi
call   10f0 <error@plt>
mov    0x8(%rbx),%rdi
call   1140 <atoi@plt>
mov    0x10(%rbx),%r15
lea    0xd95(%rip),%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2d2c(%rip),%r14
mov    (%r14),%edi
mov    0x2d02(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    12d9 <main+0x79>
lea    0xd7d(%rip),%rdi
call   10f0 <error@plt>
mov    0x2d08(%rip),%rax
mov    (%rax),%esi
mov    0x2ccf(%rip),%rax
mov    (%rax),%edx
lea    0x14(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   1120 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x20(%rsp)
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x18(%rsp)
mov    $0x2715,%edi
call   1060 <htons@plt>
mov    %eax,0x1c(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
jns    1356 <main+0xf6>
lea    0xd18(%rip),%rdi
call   10f0 <error@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
test   %rax,%rax
jns    1373 <main+0x113>
lea    0xd0f(%rip),%rdi
call   10f0 <error@plt>
movl   $0xc,0xc(%rsp)
lea    0xc0(%rsp),%r13
lea    0x40(%rsp),%rbp
xor    %r12d,%r12d
mov    %r15,0x28(%rsp)
mov    %ebx,0x8(%rsp)
jmp    13da <main+0x17a>
cs nopw 0x0(%rax,%rax,1)
lea    0xd6b(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdd5(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14d,%edi
call   1090 <close@plt>
lea    0xdd4(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%ebx
mov    %ebx,%edi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
lea    0xc(%rsp),%rdx
call   1130 <accept@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1401 <main+0x1a1>
lea    0xc94(%rip),%rdi
call   10f0 <error@plt>
mov    0x2bd8(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1150 <gethostbyaddr@plt>
mov    %rax,%r15
test   %rax,%rax
je     155d <main+0x2fd>
add    $0x1,%r12d
mov    0x30(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1444 <main+0x1e4>
lea    0xc7b(%rip),%rdi
call   10f0 <error@plt>
mov    (%r15),%rdx
lea    0xc80(%rip),%rdi
mov    %r12d,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
mov    $0x400,%esi
call   1120 <bzero@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0x400,%edx
call   10b0 <read@plt>
test   %eax,%eax
mov    0x28(%rsp),%r15
jne    14c2 <main+0x262>
lea    0xc76(%rip),%rdi
jmp    13a7 <main+0x147>
nopl   (%rax)
lea    0xcd7(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
mov    $0x400,%esi
call   1120 <bzero@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0x400,%edx
call   10b0 <read@plt>
test   %eax,%eax
je     1481 <main+0x221>
test   %eax,%eax
js     13a0 <main+0x140>
mov    %r13,%rdi
call   10a0 <isEOM@plt>
test   %rax,%rax
je     14a1 <main+0x241>
lea    0xc52(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
lea    0xc58(%rip),%rsi
lea    0xb07(%rip),%rdx
mov    %r15,%rcx
mov    %r12d,%r8d
call   1160 <sprintf@plt>
lea    0xc50(%rip),%rdi
mov    %r12d,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2ab9(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1100 <open@plt>
cmp    $0xffffffff,%eax
je     1490 <main+0x230>
mov    %eax,%ebx
mov    %eax,%edi
mov    %rsp,%rsi
call   1170 <fstat@plt>
movl   $0x0,0x10(%rsp)
mov    (%rsp),%ecx
mov    %r14d,%edi
mov    %ebx,%esi
lea    0x10(%rsp),%rdx
call   10d0 <sendfile@plt>
jmp    13b1 <main+0x151>
lea    0xb3f(%rip),%rdi
call   1110 <perror@plt>
jmp    1423 <main+0x1c3>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i8* }
%struct.stat = type { i32 }
%struct.sockaddr = type { i32 }
@main.base_path = internal global i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i32 0, i32 0)
@.str = [23 x i8] c"/tmp/mock-server/trans\00"
@.str.1 = [31 x i8] c"0> ERROR not enough parameters\00"
@.str.2 = [27 x i8] c"0> tunnel: %i - stage: %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [24 x i8] c"0> ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
@.str.4 = [20 x i8] c"0> ERROR on binding\00"
@.str.5 = [19 x i8] c"0> ERROR on listen\00"
@.str.6 = [19 x i8] c"0> ERROR on accept\00"
@.str.7 = [23 x i8] c"ERROR on gethostbyaddr\00"
@.str.8 = [20 x i8] c"ERROR on inet_ntoa\0A\00"
@.str.9 = [48 x i8] c"%i> server established connection with %s (%s)\0A\00"
@.str.10 = [20 x i8] c"%i> end of message\0A\00"
@.str.11 = [30 x i8] c"%i> ERROR reading from socket\00"
@.str.12 = [26 x i8] c"%i> EOM: retrieving file\0A\00"
@.str.13 = [17 x i8] c"%s/%s/%i.in.dump\00"
@.str.14 = [19 x i8] c"%i> filepath = %s\0A\00"
@O_RDONLY = global i32 0
@.str.15 = [31 x i8] c"%i> ERROR failed to open file\0A\00"
@.str.16 = [24 x i8] c"%i> Closing connection\0A\00"
@.str.17 = [55 x i8] c"- - - - - - - - - - - - - - - - - - - - - - - - - - -\0A\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
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.sockaddr_in
%17 = alloca %struct.sockaddr_in
%18 = alloca %struct.hostent*
%19 = alloca %struct.stat
%20 = alloca [1024 x i8]
%21 = alloca [1024 x i8]
%22 = alloca [128 x i8]
%23 = alloca i8*
%24 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
store i32 1, i32* %8
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 3
br i1 %26, label %27, label %29
27: ; preds = %2
%28 = call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %2
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %15
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
store i8* %36, i8** %24
%37 = load i32, i32* %15
%38 = load i8*, i8** %24
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %37, i8* %38)
%40 = load i32, i32* @AF_INET
%41 = load i32, i32* @SOCK_STREAM
%42 = call i32 @socket(i32 %40, i32 %41, i32 0)
store i32 %42, i32* %12
%43 = load i32, i32* %12
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %29
%46 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %29
%48 = load i32, i32* %12
%49 = load i32, i32* @SOL_SOCKET
%50 = load i32, i32* @SO_REUSEADDR
%51 = bitcast i32* %6 to i8*
%52 = call i32 @setsockopt(i32 %48, i32 %49, i32 %50, i8* %51, i32 4)
%53 = bitcast %struct.sockaddr_in* %16 to i8*
%54 = call i32 @bzero(i8* %53, i32 12)
%55 = load i32, i32* @AF_INET
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 2
store i32 %55, i32* %56
%57 = load i32, i32* @INADDR_ANY
%58 = call i32 @htonl(i32 %57)
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
%60 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %59, i32 0, i32 0
store i32 %58, i32* %60
%61 = call i32 @htons(i16 zeroext 10005)
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
store i32 %61, i32* %62
%63 = load i32, i32* %12
%64 = bitcast %struct.sockaddr_in* %16 to %struct.sockaddr*
%65 = call i64 @bind(i32 %63, %struct.sockaddr* %64, i32 12)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %47
%68 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %69
69: ; preds = %67, %47
%70 = load i32, i32* %12
%71 = call i64 @listen(i32 %70, i32 5)
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %69
%74 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %75
75: ; preds = %73, %69
store i32 12, i32* %14
store i32 0, i32* %9
br label %76
76: ; preds = %75, %164
%77 = load i32, i32* %9
%78 = add nsw i32 %77, 1
store i32 %78, i32* %9
%79 = load i32, i32* %12
%80 = bitcast %struct.sockaddr_in* %17 to %struct.sockaddr*
%81 = call i32 @accept(i32 %79, %struct.sockaddr* %80, i32* %14)
store i32 %81, i32* %13
%82 = load i32, i32* %13
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %76
%85 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %86
86: ; preds = %84, %76
%87 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%88 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %87, i32 0, i32 0
%89 = bitcast i32* %88 to i8*
%90 = load i32, i32* @AF_INET
%91 = call %struct.hostent* @gethostbyaddr(i8* %89, i32 4, i32 %90)
store %struct.hostent* %91, %struct.hostent** %18
%92 = load %struct.hostent*, %struct.hostent** %18
%93 = icmp eq %struct.hostent* %92, null
br i1 %93, label %94, label %96
94: ; preds = %86
%95 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %96
96: ; preds = %94, %86
%97 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%98 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %97, i32 0, i32 0
%99 = load i32, i32* %98
%100 = call i8* @inet_ntoa(i32 %99)
store i8* %100, i8** %23
%101 = load i8*, i8** %23
%102 = icmp eq i8* %101, null
br i1 %102, label %103, label %105
103: ; preds = %96
%104 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
br label %105
105: ; preds = %103, %96
%106 = load i32, i32* %9
%107 = load %struct.hostent*, %struct.hostent** %18
%108 = getelementptr inbounds %struct.hostent, %struct.hostent* %107, i32 0, i32 0
%109 = load i8*, i8** %108
%110 = load i8*, i8** %23
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.9, i64 0, i64 0), i32 %106, i8* %109, i8* %110)
store i32 1, i32* %8
br label %112
112: ; preds = %163, %152, %129, %123, %105
%113 = load i32, i32* %8
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %164
115: ; preds = %112
%116 = getelementptr inbounds [1024 x i8], [1024 x i8]* %20, i64 0, i64 0
%117 = call i32 @bzero(i8* %116, i32 1024)
%118 = load i32, i32* %13
%119 = getelementptr inbounds [1024 x i8], [1024 x i8]* %20, i64 0, i64 0
%120 = call i32 @read(i32 %118, i8* %119, i32 1024)
store i32 %120, i32* %7
%121 = load i32, i32* %7
%122 = icmp eq i32 %121, 0
br i1 %122, label %123, label %126
123: ; preds = %115
%124 = load i32, i32* %9
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 %124)
store i32 0, i32* %8
br label %112
126: ; preds = %115
%127 = load i32, i32* %7
%128 = icmp slt i32 %127, 0
br i1 %128, label %129, label %132
129: ; preds = %126
%130 = load i32, i32* %9
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0), i32 %130)
store i32 0, i32* %8
br label %112
132: ; preds = %126
%133 = getelementptr inbounds [1024 x i8], [1024 x i8]* %20, i64 0, i64 0
%134 = call i64 @isEOM(i8* %133)
%135 = icmp ne i64 %134, 0
br i1 %135, label %136, label %163
136: ; preds = %132
%137 = load i32, i32* %9
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0), i32 %137)
%139 = getelementptr inbounds [128 x i8], [128 x i8]* %22, i64 0, i64 0
%140 = load i8*, i8** @main.base_path
%141 = load i8*, i8** %24
%142 = load i32, i32* %9
%143 = call i32 @sprintf(i8* %139, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.13, i64 0, i64 0), i8* %140, i8* %141, i32 %142)
%144 = load i32, i32* %9
%145 = getelementptr inbounds [128 x i8], [128 x i8]* %22, i64 0, i64 0
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.14, i64 0, i64 0), i32 %144, i8* %145)
%147 = getelementptr inbounds [128 x i8], [128 x i8]* %22, i64 0, i64 0
%148 = load i32, i32* @O_RDONLY
%149 = call i32 @open(i8* %147, i32 %148)
store i32 %149, i32* %11
%150 = load i32, i32* %11
%151 = icmp eq i32 %150, -1
br i1 %151, label %152, label %155
152: ; preds = %136
%153 = load i32, i32* %9
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.15, i64 0, i64 0), i32 %153)
br label %112
155: ; preds = %136
%156 = load i32, i32* %11
%157 = call i32 @fstat(i32 %156, %struct.stat* %19)
store i32 0, i32* %10
%158 = load i32, i32* %13
%159 = load i32, i32* %11
%160 = getelementptr inbounds %struct.stat, %struct.stat* %19, i32 0, i32 0
%161 = load i32, i32* %160
%162 = call i32 @sendfile(i32 %158, i32 %159, i32* %10, i32 %161)
store i32 0, i32* %8
br label %163
163: ; preds = %155, %132
br label %112
164: ; preds = %112
%165 = load i32, i32* %9
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.16, i64 0, i64 0), i32 %165)
%167 = load i32, i32* %13
%168 = call i32 @close(i32 %167)
%169 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.17, i64 0, i64 0))
br label %76
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.stat = type { i32 }
%struct.sockaddr = type { i32 }
%struct.hostent = type { i8* }
@.str = [23 x i8] c"/tmp/mock-server/trans\00"
@.str.1 = [31 x i8] c"0> ERROR not enough parameters\00"
@.str.2 = [27 x i8] c"0> tunnel: %i - stage: %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [24 x i8] c"0> ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
@.str.4 = [20 x i8] c"0> ERROR on binding\00"
@.str.5 = [19 x i8] c"0> ERROR on listen\00"
@.str.6 = [19 x i8] c"0> ERROR on accept\00"
@.str.7 = [23 x i8] c"ERROR on gethostbyaddr\00"
@.str.8 = [20 x i8] c"ERROR on inet_ntoa\0A\00"
@.str.9 = [48 x i8] c"%i> server established connection with %s (%s)\0A\00"
@.str.10 = [20 x i8] c"%i> end of message\0A\00"
@.str.11 = [30 x i8] c"%i> ERROR reading from socket\00"
@.str.12 = [26 x i8] c"%i> EOM: retrieving file\0A\00"
@.str.13 = [17 x i8] c"%s/%s/%i.in.dump\00"
@.str.14 = [19 x i8] c"%i> filepath = %s\0A\00"
@O_RDONLY = global i32 0
@.str.15 = [31 x i8] c"%i> ERROR failed to open file\0A\00"
@.str.16 = [24 x i8] c"%i> Closing connection\0A\00"
@str = [54 x i8] c"- - - - - - - - - - - - - - - - - - - - - - - - - - -\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.stat
%9 = alloca [1024 x i8]
%10 = alloca [128 x i8]
%11 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%12 = bitcast i32* %4 to i8*
%13 = bitcast i32* %5 to i8*
%14 = bitcast %struct.sockaddr_in* %6 to i8*
%15 = bitcast %struct.sockaddr_in* %7 to i8*
%16 = bitcast %struct.stat* %8 to i8*
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%19 = icmp eq i32 %0, 3
br i1 %19, label %22, label %20
20: ; preds = %2
%21 = tail call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %25, i8* %27)
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_STREAM
%31 = tail call i32 @socket(i32 %29, i32 %30, i32 0)
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %22
%34 = tail call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %22
%36 = load i32, i32* @SOL_SOCKET
%37 = load i32, i32* @SO_REUSEADDR
%38 = call i32 @setsockopt(i32 %31, i32 %36, i32 %37, i8* %11, i32 4)
%39 = call i32 @bzero(i8* %14, i32 12)
%40 = load i32, i32* @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %40, i32* %41
%42 = load i32, i32* @INADDR_ANY
%43 = call i32 @htonl(i32 %42)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0, i32 0
store i32 %43, i32* %44
%45 = call i32 @htons(i16 zeroext 10005)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
store i32 %45, i32* %46
%47 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%48 = call i64 @bind(i32 %31, %struct.sockaddr* %47, i32 12)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %35
%51 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %50, %35
%53 = call i64 @listen(i32 %31, i32 5)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %57
57: ; preds = %55, %52
store i32 12, i32* %5
%58 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0, i32 0
%60 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 0
br label %61
61: ; preds = %114, %57
%62 = phi i32 [ 0, %57 ], [ %63, %114 ]
%63 = add nuw nsw i32 %62, 1
%64 = call i32 @accept(i32 %31, %struct.sockaddr* %58, i32* %5)
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %68
68: ; preds = %66, %61
%69 = load i32, i32* @AF_INET
%70 = call %struct.hostent* @gethostbyaddr(i8* %15, i32 4, i32 %69)
%71 = icmp eq %struct.hostent* %70, null
br i1 %71, label %72, label %74
72: ; preds = %68
%73 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %74
74: ; preds = %72, %68
%75 = load i32, i32* %59
%76 = call i8* @inet_ntoa(i32 %75)
%77 = icmp eq i8* %76, null
br i1 %77, label %78, label %80
78: ; preds = %74
%79 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
br label %80
80: ; preds = %78, %74
%81 = getelementptr inbounds %struct.hostent, %struct.hostent* %70, i64 0, i32 0
%82 = load i8*, i8** %81
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.9, i64 0, i64 0), i32 %63, i8* %82, i8* %76)
%84 = call i32 @bzero(i8* %17, i32 1024)
%85 = call i32 @read(i32 %64, i8* %17, i32 1024)
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %93
87: ; preds = %89, %80
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 %63)
br label %114
89: ; preds = %98, %108
%90 = call i32 @bzero(i8* %17, i32 1024)
%91 = call i32 @read(i32 %64, i8* %17, i32 1024)
%92 = icmp eq i32 %91, 0
br i1 %92, label %87, label %93
93: ; preds = %80, %89
%94 = phi i32 [ %91, %89 ], [ %85, %80 ]
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %93
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0), i32 %63)
br label %114
98: ; preds = %93
%99 = call i64 @isEOM(i8* %17)
%100 = icmp eq i64 %99, 0
br i1 %100, label %89, label %101
101: ; preds = %98
%102 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0), i32 %63)
%103 = call i32 @sprintf(i8* %18, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %27, i32 %63)
%104 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.14, i64 0, i64 0), i32 %63, i8* %18)
%105 = load i32, i32* @O_RDONLY
%106 = call i32 @open(i8* %18, i32 %105)
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %110
108: ; preds = %101
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.15, i64 0, i64 0), i32 %63)
br label %89
110: ; preds = %101
%111 = call i32 @fstat(i32 %106, %struct.stat* %8)
store i32 0, i32* %4
%112 = load i32, i32* %60
%113 = call i32 @sendfile(i32 %64, i32 %106, i32* %4, i32 %112)
br label %114
114: ; preds = %110, %87, %96
%115 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.16, i64 0, i64 0), i32 %63)
%116 = call i32 @close(i32 %64)
%117 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
br label %61
}