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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
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 *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int downloadFile(int port, char *filename, char *opts) {
  int cfd, datafd, portno, pid;
  socklen_t sender_length;
  struct sockaddr_in rcv_addr, snd_addr;
  char *local_opts;
  if (filename == NULL) {
    fprintf(stderr, "Filename Null.\n");
    return -1;
  }
  if (opts == NULL) {
    local_opts = "w";
  } else {
    local_opts = opts;
  }
  datafd = socket(AF_INET, SOCK_STREAM, 0);
  if (datafd < 0)
    perror("ERROR opening socket");
  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("ERROR on binding, must have authorized access.");
  listen(datafd, 5);
  printf("Listening on port %d.\n", ntohs(rcv_addr.sin_port));
  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, local_opts);
      exit(0);
    } else {
      printf("In Parent\n");
      fflush(stdout);
      waitpid(pid, NULL, 0);
    }
  }
  close(datafd);
  return 0;
}


x86 assembly (clang, -O0):
<downloadFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    123f <downloadFile+0x3f>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1432 <downloadFile+0x232>
cmpq   $0x0,-0x18(%rbp)
jne    125a <downloadFile+0x5a>
lea    0xdbf(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    1262 <downloadFile+0x62>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1294 <downloadFile+0x94>
lea    0xd83(%rip),%rdi
call   10d0 <perror@plt>
lea    -0x38(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jge    12f2 <downloadFile+0xf2>
lea    0xd3a(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x20(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
mov    -0x38(%rbp),%edi
call   10a0 <ntohs@plt>
mov    %eax,%esi
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ca2(%rip),%rax
mov    (%rax),%rdi
call   1080 <fflush@plt>
movl   $0xc,-0x2c(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x54(%rbp)
cmp    $0x5,%eax
jge    1423 <downloadFile+0x223>
mov    -0x20(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    137b <downloadFile+0x17b>
lea    0xd01(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    13a9 <downloadFile+0x1a9>
lea    0xcde(%rip),%rdi
call   10d0 <perror@plt>
jmp    141e <downloadFile+0x21e>
cmpl   $0x0,-0x28(%rbp)
jne    13ee <downloadFile+0x1ee>
mov    -0x48(%rbp),%edi
call   10a0 <ntohs@plt>
mov    %eax,%esi
lea    0xcc7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    -0x50(%rbp),%rcx
lea    -0x48(%rbp),%rsi
call   1060 <dataConnect@plt>
xor    %edi,%edi
call   1100 <exit@plt>
lea    0xcbb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2bbd(%rip),%rax
mov    (%rax),%rdi
call   1080 <fflush@plt>
mov    -0x28(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10c0 <waitpid@plt>
jmp    141e <downloadFile+0x21e>
jmp    1334 <downloadFile+0x134>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<downloadFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %rsi,%rsi
je     14ac <downloadFile+0x29c>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2db2(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,%r12d
test   %eax,%eax
js     14d5 <downloadFile+0x2c5>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x0(%r13),%eax
mov    %eax,0x20(%rsp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x18(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
js     14e6 <downloadFile+0x2d6>
mov    %r12d,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
mov    0x18(%rsp),%edi
call   10b0 <ntohs@plt>
lea    0xd99(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2cf3(%rip),%r13
mov    0x0(%r13),%rdi
call   1090 <fflush@plt>
movl   $0xc,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r12d,%edi
call   1100 <accept@plt>
test   %eax,%eax
js     154c <downloadFile+0x33c>
mov    %eax,%ebp
xor    %edi,%edi
call   1090 <fflush@plt>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
js     14f7 <downloadFile+0x2e7>
je     1562 <downloadFile+0x352>
mov    %eax,%ebx
lea    0xd91(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%rdi
call   1090 <fflush@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r12d,%edi
call   1100 <accept@plt>
test   %eax,%eax
js     154c <downloadFile+0x33c>
mov    %eax,%ebp
xor    %edi,%edi
call   1090 <fflush@plt>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
js     1508 <downloadFile+0x2f8>
je     1562 <downloadFile+0x352>
mov    %eax,%ebx
lea    0xd37(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%rdi
call   1090 <fflush@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r12d,%edi
call   1100 <accept@plt>
test   %eax,%eax
js     154c <downloadFile+0x33c>
mov    %eax,%ebp
xor    %edi,%edi
call   1090 <fflush@plt>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
js     1519 <downloadFile+0x309>
je     1562 <downloadFile+0x352>
mov    %eax,%ebx
lea    0xcdd(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%rdi
call   1090 <fflush@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r12d,%edi
call   1100 <accept@plt>
test   %eax,%eax
js     154c <downloadFile+0x33c>
mov    %eax,%ebp
xor    %edi,%edi
call   1090 <fflush@plt>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
js     152a <downloadFile+0x31a>
je     1562 <downloadFile+0x352>
mov    %eax,%ebx
lea    0xc83(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%rdi
call   1090 <fflush@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r12d,%edi
call   1100 <accept@plt>
test   %eax,%eax
js     154c <downloadFile+0x33c>
mov    %eax,%ebp
xor    %edi,%edi
call   1090 <fflush@plt>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
js     153b <downloadFile+0x32b>
je     1562 <downloadFile+0x352>
mov    %eax,%ebx
lea    0xc29(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%rdi
call   1090 <fflush@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
mov    %r12d,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    14c6 <downloadFile+0x2b6>
mov    0x2b1d(%rip),%rax
mov    (%rax),%edi
lea    0xb44(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb36(%rip),%rdi
call   10e0 <perror@plt>
jmp    1255 <downloadFile+0x45>
lea    0xb3a(%rip),%rdi
call   10e0 <perror@plt>
jmp    12a0 <downloadFile+0x90>
lea    0xb7f(%rip),%rdi
call   10e0 <perror@plt>
jmp    1338 <downloadFile+0x128>
lea    0xb6e(%rip),%rdi
call   10e0 <perror@plt>
jmp    1392 <downloadFile+0x182>
lea    0xb5d(%rip),%rdi
call   10e0 <perror@plt>
jmp    13ec <downloadFile+0x1dc>
lea    0xb4c(%rip),%rdi
call   10e0 <perror@plt>
jmp    1446 <downloadFile+0x236>
lea    0xb3b(%rip),%rdi
call   10e0 <perror@plt>
jmp    14a0 <downloadFile+0x290>
lea    0xb1a(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
test   %r15,%r15
lea    0xaa4(%rip),%rbx
cmovne %r15,%rbx
mov    0x8(%rsp),%edi
call   10b0 <ntohs@plt>
lea    0xb0b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12d,%edi
call   1060 <close@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1070 <dataConnect@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Filename Null.\0A\00"
@.str.1 = [2 x i8] c"w\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [21 x i8] c"ERROR opening socket\00"
@INADDR_ANY = global i32 0
@.str.3 = [47 x i8] c"ERROR on binding, must have authorized access.\00"
@.str.4 = [23 x i8] c"Listening on port %d.\0A\00"
@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, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.sockaddr_in
%14 = alloca %struct.sockaddr_in
%15 = alloca i8*
%16 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %109
22: ; preds = %3
%23 = load i8*, i8** %7
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %22
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %15
br label %28
26: ; preds = %22
%27 = load i8*, i8** %7
store i8* %27, i8** %15
br label %28
28: ; preds = %26, %25
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_STREAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %28
%37 = bitcast %struct.sockaddr_in* %13 to i8*
%38 = call i32 @bzero(i8* %37, i32 12)
%39 = load i32, i32* %5
store i32 %39, i32* %10
%40 = load i32, i32* @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i32 %40, i32* %41
%42 = load i32, i32* @INADDR_ANY
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
%44 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %43, i32 0, i32 0
store i32 %42, i32* %44
%45 = load i32, i32* %10
%46 = call i32 @htons(i32 %45)
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
store i32 %46, i32* %47
%48 = load i32, i32* %9
%49 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%50 = call i64 @bind(i32 %48, %struct.sockaddr* %49, i32 12)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %36
%53 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52, %36
%55 = load i32, i32* %9
%56 = call i32 @listen(i32 %55, i32 5)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%58 = load i32, i32* %57
%59 = call i32 @ntohs(i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %59)
%61 = load i32*, i32** @stdout
%62 = call i32 @fflush(i32* %61)
store i32 12, i32* %12
store i32 0, i32* %16
br label %63
63: ; preds = %105, %54
%64 = load i32, i32* %16
%65 = add nsw i32 %64, 1
store i32 %65, i32* %16
%66 = icmp slt i32 %64, 5
br i1 %66, label %67, label %106
67: ; preds = %63
%68 = load i32, i32* %9
%69 = bitcast %struct.sockaddr_in* %14 to %struct.sockaddr*
%70 = call i32 @accept(i32 %68, %struct.sockaddr* %69, i32* %12)
store i32 %70, i32* %8
%71 = load i32, i32* %8
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %67
%74 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %67
%77 = call i32 @fflush(i32* null)
%78 = call i32 (...) @fork()
store i32 %78, i32* %11
%79 = load i32, i32* %11
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %76
%82 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %105
83: ; preds = %76
%84 = load i32, i32* %11
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %98
86: ; preds = %83
%87 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
%88 = load i32, i32* %87
%89 = call i32 @ntohs(i32 %88)
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %89)
%91 = load i32, i32* %9
%92 = call i32 @close(i32 %91)
%93 = load i32, i32* %8
%94 = load i8*, i8** %6
%95 = load i8*, i8** %15
%96 = call i32 @dataConnect(i32 %93, %struct.sockaddr_in* %14, i8* %94, i8* %95)
%97 = call i32 @exit(i32 0)
unreachable
98: ; preds = %83
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%100 = load i32*, i32** @stdout
%101 = call i32 @fflush(i32* %100)
%102 = load i32, i32* %11
%103 = call i32 @waitpid(i32 %102, i32* null, i32 0)
br label %104
104: ; preds = %98
br label %105
105: ; preds = %104, %81
br label %63
106: ; preds = %63
%107 = load i32, i32* %9
%108 = call i32 @close(i32 %107)
store i32 0, i32* %4
br label %109
109: ; preds = %106, %19
%110 = load i32, i32* %4
ret i32 %110
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Filename Null.\0A\00"
@.str.1 = [2 x i8] c"w\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [21 x i8] c"ERROR opening socket\00"
@INADDR_ANY = global i32 0
@.str.3 = [47 x i8] c"ERROR on binding, must have authorized access.\00"
@.str.4 = [23 x i8] c"Listening on port %d.\0A\00"
@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, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = bitcast %struct.sockaddr_in* %6 to i8*
%10 = icmp eq i8* %1, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %137
14: ; preds = %3
%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 = %14
%20 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
%22 = call i32 @bzero(i8* %8, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %25, i32* %26
%27 = tail call i32 @htons(i32 %0)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %27, i32* %28
%29 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%30 = call i64 @bind(i32 %17, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %21
%35 = call i32 @listen(i32 %17, i32 5)
%36 = load i32, i32* %28
%37 = call i32 @ntohs(i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = load i32*, i32** @stdout
%40 = call i32 @fflush(i32* %39)
store i32 12, i32* %4
%41 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%42 = call i32 @accept(i32 %17, %struct.sockaddr* %41, i32* %4)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %119, %103, %87, %71, %34
%45 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %34
%48 = call i32 @fflush(i32* null)
%49 = call i32 (...) @fork()
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %71
53: ; preds = %47
%54 = icmp eq i32 %49, 0
br i1 %54, label %55, label %66
55: ; preds = %126, %110, %94, %78, %53
%56 = phi i32 [ %42, %53 ], [ %72, %78 ], [ %88, %94 ], [ %104, %110 ], [ %120, %126 ]
%57 = icmp eq i8* %2, null
%58 = select i1 %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %2
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
%60 = load i32, i32* %59
%61 = call i32 @ntohs(i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %61)
%63 = call i32 @close(i32 %17)
%64 = call i32 @dataConnect(i32 %56, %struct.sockaddr_in* %6, i8* %1, i8* %58)
%65 = call i32 @exit(i32 0)
unreachable
66: ; preds = %53
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%68 = load i32*, i32** @stdout
%69 = call i32 @fflush(i32* %68)
%70 = call i32 @waitpid(i32 %49, i32* null, i32 0)
br label %71
71: ; preds = %66, %51
%72 = call i32 @accept(i32 %17, %struct.sockaddr* %41, i32* %4)
%73 = icmp slt i32 %72, 0
br i1 %73, label %44, label %74
74: ; preds = %71
%75 = call i32 @fflush(i32* null)
%76 = call i32 (...) @fork()
%77 = icmp slt i32 %76, 0
br i1 %77, label %85, label %78
78: ; preds = %74
%79 = icmp eq i32 %76, 0
br i1 %79, label %55, label %80
80: ; preds = %78
%81 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%82 = load i32*, i32** @stdout
%83 = call i32 @fflush(i32* %82)
%84 = call i32 @waitpid(i32 %76, i32* null, i32 0)
br label %87
85: ; preds = %74
%86 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %87
87: ; preds = %85, %80
%88 = call i32 @accept(i32 %17, %struct.sockaddr* %41, i32* %4)
%89 = icmp slt i32 %88, 0
br i1 %89, label %44, label %90
90: ; preds = %87
%91 = call i32 @fflush(i32* null)
%92 = call i32 (...) @fork()
%93 = icmp slt i32 %92, 0
br i1 %93, label %101, label %94
94: ; preds = %90
%95 = icmp eq i32 %92, 0
br i1 %95, label %55, label %96
96: ; preds = %94
%97 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%98 = load i32*, i32** @stdout
%99 = call i32 @fflush(i32* %98)
%100 = call i32 @waitpid(i32 %92, i32* null, i32 0)
br label %103
101: ; preds = %90
%102 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %103
103: ; preds = %101, %96
%104 = call i32 @accept(i32 %17, %struct.sockaddr* %41, i32* %4)
%105 = icmp slt i32 %104, 0
br i1 %105, label %44, label %106
106: ; preds = %103
%107 = call i32 @fflush(i32* null)
%108 = call i32 (...) @fork()
%109 = icmp slt i32 %108, 0
br i1 %109, label %117, label %110
110: ; preds = %106
%111 = icmp eq i32 %108, 0
br i1 %111, label %55, label %112
112: ; preds = %110
%113 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%114 = load i32*, i32** @stdout
%115 = call i32 @fflush(i32* %114)
%116 = call i32 @waitpid(i32 %108, i32* null, i32 0)
br label %119
117: ; preds = %106
%118 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %119
119: ; preds = %117, %112
%120 = call i32 @accept(i32 %17, %struct.sockaddr* %41, i32* %4)
%121 = icmp slt i32 %120, 0
br i1 %121, label %44, label %122
122: ; preds = %119
%123 = call i32 @fflush(i32* null)
%124 = call i32 (...) @fork()
%125 = icmp slt i32 %124, 0
br i1 %125, label %133, label %126
126: ; preds = %122
%127 = icmp eq i32 %124, 0
br i1 %127, label %55, label %128
128: ; preds = %126
%129 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%130 = load i32*, i32** @stdout
%131 = call i32 @fflush(i32* %130)
%132 = call i32 @waitpid(i32 %124, i32* null, i32 0)
br label %135
133: ; preds = %122
%134 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %135
135: ; preds = %133, %128
%136 = call i32 @close(i32 %17)
br label %137
137: ; preds = %135, %11
%138 = phi i32 [ -1, %11 ], [ 0, %135 ]
ret i32 %138
}