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

/* Variables and functions */
int accept(int, int /*<<< orphan*/, int /*<<< orphan*/);
char *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *);
int read(int, ...);
const char *retList(int dataSocket) {
  char *dataBuff = "";
  int data1;
  data1 = accept(dataSocket, 0, 0);
  if (data1 < 0) {
    printf("accept failed\n");
    close(dataSocket);
    return dataBuff;
  } else {
    printf("data1 connection accepted on client\n");
  }
  int size;
  int rS = read(data1, &size, sizeof(size));
  dataBuff = calloc(size, sizeof(char));
  read(data1, dataBuff, size);
  close(data1);
  return dataBuff;
}


x86 assembly (clang, -O0):
<retList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
lea    0xeac(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1070 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11a0 <retList+0x50>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f4 <retList+0xa4>
lea    0xe68(%rip),%rdi
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    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<retList>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
xor    %esi,%esi
xor    %edx,%edx
call   1070 <accept@plt>
test   %eax,%eax
js     11b5 <retList+0x65>
mov    %eax,%ebx
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <read@plt>
mov    0xc(%rsp),%r14d
mov    %r14d,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbp
mov    %ebx,%edi
mov    %rax,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <read@plt>
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11cf <retList+0x7f>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1040 <close@plt>
lea    0xe62(%rip),%rbp
mov    %rbp,%rax
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"
define i8* @retList(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %4
%8 = load i32, i32* %3
%9 = call i32 @accept(i32 %8, i32 0, i32 0)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* %3
%15 = call i32 @close(i32 %14)
%16 = load i8*, i8** %4
store i8* %16, i8** %2
br label %31
17: ; preds = %1
%18 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17
%20 = load i32, i32* %5
%21 = call i32 (i32, ...) @read(i32 %20, i32* %6, i64 4)
store i32 %21, i32* %7
%22 = load i32, i32* %6
%23 = call i8* @calloc(i32 %22, i32 1)
store i8* %23, i8** %4
%24 = load i32, i32* %5
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = call i32 (i32, ...) @read(i32 %24, i8* %25, i32 %26)
%28 = load i32, i32* %5
%29 = call i32 @close(i32 %28)
%30 = load i8*, i8** %4
store i8* %30, i8** %2
br label %31
31: ; preds = %19, %12
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@str = [36 x i8] c"data1 connection accepted on client\00"
@str.3 = [14 x i8] c"accept failed\00"
define i8* @retList(i32 %0) {
%2 = alloca i32
%3 = tail call i32 @accept(i32 %0, i32 0, i32 0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.3, i64 0, i64 0))
%7 = tail call i32 @close(i32 %0)
br label %16
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%10 = bitcast i32* %2 to i8*
%11 = call i32 (i32, ...) @read(i32 %3, i32* %2, i64 4)
%12 = load i32, i32* %2
%13 = call i8* @calloc(i32 %12, i32 1)
%14 = call i32 (i32, ...) @read(i32 %3, i8* %13, i32 %12)
%15 = call i32 @close(i32 %3)
br label %16
16: ; preds = %8, %5
%17 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %5 ], [ %13, %8 ]
ret i8* %17
}