#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*/ fname;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int clientList(int SSocket, int BSocket, int port, char *hserver) {
  char fname[1024];
  char sname[1024];
  int byteRecieve;
  if (recv(SSocket, sname, 1024, 0) == -1) {
    perror("Error retriving data from server\n");
    return -1;
  }
  printf("Receiving directory structure from %s:%d\n", hserver, port);
  memset(fname, 0, sizeof(fname));
  while ((byteRecieve = recv(BSocket, fname, 1024, 0)) > 0) {
    printf("%s", fname);
    memset(fname, 0, sizeof(fname));
  }
  if (byteRecieve < 0) {
    perror("error");
  }
  return 0;
}


x86 assembly (clang, -O0):
<clientList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jne    118f <clientList+0x4f>
lea    0xe82(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <clientList+0xe9>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x824(%rbp)
cmp    $0x0,%eax
jle    1209 <clientList+0xc9>
lea    -0x420(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
jmp    11b7 <clientList+0x77>
cmpl   $0x0,-0x824(%rbp)
jge    1222 <clientList+0xe2>
lea    0xe32(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clientList>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rcx,%r15
mov    %edx,%ebx
mov    %esi,%ebp
lea    0x400(%rsp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     1206 <clientList+0xc6>
lea    0xeaa(%rip),%rdi
xor    %r14d,%r14d
mov    %r15,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    11f1 <clientList+0xb1>
lea    0xe97(%rip),%r15
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jg     11c0 <clientList+0x80>
test   %eax,%eax
js     1215 <clientList+0xd5>
mov    %r14d,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%r14d
lea    0xded(%rip),%rdi
jmp    121c <clientList+0xdc>
lea    0xe33(%rip),%rdi
call   1060 <perror@plt>
jmp    11f5 <clientList+0xb5>

LLVM IR (-O0):
@.str = [34 x i8] c"Error retriving data from server\0A\00"
@.str.1 = [42 x i8] c"Receiving directory structure from %s:%d\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [6 x i8] c"error\00"
define i32 @clientList(i32 %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [1024 x i8]
%11 = alloca [1024 x i8]
%12 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%13 = load i32, i32* %6
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%15 = call i32 @recv(i32 %13, i8* %14, i32 1024, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %41
19: ; preds = %4
%20 = load i8*, i8** %9
%21 = load i32, i32* %8
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%24 = call i32 @memset(i8* %23, i32 0, i32 1024)
br label %25
25: ; preds = %30, %19
%26 = load i32, i32* %7
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%28 = call i32 @recv(i32 %26, i8* %27, i32 1024, i32 0)
store i32 %28, i32* %12
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%32 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%34 = call i32 @memset(i8* %33, i32 0, i32 1024)
br label %25
35: ; preds = %25
%36 = load i32, i32* %12
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
store i32 0, i32* %5
br label %41
41: ; preds = %40, %17
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
@.str = [34 x i8] c"Error retriving data from server\0A\00"
@.str.1 = [42 x i8] c"Receiving directory structure from %s:%d\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [6 x i8] c"error\00"
define i32 @clientList(i32 %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = call i32 @recv(i32 %0, i8* %8, i32 1024, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %24, label %11
11: ; preds = %4
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 %2)
%13 = call i32 @memset(i8* %7, i32 0, i32 1024)
%14 = call i32 @recv(i32 %1, i8* %7, i32 1024, i32 0)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %11, %16
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%18 = call i32 @memset(i8* %7, i32 0, i32 1024)
%19 = call i32 @recv(i32 %1, i8* %7, i32 1024, i32 0)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %16, label %21
21: ; preds = %16, %11
%22 = phi i32 [ %14, %11 ], [ %19, %16 ]
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21, %4
%25 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %21 ]
%26 = phi i32 [ -1, %4 ], [ 0, %21 ]
%27 = call i32 @perror(i8* %25)
br label %28
28: ; preds = %24, %21
%29 = phi i32 [ 0, %21 ], [ %26, %24 ]
ret i32 %29
}