#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 TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ snd_addr;
typedef int /*<<< orphan*/ rcv_addr;
typedef int /*<<< orphan*/ optval;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ MSG_CONFIRM;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEPORT;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dataConnect(int, struct sockaddr_in *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int fork();
char *getIpAddress();
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int downloadFile(int control, int port, char *filename) {
  int cfd, datafd, portno, pid;
  socklen_t sender_length;
  char temp[50];
  char buffer[100];
  char *ip;
  struct sockaddr_in rcv_addr, snd_addr;
  datafd = socket(AF_INET, SOCK_STREAM, 0);
  if (datafd < 0)
    perror("ERROR opening socket");
  int optval = 1;
  if (setsockopt(datafd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)) < 0)
    perror("setsockopt()");
  bzero((char *)&rcv_addr, sizeof(rcv_addr));
  portno = port;
  rcv_addr.sin_family = AF_INET;
  rcv_addr.sin_addr.s_addr = INADDR_ANY;
  rcv_addr.sin_port = htons(portno);
  if (bind(datafd, (struct sockaddr *)&rcv_addr, sizeof(rcv_addr)) < 0)
    perror("bind(): must have authorized access.");
  int a = port & 0xFF;
  int b = (port >> 8) & 0xFF;
  sprintf(temp, "%d,%d\r\n", a, b);
  if ((ip = getIpAddress()) == NULL)
    return -1;
  sprintf(buffer, "PORT %s,%s", ip, temp);
  send(control, buffer, strlen(buffer), MSG_CONFIRM);
  listen(datafd, 5);
  fflush(stdout);
  sender_length = sizeof(snd_addr);
  int i = 0;
  while (i++ < 5) {
    cfd = accept(datafd, (struct sockaddr *)&snd_addr, &sender_length);
    if (cfd < 0) {
      perror("ERROR on accept");
      exit(1);
    }
    fflush(NULL);
    pid = fork();
    if (pid < 0)
      perror("ERROR on fork");
    else if (pid == 0) {
      printf("Server contacting from it's port %d\n", ntohs(snd_addr.sin_port));
      close(datafd);
      dataConnect(cfd, &snd_addr, filename);
      exit(0);
    } else {
      printf("In Parent\n");
      fflush(stdout);
      waitpid(pid, NULL, 0);
      break;
    }
  }
  close(datafd);
  return 0;
}


x86 assembly (clang, -O0):
<downloadFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    0x2d53(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1287 <downloadFile+0x47>
lea    0xd7e(%rip),%rdi
call   1100 <perror@plt>
movl   $0x1,-0xfc(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
mov    0x2d34(%rip),%rax
mov    (%rax),%edx
lea    -0xfc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12ce <downloadFile+0x8e>
lea    0xd4c(%rip),%rdi
call   1100 <perror@plt>
lea    -0xe8(%rbp),%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe0(%rbp)
mov    0x2cd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe4(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0xe8(%rbp)
mov    -0x20(%rbp),%edi
lea    -0xe8(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    133b <downloadFile+0xfb>
lea    0xcec(%rip),%rdi
call   1100 <perror@plt>
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x100(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x104(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x100(%rbp),%edx
mov    -0x104(%rbp),%ecx
lea    0xcd6(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
mov    $0x0,%al
call   1050 <getIpAddress@plt>
mov    %rax,-0xd8(%rbp)
cmp    $0x0,%rax
jne    139c <downloadFile+0x15c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1532 <downloadFile+0x2f2>
lea    -0xd0(%rbp),%rdi
mov    -0xd8(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    0xc9a(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x114(%rbp)
lea    -0xd0(%rbp),%rax
mov    %rax,-0x110(%rbp)
lea    -0xd0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x114(%rbp),%edi
mov    -0x110(%rbp),%rsi
mov    %eax,%edx
mov    0x2bd3(%rip),%rax
mov    (%rax),%ecx
call   1070 <send@plt>
mov    -0x20(%rbp),%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
mov    0x2ba0(%rip),%rax
mov    (%rax),%rdi
call   10b0 <fflush@plt>
movl   $0xc,-0x2c(%rbp)
movl   $0x0,-0x108(%rbp)
mov    -0x108(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x108(%rbp)
cmp    $0x5,%eax
jge    1523 <downloadFile+0x2e3>
mov    -0x20(%rbp),%edi
lea    -0xf8(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1120 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1479 <downloadFile+0x239>
lea    0xbf0(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <fflush@plt>
mov    $0x0,%al
call   1150 <fork@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    14a7 <downloadFile+0x267>
lea    0xbcd(%rip),%rdi
call   1100 <perror@plt>
jmp    151e <downloadFile+0x2de>
cmpl   $0x0,-0x28(%rbp)
jne    14ee <downloadFile+0x2ae>
mov    -0xf8(%rbp),%edi
call   10d0 <ntohs@plt>
mov    %eax,%esi
lea    0xbb3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
lea    -0xf8(%rbp),%rsi
call   10a0 <dataConnect@plt>
xor    %edi,%edi
call   1140 <exit@plt>
lea    0xba8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2aad(%rip),%rax
mov    (%rax),%rdi
call   10b0 <fflush@plt>
mov    -0x28(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10f0 <waitpid@plt>
jmp    1523 <downloadFile+0x2e3>
jmp    1429 <downloadFile+0x1e9>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<downloadFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
mov    %edi,%r15d
mov    0x2d70(%rip),%r12
mov    (%r12),%edi
mov    0x2d3d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,%r13d
test   %eax,%eax
js     141a <downloadFile+0x1ca>
movl   $0x1,0x1c(%rsp)
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
mov    0x2d31(%rip),%rax
mov    (%rax),%edx
lea    0x1c(%rsp),%rcx
mov    %r13d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     142b <downloadFile+0x1db>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   1120 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x28(%rsp)
mov    0x2cea(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    %ebx,%edi
call   1070 <htons@plt>
mov    %eax,0x20(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
test   %rax,%rax
js     143c <downloadFile+0x1ec>
movzbl %bl,%edx
movzbl %bh,%ecx
lea    0xd2a(%rip),%rsi
lea    0x30(%rsp),%rdi
xor    %eax,%eax
call   1140 <sprintf@plt>
xor    %eax,%eax
call   1060 <getIpAddress@plt>
test   %rax,%rax
je     1403 <downloadFile+0x1b3>
lea    0xd0f(%rip),%rsi
lea    0x70(%rsp),%rbp
lea    0x30(%rsp),%rcx
mov    %rbp,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1140 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    0x2c62(%rip),%rcx
mov    (%rcx),%ecx
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1080 <send@plt>
mov    %r13d,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
mov    0x2c27(%rip),%r12
mov    (%r12),%rdi
call   10c0 <fflush@plt>
movl   $0xc,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r13d,%edi
call   1130 <accept@plt>
test   %eax,%eax
js     1552 <downloadFile+0x302>
mov    %eax,%r15d
xor    %edi,%edi
call   10c0 <fflush@plt>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
js     144d <downloadFile+0x1fd>
mov    %eax,%ebp
test   %eax,%eax
je     1568 <downloadFile+0x318>
lea    0xcbf(%rip),%rdi
call   1030 <puts@plt>
mov    (%r12),%rdi
call   10c0 <fflush@plt>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1100 <waitpid@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
jmp    1408 <downloadFile+0x1b8>
mov    $0xffffffff,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbdf(%rip),%rdi
call   1110 <perror@plt>
jmp    128f <downloadFile+0x3f>
lea    0xbe3(%rip),%rdi
call   1110 <perror@plt>
jmp    12c5 <downloadFile+0x75>
lea    0xbdf(%rip),%rdi
call   1110 <perror@plt>
jmp    1310 <downloadFile+0xc0>
lea    0xc16(%rip),%rdi
call   1110 <perror@plt>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r13d,%edi
call   1130 <accept@plt>
test   %eax,%eax
js     1552 <downloadFile+0x302>
mov    %eax,%r15d
xor    %edi,%edi
call   10c0 <fflush@plt>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
jns    13cd <downloadFile+0x17d>
lea    0xbd7(%rip),%rdi
call   1110 <perror@plt>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r13d,%edi
call   1130 <accept@plt>
test   %eax,%eax
js     1552 <downloadFile+0x302>
mov    %eax,%r15d
xor    %edi,%edi
call   10c0 <fflush@plt>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
jns    13cd <downloadFile+0x17d>
lea    0xb98(%rip),%rdi
call   1110 <perror@plt>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r13d,%edi
call   1130 <accept@plt>
test   %eax,%eax
js     1552 <downloadFile+0x302>
mov    %eax,%r15d
xor    %edi,%edi
call   10c0 <fflush@plt>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
jns    13cd <downloadFile+0x17d>
lea    0xb5d(%rip),%rdi
call   1110 <perror@plt>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r13d,%edi
call   1130 <accept@plt>
test   %eax,%eax
js     1552 <downloadFile+0x302>
mov    %eax,%r15d
xor    %edi,%edi
call   10c0 <fflush@plt>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
jns    13cd <downloadFile+0x17d>
lea    0xb22(%rip),%rdi
call   1110 <perror@plt>
jmp    13f7 <downloadFile+0x1a7>
lea    0xb01(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    0x10(%rsp),%edi
call   10e0 <ntohs@plt>
lea    0xb00(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    %r14,%rdx
call   10b0 <dataConnect@plt>
xor    %edi,%edi
call   1150 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [21 x i8] c"ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEPORT = global i32 0
@.str.1 = [13 x i8] c"setsockopt()\00"
@INADDR_ANY = global i32 0
@.str.2 = [37 x i8] c"bind(): must have authorized access.\00"
@.str.3 = [8 x i8] c"%d,%d\0D\0A\00"
@.str.4 = [11 x i8] c"PORT %s,%s\00"
@MSG_CONFIRM = global i32 0
@stdout = global i32* null
@.str.5 = [16 x i8] c"ERROR on accept\00"
@.str.6 = [14 x i8] c"ERROR on fork\00"
@.str.7 = [37 x i8] c"Server contacting from it's port %d\0A\00"
@.str.8 = [11 x i8] c"In Parent\0A\00"
define i32 @downloadFile(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [50 x i8]
%14 = alloca [100 x i8]
%15 = alloca i8*
%16 = alloca %struct.sockaddr_in
%17 = alloca %struct.sockaddr_in
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %3
%28 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %3
store i32 1, i32* %18
%30 = load i32, i32* %9
%31 = load i32, i32* @SOL_SOCKET
%32 = load i32, i32* @SO_REUSEPORT
%33 = call i64 @setsockopt(i32 %30, i32 %31, i32 %32, i32* %18, i32 4)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
%38 = bitcast %struct.sockaddr_in* %16 to i8*
%39 = call i32 @bzero(i8* %38, i32 12)
%40 = load i32, i32* %6
store i32 %40, i32* %10
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 2
store i32 %41, i32* %42
%43 = load i32, i32* @INADDR_ANY
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
%45 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %44, i32 0, i32 0
store i32 %43, i32* %45
%46 = load i32, i32* %10
%47 = call i32 @htons(i32 %46)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
store i32 %47, i32* %48
%49 = load i32, i32* %9
%50 = bitcast %struct.sockaddr_in* %16 to %struct.sockaddr*
%51 = call i64 @bind(i32 %49, %struct.sockaddr* %50, i32 12)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %37
%54 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %53, %37
%56 = load i32, i32* %6
%57 = and i32 %56, 255
store i32 %57, i32* %19
%58 = load i32, i32* %6
%59 = ashr i32 %58, 8
%60 = and i32 %59, 255
store i32 %60, i32* %20
%61 = getelementptr inbounds [50 x i8], [50 x i8]* %13, i64 0, i64 0
%62 = load i32, i32* %19
%63 = load i32, i32* %20
%64 = call i32 (i8*, i8*, ...) @sprintf(i8* %61, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %62, i32 %63)
%65 = call i8* (...) @getIpAddress()
store i8* %65, i8** %15
%66 = icmp eq i8* %65, null
br i1 %66, label %67, label %68
67: ; preds = %55
store i32 -1, i32* %4
br label %127
68: ; preds = %55
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%70 = load i8*, i8** %15
%71 = getelementptr inbounds [50 x i8], [50 x i8]* %13, i64 0, i64 0
%72 = call i32 (i8*, i8*, ...) @sprintf(i8* %69, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %70, i8* %71)
%73 = load i32, i32* %5
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%75 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%76 = call i32 @strlen(i8* %75)
%77 = load i32, i32* @MSG_CONFIRM
%78 = call i32 @send(i32 %73, i8* %74, i32 %76, i32 %77)
%79 = load i32, i32* %9
%80 = call i32 @listen(i32 %79, i32 5)
%81 = load i32*, i32** @stdout
%82 = call i32 @fflush(i32* %81)
store i32 12, i32* %12
store i32 0, i32* %21
br label %83
83: ; preds = %123, %68
%84 = load i32, i32* %21
%85 = add nsw i32 %84, 1
store i32 %85, i32* %21
%86 = icmp slt i32 %84, 5
br i1 %86, label %87, label %124
87: ; preds = %83
%88 = load i32, i32* %9
%89 = bitcast %struct.sockaddr_in* %17 to %struct.sockaddr*
%90 = call i32 @accept(i32 %88, %struct.sockaddr* %89, i32* %12)
store i32 %90, i32* %8
%91 = load i32, i32* %8
%92 = icmp slt i32 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %87
%94 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %87
%97 = call i32 @fflush(i32* null)
%98 = call i32 (...) @fork()
store i32 %98, i32* %11
%99 = load i32, i32* %11
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %96
%102 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %123
103: ; preds = %96
%104 = load i32, i32* %11
%105 = icmp eq i32 %104, 0
br i1 %105, label %106, label %117
106: ; preds = %103
%107 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%108 = load i32, i32* %107
%109 = call i32 @ntohs(i32 %108)
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %109)
%111 = load i32, i32* %9
%112 = call i32 @close(i32 %111)
%113 = load i32, i32* %8
%114 = load i8*, i8** %7
%115 = call i32 @dataConnect(i32 %113, %struct.sockaddr_in* %17, i8* %114)
%116 = call i32 @exit(i32 0)
unreachable
117: ; preds = %103
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%119 = load i32*, i32** @stdout
%120 = call i32 @fflush(i32* %119)
%121 = load i32, i32* %11
%122 = call i32 @waitpid(i32 %121, i32* null, i32 0)
br label %124
123: ; preds = %101
br label %83
124: ; preds = %117, %83
%125 = load i32, i32* %9
%126 = call i32 @close(i32 %125)
store i32 0, i32* %4
br label %127
127: ; preds = %124, %67
%128 = load i32, i32* %4
ret i32 %128
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [21 x i8] c"ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEPORT = global i32 0
@.str.1 = [13 x i8] c"setsockopt()\00"
@INADDR_ANY = global i32 0
@.str.2 = [37 x i8] c"bind(): must have authorized access.\00"
@.str.3 = [8 x i8] c"%d,%d\0D\0A\00"
@.str.4 = [11 x i8] c"PORT %s,%s\00"
@MSG_CONFIRM = global i32 0
@stdout = global i32* null
@.str.5 = [16 x i8] c"ERROR on accept\00"
@.str.6 = [14 x i8] c"ERROR on fork\00"
@.str.7 = [37 x i8] c"Server contacting from it's port %d\0A\00"
@str = [10 x i8] c"In Parent\00"
define i32 @downloadFile(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca [50 x i8]
%6 = alloca [100 x i8]
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = bitcast i32* %4 to i8*
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%13 = bitcast %struct.sockaddr_in* %7 to i8*
%14 = bitcast %struct.sockaddr_in* %8 to i8*
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %3
%20 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %3
%22 = bitcast i32* %9 to i8*
store i32 1, i32* %9
%23 = load i32, i32* @SOL_SOCKET
%24 = load i32, i32* @SO_REUSEPORT
%25 = call i64 @setsockopt(i32 %17, i32 %23, i32 %24, i32* %9, i32 4)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %21
%30 = call i32 @bzero(i8* %13, i32 12)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i32 %31, i32* %32
%33 = load i32, i32* @INADDR_ANY
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1, i32 0
store i32 %33, i32* %34
%35 = call i32 @htons(i32 %1)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
store i32 %35, i32* %36
%37 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%38 = call i64 @bind(i32 %17, %struct.sockaddr* %37, i32 12)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %29
%41 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %29
%43 = and i32 %1, 255
%44 = lshr i32 %1, 8
%45 = and i32 %44, 255
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 %45)
%47 = call i8* (...) @getIpAddress()
%48 = icmp eq i8* %47, null
br i1 %48, label %120, label %49
49: ; preds = %42
%50 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %47, i8* %11)
%51 = call i32 @strlen(i8* %12)
%52 = load i32, i32* @MSG_CONFIRM
%53 = call i32 @send(i32 %0, i8* %12, i32 %51, i32 %52)
%54 = call i32 @listen(i32 %17, i32 5)
%55 = load i32*, i32** @stdout
%56 = call i32 @fflush(i32* %55)
store i32 12, i32* %4
%57 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%58 = call i32 @accept(i32 %17, %struct.sockaddr* %57, i32* %4)
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %91, %83, %75, %67, %49
%61 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %49
%64 = call i32 @fflush(i32* null)
%65 = call i32 (...) @fork()
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %101
67: ; preds = %63
%68 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%69 = call i32 @accept(i32 %17, %struct.sockaddr* %57, i32* %4)
%70 = icmp slt i32 %69, 0
br i1 %70, label %60, label %71
71: ; preds = %67
%72 = call i32 @fflush(i32* null)
%73 = call i32 (...) @fork()
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %101
75: ; preds = %71
%76 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%77 = call i32 @accept(i32 %17, %struct.sockaddr* %57, i32* %4)
%78 = icmp slt i32 %77, 0
br i1 %78, label %60, label %79
79: ; preds = %75
%80 = call i32 @fflush(i32* null)
%81 = call i32 (...) @fork()
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %101
83: ; preds = %79
%84 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%85 = call i32 @accept(i32 %17, %struct.sockaddr* %57, i32* %4)
%86 = icmp slt i32 %85, 0
br i1 %86, label %60, label %87
87: ; preds = %83
%88 = call i32 @fflush(i32* null)
%89 = call i32 (...) @fork()
%90 = icmp slt i32 %89, 0
br i1 %90, label %91, label %101
91: ; preds = %87
%92 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%93 = call i32 @accept(i32 %17, %struct.sockaddr* %57, i32* %4)
%94 = icmp slt i32 %93, 0
br i1 %94, label %60, label %95
95: ; preds = %91
%96 = call i32 @fflush(i32* null)
%97 = call i32 (...) @fork()
%98 = icmp slt i32 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %95
%100 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %118
101: ; preds = %95, %87, %79, %71, %63
%102 = phi i32 [ %65, %63 ], [ %73, %71 ], [ %81, %79 ], [ %89, %87 ], [ %97, %95 ]
%103 = phi i32 [ %58, %63 ], [ %69, %71 ], [ %77, %79 ], [ %85, %87 ], [ %93, %95 ]
%104 = icmp eq i32 %102, 0
br i1 %104, label %105, label %113
105: ; preds = %101
%106 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 0
%107 = load i32, i32* %106
%108 = call i32 @ntohs(i32 %107)
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %108)
%110 = call i32 @close(i32 %17)
%111 = call i32 @dataConnect(i32 %103, %struct.sockaddr_in* %8, i8* %2)
%112 = call i32 @exit(i32 0)
unreachable
113: ; preds = %101
%114 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%115 = load i32*, i32** @stdout
%116 = call i32 @fflush(i32* %115)
%117 = call i32 @waitpid(i32 %102, i32* null, i32 0)
br label %118
118: ; preds = %99, %113
%119 = call i32 @close(i32 %17)
br label %120
120: ; preds = %42, %118
%121 = phi i32 [ 0, %118 ], [ -1, %42 ]
ret i32 %121
}