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

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int read(int, char *, int);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ uiMessage(int, char *, char *);
char *sckRecv(int *sock) {
  char *ret;
  char buff[1024];
  int bytes;
  ret = (char *)malloc(sizeof(char));
  *ret = '\0';
  memset(buff, '\0', sizeof(buff));
  bytes = read(*sock, buff, sizeof(buff) - 1);
  if (bytes > 0) {
    buff[bytes] = '\0';
    ret = (char *)realloc(ret, bytes + 1);
    strcpy(ret, buff);
  }
  uiMessage(4, "<<< %s", ret);
  return ret;
}


x86 assembly (clang, -O0):
<sckRecv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
call   1050 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jle    11f6 <sckRecv+0x96>
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
mov    -0x414(%rbp),%esi
add    $0x1,%esi
call   1080 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdx
mov    $0x4,%edi
lea    0xdfa(%rip),%rsi
call   1060 <uiMessage@plt>
mov    -0x10(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sckRecv>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
mov    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    (%r14),%edi
mov    %r15,%rsi
mov    $0x3ff,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11c6 <sckRecv+0x66>
mov    %eax,%ecx
movb   $0x0,(%rsp,%rcx,1)
add    $0x1,%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0xe33(%rip),%rsi
mov    $0x4,%edi
mov    %rbx,%rdx
call   1060 <uiMessage@plt>
mov    %rbx,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"<<< %s\00"
define i8* @sckRecv(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i32
store i32* %0, i32** %2
%6 = call i64 @malloc(i32 1)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = load i8*, i8** %3
store i8 0, i8* %8
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i8 signext 0, i32 1024)
%11 = load i32*, i32** %2
%12 = load i32, i32* %11
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = call i32 @read(i32 %12, i8* %13, i32 1023)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %29
17: ; preds = %1
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %19
store i8 0, i8* %20
%21 = load i8*, i8** %3
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
%24 = call i64 @realloc(i8* %21, i32 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %3
%26 = load i8*, i8** %3
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%28 = call i32 @strcpy(i8* %26, i8* %27)
br label %29
29: ; preds = %17, %1
%30 = load i8*, i8** %3
%31 = call i32 @uiMessage(i32 4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
@.str = [7 x i8] c"<<< %s\00"
define i8* @sckRecv(i32* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @malloc(i32 1)
%5 = inttoptr i64 %4 to i8*
store i8 0, i8* %5
%6 = call i32 @memset(i8* %3, i8 signext 0, i32 1024)
%7 = load i32, i32* %0
%8 = call i32 @read(i32 %7, i8* %3, i32 1023)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = zext i32 %8 to i64
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %11
store i8 0, i8* %12
%13 = add nuw nsw i32 %8, 1
%14 = call i64 @realloc(i8* %5, i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = call i32 @strcpy(i8* %15, i8* %3)
br label %17
17: ; preds = %10, %1
%18 = phi i8* [ %15, %10 ], [ %5, %1 ]
%19 = call i32 @uiMessage(i32 4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %18)
ret i8* %18
}