#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*/ validate;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int clientTranfer(int SSocket, int BSocket, char *filename, int port, int port2,
                  char *hserver) {
  char fname[1024];
  char validate[4];
  int bytesRecieve;
  printf("Receiving '%s' from %s:%d\n", filename, hserver, port);
  if (recv(SSocket, validate, sizeof(validate), 0) == -1) {
    perror("Error retriving data from server\n");
    return -1;
  }
  printf("dataSock:%s\n", validate);
  if (!strcmp(validate, "pass")) {
    FILE *fd = fopen(filename, "w");
    printf("Receiving '%s' from :%d\n", filename, port);
    while ((bytesRecieve = recv(BSocket, fname, 1024, 0)) > 0) {
      fwrite(fname, 1, bytesRecieve, fd);
    }
    if (bytesRecieve < 0) {
      return -1;
    }
    printf("File transfer complete.\n");
    fclose(fd);
  } else {
    printf("%s:%d says FILE NOT FOUND.\n", hserver, port2);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<clientTranfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x434(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jne    11e0 <clientTranfer+0x70>
lea    0xe4c(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e5 <clientTranfer+0x175>
lea    -0x434(%rbp),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x434(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12bd <clientTranfer+0x14d>
mov    -0x18(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x440(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x438(%rbp)
cmp    $0x0,%eax
jle    1285 <clientTranfer+0x115>
lea    -0x430(%rbp),%rdi
mov    -0x438(%rbp),%edx
mov    -0x440(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
jmp    123d <clientTranfer+0xcd>
cmpl   $0x0,-0x438(%rbp)
jge    129e <clientTranfer+0x12e>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e5 <clientTranfer+0x175>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x440(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12de <clientTranfer+0x16e>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e5 <clientTranfer+0x175>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clientTranfer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %r9,%rbx
mov    %r8d,%r12d
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%r13d
mov    %edi,%ebp
lea    0xe57(%rip),%rdi
mov    %rdx,%rsi
mov    %r9,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     12b9 <clientTranfer+0x139>
lea    0xe64(%rip),%rdi
lea    0xc(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe5b(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1219 <clientTranfer+0x99>
lea    0xe68(%rip),%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebp
jmp    12a5 <clientTranfer+0x125>
lea    0xe2f(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
mov    %rax,%r12
lea    0xe1f(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %r13d,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    128a <clientTranfer+0x10a>
lea    0x10(%rsp),%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1260 <clientTranfer+0xe0>
test   %ebp,%ebp
js     12a2 <clientTranfer+0x122>
lea    0xdf1(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
sar    $0x1f,%ebp
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5b(%rip),%rdi
call   1090 <perror@plt>
jmp    120f <clientTranfer+0x8f>

LLVM IR (-O0):
@.str = [27 x i8] c"Receiving '%s' from %s:%d\0A\00"
@.str.1 = [34 x i8] c"Error retriving data from server\0A\00"
@.str.2 = [13 x i8] c"dataSock:%s\0A\00"
@.str.3 = [5 x i8] c"pass\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [25 x i8] c"Receiving '%s' from :%d\0A\00"
@.str.6 = [25 x i8] c"File transfer complete.\0A\00"
@.str.7 = [28 x i8] c"%s:%d says FILE NOT FOUND.\0A\00"
define i32 @clientTranfer(i32 %0, i32 %1, i8* %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca [1024 x i8]
%15 = alloca [4 x i8]
%16 = alloca i32
%17 = alloca i32*
store i32 %0, i32* %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i8* %5, i8** %13
%18 = load i8*, i8** %10
%19 = load i8*, i8** %13
%20 = load i32, i32* %11
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19, i32 %20)
%22 = load i32, i32* %8
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
%24 = call i32 @recv(i32 %22, i8* %23, i32 4, i32 0)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %6
%27 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %7
br label %63
28: ; preds = %6
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %58, label %34
34: ; preds = %28
%35 = load i8*, i8** %10
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %36, i32** %17
%37 = load i8*, i8** %10
%38 = load i32, i32* %11
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %37, i32 %38)
br label %40
40: ; preds = %45, %34
%41 = load i32, i32* %9
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%43 = call i32 @recv(i32 %41, i8* %42, i32 1024, i32 0)
store i32 %43, i32* %16
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %40
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%47 = load i32, i32* %16
%48 = load i32*, i32** %17
%49 = call i32 @fwrite(i8* %46, i32 1, i32 %47, i32* %48)
br label %40
50: ; preds = %40
%51 = load i32, i32* %16
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %50
store i32 -1, i32* %7
br label %63
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%56 = load i32*, i32** %17
%57 = call i32 @fclose(i32* %56)
br label %62
58: ; preds = %28
%59 = load i8*, i8** %13
%60 = load i32, i32* %12
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %59, i32 %60)
store i32 -1, i32* %7
br label %63
62: ; preds = %54
store i32 0, i32* %7
br label %63
63: ; preds = %62, %58, %53, %26
%64 = load i32, i32* %7
ret i32 %64
}

LLVM IR (-O2):
@.str = [27 x i8] c"Receiving '%s' from %s:%d\0A\00"
@.str.1 = [34 x i8] c"Error retriving data from server\0A\00"
@.str.2 = [13 x i8] c"dataSock:%s\0A\00"
@.str.3 = [5 x i8] c"pass\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [25 x i8] c"Receiving '%s' from :%d\0A\00"
@.str.7 = [28 x i8] c"%s:%d says FILE NOT FOUND.\0A\00"
@str = [24 x i8] c"File transfer complete.\00"
define i32 @clientTranfer(i32 %0, i32 %1, i8* %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca [1024 x i8]
%8 = alloca [4 x i8]
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %5, i32 %3)
%12 = call i32 @recv(i32 %0, i8* %10, i32 4, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %40
16: ; preds = %6
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%18 = call i32 @strcmp(i8* %10, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %38
20: ; preds = %16
%21 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %2, i32 %3)
%23 = call i32 @recv(i32 %1, i8* %9, i32 1024, i32 0)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20, %25
%26 = phi i32 [ %28, %25 ], [ %23, %20 ]
%27 = call i32 @fwrite(i8* %9, i32 1, i32 %26, i32* %21)
%28 = call i32 @recv(i32 %1, i8* %9, i32 1024, i32 0)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %25, label %30
30: ; preds = %25, %20
%31 = phi i32 [ %23, %20 ], [ %28, %25 ]
%32 = icmp slt i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%35 = call i32 @fclose(i32* %21)
br label %36
36: ; preds = %30, %33
%37 = ashr i32 %31, 31
br label %40
38: ; preds = %16
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %5, i32 %4)
br label %40
40: ; preds = %36, %38, %14
%41 = phi i32 [ -1, %14 ], [ -1, %38 ], [ %37, %36 ]
ret i32 %41
}