#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 accept(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, ...);
int retFile(int dataSocket, char *fileName) {
  char *dataBuff = "";
  int data1;
  data1 = accept(dataSocket, 0, 0);
  if (data1 < 0) {
    printf("accept failed\n");
    close(dataSocket);
    return 0;
  } else {
    printf("data1 connection accepted on client\n");
  }
  int size;
  int rS = read(data1, &size, sizeof(int));
  dataBuff = (char *)calloc(size, sizeof(char));
  read(data1, dataBuff, size);
  close(data1);
  FILE *filePtr = fopen(fileName, "wb");
  fwrite(dataBuff, 1, size, filePtr);
  printf("file recived :: %s :: %d\n", fileName, size);
  return 0;
}


x86 assembly (clang, -O0):
<retFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11c5 <retFile+0x55>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1258 <retFile+0xe8>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<retFile>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %esi,%esi
xor    %edx,%edx
call   1090 <accept@plt>
test   %eax,%eax
js     1221 <retFile+0xa1>
mov    %eax,%ebp
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1060 <read@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%edx
mov    %ebp,%edi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <read@plt>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe12(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    0xc(%rsp),%edx
lea    0xdee(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1234 <retFile+0xb4>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [15 x i8] c"accept failed\0A\00"
@.str.2 = [37 x i8] c"data1 connection accepted on client\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [26 x i8] c"file recived :: %s :: %d\0A\00"
define i32 @retFile(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
%11 = load i32, i32* %4
%12 = call i32 @accept(i32 %11, i32 0, i32 0)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* %4
%18 = call i32 @close(i32 %17)
store i32 0, i32* %3
br label %42
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19
%22 = load i32, i32* %7
%23 = call i32 (i32, ...) @read(i32 %22, i32* %8, i64 4)
store i32 %23, i32* %9
%24 = load i32, i32* %8
%25 = call i64 @calloc(i32 %24, i32 1)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %6
%27 = load i32, i32* %7
%28 = load i8*, i8** %6
%29 = load i32, i32* %8
%30 = call i32 (i32, ...) @read(i32 %27, i8* %28, i32 %29)
%31 = load i32, i32* %7
%32 = call i32 @close(i32 %31)
%33 = load i8*, i8** %5
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %10
%35 = load i8*, i8** %6
%36 = load i32, i32* %8
%37 = load i32*, i32** %10
%38 = call i32 @fwrite(i8* %35, i32 1, i32 %36, i32* %37)
%39 = load i8*, i8** %5
%40 = load i32, i32* %8
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %39, i32 %40)
store i32 0, i32* %3
br label %42
42: ; preds = %21, %15
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [26 x i8] c"file recived :: %s :: %d\0A\00"
@str = [36 x i8] c"data1 connection accepted on client\00"
@str.5 = [14 x i8] c"accept failed\00"
define i32 @retFile(i32 %0, i8* %1) {
%3 = alloca i32
%4 = tail call i32 @accept(i32 %0, i32 0, i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 @close(i32 %0)
br label %24
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%11 = bitcast i32* %3 to i8*
%12 = call i32 (i32, ...) @read(i32 %4, i32* %3, i64 4)
%13 = load i32, i32* %3
%14 = call i64 @calloc(i32 %13, i32 1)
%15 = inttoptr i64 %14 to i8*
%16 = load i32, i32* %3
%17 = call i32 (i32, ...) @read(i32 %4, i8* %15, i32 %16)
%18 = call i32 @close(i32 %4)
%19 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* %3
%21 = call i32 @fwrite(i8* %15, i32 1, i32 %20, i32* %19)
%22 = load i32, i32* %3
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %1, i32 %22)
br label %24
24: ; preds = %9, %6
ret i32 0
}