#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 /*<<< orphan*/ their_addr;
struct sockaddr_storage {
  int /*<<< orphan*/ ss_family;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ s;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ handle_request(int);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int proxy(int start) {
  char *proxy_port = "8080";
  int sockfd, new_fd = 0;
  int status;
  struct addrinfo hints;
  struct addrinfo *servinfo, *p;
  struct sockaddr_storage their_addr;
  char s[INET6_ADDRSTRLEN];
  socklen_t addr_size;
  int yes = 1;
  signal(SIGCHLD, SIG_IGN);
  int pid;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  if ((status = getaddrinfo(NULL, proxy_port, &hints, &servinfo)) != 0) {
    printf("Error getting address info");
    exit(1);
  }
  sockfd = socket(servinfo->ai_family, servinfo->ai_socktype, 0);
  for (p = servinfo; p != NULL; p = p->ai_next) {
    if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
      perror("Error getting server socket");
      continue;
    }
    if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
      perror("Error setting the socket options");
      exit(1);
    }
    if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
      close(sockfd);
      perror("Error on server bind");
      continue;
    }
    break;
  }
  if ((listen(sockfd, 15)) == -1) {
    printf("Error on listen\n");
    exit(1);
  } else {
    printf("Listening on port %s...\n", proxy_port);
  }
  while (1) {
    addr_size = sizeof(their_addr);
    new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &addr_size);
    if (new_fd == -1) {
      printf("Error on accept\n");
      exit(1);
    }
    inet_ntop(their_addr.ss_family, get_in_addr((struct sockaddr *)&their_addr),
              s, sizeof(s));
    printf("Server has incoming connection from %s\n", s);
    pid = fork();
    if (pid < 0)
      perror("Error on fork");
    if (pid == 0) {
      close(sockfd);
      handle_request(new_fd);
      exit(0);
    } else {
      close(new_fd);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<proxy>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
lea    0xdeb(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x90(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x70(%rbp)
movl   $0x1,-0x78(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
mov    0x2d53(%rip),%rax
mov    (%rax),%esi
call   1090 <signal@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1100 <getaddrinfo@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     12e1 <proxy+0xe1>
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x50(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x50(%rbp),%rax
mov    0xc(%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     13d3 <proxy+0x1d3>
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x58(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1343 <proxy+0x143>
lea    0xce7(%rip),%rdi
call   10d0 <perror@plt>
jmp    13c2 <proxy+0x1c2>
mov    -0x14(%rbp),%edi
mov    0x2c9b(%rip),%rax
mov    (%rax),%esi
mov    0x2c52(%rip),%rax
mov    (%rax),%edx
lea    -0x78(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1386 <proxy+0x186>
lea    0xcc5(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x58(%rbp),%rax
mov    (%rax),%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    13bd <proxy+0x1bd>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
lea    0xcaa(%rip),%rdi
call   10d0 <perror@plt>
jmp    13c2 <proxy+0x1c2>
jmp    13d3 <proxy+0x1d3>
mov    -0x58(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    1301 <proxy+0x101>
mov    -0x14(%rbp),%edi
mov    $0xf,%esi
call   10b0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1401 <proxy+0x201>
lea    0xc82(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xc77(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1418 <proxy+0x218>
jmp    141d <proxy+0x21d>
movl   $0x4,-0x74(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
lea    -0x74(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1459 <proxy+0x259>
lea    0xc54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x60(%rbp),%eax
mov    %eax,-0x94(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <get_in_addr@plt>
mov    -0x94(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    %eax,%esi
mov    -0x90(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x88(%rbp),%rsi
lea    0xc17(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
jge    14bd <proxy+0x2bd>
lea    0xc1d(%rip),%rdi
call   10d0 <perror@plt>
cmpl   $0x0,-0x7c(%rbp)
jne    14de <proxy+0x2de>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%edi
call   10a0 <handle_request@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
jmp    1418 <proxy+0x218>

x86 assembly (clang, -O2):
<proxy>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
movl   $0x1,-0x34(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
call   10a0 <signal@plt>
lea    -0x70(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1080 <memset@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2d49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
lea    0xd65(%rip),%rsi
lea    -0x40(%rbp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   1110 <getaddrinfo@plt>
test   %eax,%eax
jne    12cf <proxy+0xbf>
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%esi
mov    0x10(%rax),%edi
xor    %edx,%edx
call   1130 <socket@plt>
mov    -0x40(%rbp),%rbx
test   %rbx,%rbx
jne    12e7 <proxy+0xd7>
mov    %eax,%r12d
jmp    1371 <proxy+0x161>
lea    0xd2f(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xd32(%rip),%r13
lea    0xd68(%rip),%r14
jmp    1319 <proxy+0x109>
nopw   0x0(%rax,%rax,1)
mov    %r12d,%edi
call   1090 <close@plt>
mov    %r14,%rdi
call   10e0 <perror@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     1371 <proxy+0x161>
mov    0x10(%rbx),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   1130 <socket@plt>
mov    %eax,%r12d
mov    %r13,%rdi
cmp    $0xffffffff,%eax
je     130b <proxy+0xfb>
mov    0x2caf(%rip),%rax
mov    (%rax),%esi
mov    0x2c66(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
lea    -0x34(%rbp),%rcx
mov    $0x4,%r8d
call   1060 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1465 <proxy+0x255>
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %r12d,%edi
call   10d0 <bind@plt>
cmp    $0xffffffff,%eax
je     1300 <proxy+0xf0>
mov    %r12d,%edi
mov    $0xf,%esi
call   10c0 <listen@plt>
cmp    $0xffffffff,%eax
jne    138c <proxy+0x17c>
lea    0xd47(%rip),%rdi
jmp    13c4 <proxy+0x1b4>
lea    0xcdf(%rip),%rdi
lea    0xc66(%rip),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
movl   $0x4,-0x2c(%rbp)
lea    -0x30(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    %r12d,%edi
call   10f0 <accept@plt>
cmp    $0xffffffff,%eax
jne    13d3 <proxy+0x1c3>
lea    0xcfd(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %eax,%ebx
lea    -0x30(%rbp),%r13
jmp    1414 <proxy+0x204>
lea    0xcd1(%rip),%rdi
call   10e0 <perror@plt>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1090 <close@plt>
movl   $0x4,-0x2c(%rbp)
mov    %r12d,%edi
mov    %r13,%rsi
lea    -0x2c(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     13bd <proxy+0x1ad>
mov    -0x30(%rbp),%r14d
mov    %r13,%rdi
call   1040 <get_in_addr@plt>
mov    %r14d,%edi
mov    %eax,%esi
mov    %r15,%rdx
mov    -0x48(%rbp),%rcx
call   1030 <inet_ntop@plt>
lea    0xc53(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
js     13db <proxy+0x1cb>
jne    13f0 <proxy+0x1e0>
mov    %r12d,%edi
call   1090 <close@plt>
mov    %ebx,%edi
call   10b0 <handle_request@plt>
xor    %edi,%edi
call   1100 <exit@plt>
lea    0xbd0(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"8080\00"
@INET6_ADDRSTRLEN = global i32 0
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [27 x i8] c"Error getting address info\00"
@.str.2 = [28 x i8] c"Error getting server socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [33 x i8] c"Error setting the socket options\00"
@.str.4 = [21 x i8] c"Error on server bind\00"
@.str.5 = [17 x i8] c"Error on listen\0A\00"
@.str.6 = [25 x i8] c"Listening on port %s...\0A\00"
@.str.7 = [17 x i8] c"Error on accept\0A\00"
@.str.8 = [40 x i8] c"Server has incoming connection from %s\0A\00"
@.str.9 = [14 x i8] c"Error on fork\00"
define i32 @proxy(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.addrinfo
%8 = alloca %struct.addrinfo*
%9 = alloca %struct.addrinfo*
%10 = alloca %struct.sockaddr_storage
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
store i32 0, i32* %5
%16 = load i32, i32* @INET6_ADDRSTRLEN
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %11
%19 = alloca i8, i64 %17
store i64 %17, i64* %12
store i32 1, i32* %14
%20 = load i32, i32* @SIGCHLD
%21 = load i32, i32* @SIG_IGN
%22 = call i32 @signal(i32 %20, i32 %21)
%23 = call i32 @memset(%struct.addrinfo* %7, i32 0, i32 40)
%24 = load i32, i32* @AF_UNSPEC
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 4
store i32 %24, i32* %25
%26 = load i32, i32* @SOCK_STREAM
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 3
store i32 %26, i32* %27
%28 = load i32, i32* @AI_PASSIVE
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 6
store i32 %28, i32* %29
%30 = load i8*, i8** %3
%31 = call i32 @getaddrinfo(i32* null, i8* %30, %struct.addrinfo* %7, %struct.addrinfo** %8)
store i32 %31, i32* %6
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %1
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %1
%37 = load %struct.addrinfo*, %struct.addrinfo** %8
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i32 0, i32 4
%39 = load i32, i32* %38
%40 = load %struct.addrinfo*, %struct.addrinfo** %8
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i32 0, i32 3
%42 = load i32, i32* %41
%43 = call i32 @socket(i32 %39, i32 %42, i32 0)
store i32 %43, i32* %4
%44 = load %struct.addrinfo*, %struct.addrinfo** %8
store %struct.addrinfo* %44, %struct.addrinfo** %9
br label %45
45: ; preds = %86, %36
%46 = load %struct.addrinfo*, %struct.addrinfo** %9
%47 = icmp ne %struct.addrinfo* %46, null
br i1 %47, label %48, label %90
48: ; preds = %45
%49 = load %struct.addrinfo*, %struct.addrinfo** %9
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i32 0, i32 4
%51 = load i32, i32* %50
%52 = load %struct.addrinfo*, %struct.addrinfo** %9
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %52, i32 0, i32 3
%54 = load i32, i32* %53
%55 = load %struct.addrinfo*, %struct.addrinfo** %9
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i32 0, i32 2
%57 = load i32, i32* %56
%58 = call i32 @socket(i32 %51, i32 %54, i32 %57)
store i32 %58, i32* %4
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %62
60: ; preds = %48
%61 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %86
62: ; preds = %48
%63 = load i32, i32* %4
%64 = load i32, i32* @SOL_SOCKET
%65 = load i32, i32* @SO_REUSEADDR
%66 = call i32 @setsockopt(i32 %63, i32 %64, i32 %65, i32* %14, i32 4)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %71
68: ; preds = %62
%69 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %62
%72 = load i32, i32* %4
%73 = load %struct.addrinfo*, %struct.addrinfo** %9
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %73, i32 0, i32 1
%75 = load i32, i32* %74
%76 = load %struct.addrinfo*, %struct.addrinfo** %9
%77 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i32 0, i32 0
%78 = load i32, i32* %77
%79 = call i32 @bind(i32 %72, i32 %75, i32 %78)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %85
81: ; preds = %71
%82 = load i32, i32* %4
%83 = call i32 @close(i32 %82)
%84 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %86
85: ; preds = %71
br label %90
86: ; preds = %81, %60
%87 = load %struct.addrinfo*, %struct.addrinfo** %9
%88 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %87, i32 0, i32 5
%89 = load %struct.addrinfo*, %struct.addrinfo** %88
store %struct.addrinfo* %89, %struct.addrinfo** %9
br label %45
90: ; preds = %85, %45
%91 = load i32, i32* %4
%92 = call i32 @listen(i32 %91, i32 15)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %97
94: ; preds = %90
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %90
%98 = load i8*, i8** %3
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %98)
br label %100
100: ; preds = %97
br label %101
101: ; preds = %136, %100
br label %102
102: ; preds = %101
store i32 4, i32* %13
%103 = load i32, i32* %4
%104 = bitcast %struct.sockaddr_storage* %10 to %struct.sockaddr*
%105 = call i32 @accept(i32 %103, %struct.sockaddr* %104, i32* %13)
store i32 %105, i32* %5
%106 = load i32, i32* %5
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %111
108: ; preds = %102
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%110 = call i32 @exit(i32 1)
unreachable
111: ; preds = %102
%112 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %10, i32 0, i32 0
%113 = load i32, i32* %112
%114 = bitcast %struct.sockaddr_storage* %10 to %struct.sockaddr*
%115 = call i32 @get_in_addr(%struct.sockaddr* %114)
%116 = trunc i64 %17 to i32
%117 = call i32 @inet_ntop(i32 %113, i32 %115, i8* %19, i32 %116)
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i8* %19)
%119 = call i32 (...) @fork()
store i32 %119, i32* %15
%120 = load i32, i32* %15
%121 = icmp slt i32 %120, 0
br i1 %121, label %122, label %124
122: ; preds = %111
%123 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %124
124: ; preds = %122, %111
%125 = load i32, i32* %15
%126 = icmp eq i32 %125, 0
br i1 %126, label %127, label %133
127: ; preds = %124
%128 = load i32, i32* %4
%129 = call i32 @close(i32 %128)
%130 = load i32, i32* %5
%131 = call i32 @handle_request(i32 %130)
%132 = call i32 @exit(i32 0)
unreachable
133: ; preds = %124
%134 = load i32, i32* %5
%135 = call i32 @close(i32 %134)
br label %136
136: ; preds = %133
br label %101
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"8080\00"
@INET6_ADDRSTRLEN = global i32 0
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [27 x i8] c"Error getting address info\00"
@.str.2 = [28 x i8] c"Error getting server socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [33 x i8] c"Error setting the socket options\00"
@.str.4 = [21 x i8] c"Error on server bind\00"
@.str.6 = [25 x i8] c"Listening on port %s...\0A\00"
@.str.8 = [40 x i8] c"Server has incoming connection from %s\0A\00"
@.str.9 = [14 x i8] c"Error on fork\00"
@str = [16 x i8] c"Error on accept\00"
@str.10 = [16 x i8] c"Error on listen\00"
define i32 @proxy(i32 %0) {
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.sockaddr_storage
%5 = alloca i32
%6 = alloca i32
%7 = bitcast %struct.addrinfo* %2 to i8*
%8 = bitcast %struct.addrinfo** %3 to i8*
%9 = bitcast %struct.sockaddr_storage* %4 to i8*
%10 = load i32, i32* @INET6_ADDRSTRLEN
%11 = zext i32 %10 to i64
%12 = alloca i8, i64 %11
%13 = bitcast i32* %5 to i8*
%14 = bitcast i32* %6 to i8*
store i32 1, i32* %6
%15 = load i32, i32* @SIGCHLD
%16 = load i32, i32* @SIG_IGN
%17 = tail call i32 @signal(i32 %15, i32 %16)
%18 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 40)
%19 = load i32, i32* @AF_UNSPEC
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 4
store i32 %19, i32* %20
%21 = load i32, i32* @SOCK_STREAM
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 3
store i32 %21, i32* %22
%23 = load i32, i32* @AI_PASSIVE
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 6
store i32 %23, i32* %24
%25 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %2, %struct.addrinfo** %3)
%26 = icmp eq i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %1
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %1
%31 = load %struct.addrinfo*, %struct.addrinfo** %3
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 4
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 3
%35 = load i32, i32* %34
%36 = call i32 @socket(i32 %33, i32 %35, i32 0)
%37 = load %struct.addrinfo*, %struct.addrinfo** %3
%38 = icmp eq %struct.addrinfo* %37, null
br i1 %38, label %72, label %39
39: ; preds = %30, %66
%40 = phi %struct.addrinfo* [ %70, %66 ], [ %37, %30 ]
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 4
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 3
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 2
%46 = load i32, i32* %45
%47 = call i32 @socket(i32 %42, i32 %44, i32 %46)
%48 = icmp eq i32 %47, -1
br i1 %48, label %66, label %49
49: ; preds = %39
%50 = load i32, i32* @SOL_SOCKET
%51 = load i32, i32* @SO_REUSEADDR
%52 = call i32 @setsockopt(i32 %47, i32 %50, i32 %51, i32* %6, i32 4)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %49
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 1
%59 = load i32, i32* %58
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 0
%61 = load i32, i32* %60
%62 = call i32 @bind(i32 %47, i32 %59, i32 %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %72
64: ; preds = %57
%65 = call i32 @close(i32 %47)
br label %66
66: ; preds = %39, %64
%67 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), %64 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), %39 ]
%68 = call i32 @perror(i8* %67)
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 5
%70 = load %struct.addrinfo*, %struct.addrinfo** %69
%71 = icmp eq %struct.addrinfo* %70, null
br i1 %71, label %72, label %39
72: ; preds = %66, %57, %30
%73 = phi i32 [ %36, %30 ], [ %47, %57 ], [ %47, %66 ]
%74 = call i32 @listen(i32 %73, i32 15)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %79
76: ; preds = %72
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.10, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %72
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%81 = bitcast %struct.sockaddr_storage* %4 to %struct.sockaddr*
store i32 4, i32* %5
%82 = call i32 @accept(i32 %73, %struct.sockaddr* %81, i32* %5)
%83 = icmp eq i32 %82, -1
br i1 %83, label %86, label %84
84: ; preds = %79
%85 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %4, i64 0, i32 0
br label %89
86: ; preds = %105, %79
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %84, %105
%90 = phi i32 [ %82, %84 ], [ %107, %105 ]
%91 = load i32, i32* %85
%92 = call i32 @get_in_addr(%struct.sockaddr* %81)
%93 = call i32 @inet_ntop(i32 %91, i32 %92, i8* %12, i32 %10)
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i8* %12)
%95 = call i32 (...) @fork()
%96 = icmp slt i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %89
%98 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %105
99: ; preds = %89
%100 = icmp eq i32 %95, 0
br i1 %100, label %101, label %105
101: ; preds = %99
%102 = call i32 @close(i32 %73)
%103 = call i32 @handle_request(i32 %90)
%104 = call i32 @exit(i32 0)
unreachable
105: ; preds = %97, %99
%106 = call i32 @close(i32 %90)
store i32 4, i32* %5
%107 = call i32 @accept(i32 %73, %struct.sockaddr* %81, i32* %5)
%108 = icmp eq i32 %107, -1
br i1 %108, label %86, label %89
}