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

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
void *receiveData(void *args) {
  char buffer[1024];
  int block = 0;
  int newSocket = (intptr_t)args;
  while (recv(newSocket, buffer, 512, 0)) {
    printf("File name: %s\n", buffer);
    break;
  }
  FILE *fp;
  fp = fopen(buffer, "w");
  bzero(buffer, 512);
  while (block = recv(newSocket, buffer, 512, 0)) {
    fwrite(buffer, sizeof(char), block, fp);
    bzero(buffer, 512);
  }
  fclose(fp);
  return NULL;
}


x86 assembly (clang, -O0):
<receiveData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x414(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%eax
je     11b8 <receiveData+0x58>
lea    -0x410(%rbp),%rsi
lea    0xe4d(%rip),%rdi
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x200,%esi
call   1070 <bzero@plt>
mov    -0x418(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x414(%rbp)
cmp    $0x0,%eax
je     123f <receiveData+0xdf>
lea    -0x410(%rbp),%rdi
mov    -0x414(%rbp),%edx
mov    -0x420(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
lea    -0x410(%rbp),%rdi
mov    $0x200,%esi
call   1070 <bzero@plt>
jmp    11e3 <receiveData+0x83>
mov    -0x420(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receiveData>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
mov    %rsp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     1191 <receiveData+0x31>
lea    0xe77(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
lea    0xe77(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x200,%esi
call   1070 <bzero@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     1205 <receiveData+0xa5>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
call   1070 <bzero@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jne    11d0 <receiveData+0x70>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"File name: %s\0A\00"
@.str.1 = [2 x i8] c"w\00"
define i8* @receiveData(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %4
%7 = load i8*, i8** %2
%8 = ptrtoint i8* %7 to i64
%9 = trunc i64 %8 to i32
store i32 %9, i32* %5
br label %10
10: ; preds = %1
%11 = load i32, i32* %5
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = call i32 @recv(i32 %11, i8* %12, i32 512, i32 0)
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15, %10
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%22 = call i32 @bzero(i8* %21, i32 512)
br label %23
23: ; preds = %28, %18
%24 = load i32, i32* %5
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%26 = call i32 @recv(i32 %24, i8* %25, i32 512, i32 0)
store i32 %26, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %23
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%30 = load i32, i32* %4
%31 = load i32*, i32** %6
%32 = call i32 @fwrite(i8* %29, i32 1, i32 %30, i32* %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%34 = call i32 @bzero(i8* %33, i32 512)
br label %23
35: ; preds = %23
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
ret i8* null
}

LLVM IR (-O2):
@.str = [15 x i8] c"File name: %s\0A\00"
@.str.1 = [2 x i8] c"w\00"
define noalias i8* @receiveData(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = ptrtoint i8* %0 to i64
%5 = trunc i64 %4 to i32
%6 = call i32 @recv(i32 %5, i8* %3, i32 512, i32 0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %10
10: ; preds = %8, %1
%11 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @bzero(i8* %3, i32 512)
%13 = call i32 @recv(i32 %5, i8* %3, i32 512, i32 0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %10, %15
%16 = phi i32 [ %19, %15 ], [ %13, %10 ]
%17 = call i32 @fwrite(i8* %3, i32 1, i32 %16, i32* %11)
%18 = call i32 @bzero(i8* %3, i32 512)
%19 = call i32 @recv(i32 %5, i8* %3, i32 512, i32 0)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %15
21: ; preds = %15, %10
%22 = call i32 @fclose(i32* %11)
ret i8* null
}