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

/* Variables and functions */
int /*<<< orphan*/ debugPrint(char *);
int /*<<< orphan*/ debugPrintStr(char *, char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int recv(int, char *, int, int /*<<< orphan*/);
char *receive(int streamID) {
  char *dir = malloc(8192);
  int len = recv(streamID, dir, 8192, 0);
  if (len > 8192) {
    debugPrint("WARN : msn : connection : receive : Buffer too small!");
    len = 8192;
  }
  if (len == -1) {
    debugPrint("INFO : msn : connection : receive : Connection ending.");
    perror("recv");
    return NULL;
  } else {
    debugPrintStr("INFO : msn : connection : receive : ", dir);
    return dir;
  }
}


x86 assembly (clang, -O0):
<receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    $0x2000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x2000,-0x1c(%rbp)
jle    119f <receive+0x4f>
lea    0xe6d(%rip),%rdi
call   1060 <debugPrint@plt>
movl   $0x2000,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ce <receive+0x7e>
lea    0xe86(%rip),%rdi
call   1060 <debugPrint@plt>
lea    0xeb1(%rip),%rdi
call   1070 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e6 <receive+0x96>
mov    -0x18(%rbp),%rsi
lea    0xe99(%rip),%rdi
call   1040 <debugPrintStr@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x2000,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x2001,%eax
jl     1188 <receive+0x38>
lea    0xe7f(%rip),%rdi
call   1060 <debugPrint@plt>
jmp    118d <receive+0x3d>
cmp    $0xffffffff,%eax
je     11a6 <receive+0x56>
lea    0xede(%rip),%rdi
mov    %rbx,%rsi
call   1040 <debugPrintStr@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe89(%rip),%rdi
call   1060 <debugPrint@plt>
lea    0xeb4(%rip),%rdi
call   1070 <perror@plt>
xor    %ebx,%ebx
jmp    119c <receive+0x4c>

LLVM IR (-O0):
@.str = [54 x i8] c"WARN : msn : connection : receive : Buffer too small!\00"
@.str.1 = [55 x i8] c"INFO : msn : connection : receive : Connection ending.\00"
@.str.2 = [5 x i8] c"recv\00"
@.str.3 = [37 x i8] c"INFO : msn : connection : receive : \00"
define i8* @receive(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i8* @malloc(i32 8192)
store i8* %6, i8** %4
%7 = load i32, i32* %3
%8 = load i8*, i8** %4
%9 = call i32 @recv(i32 %7, i8* %8, i32 8192, i32 0)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 8192
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @debugPrint(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
store i32 8192, i32* %5
br label %14
14: ; preds = %12, %1
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = call i32 @debugPrint(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %2
br label %24
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = call i32 @debugPrintStr(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %4
store i8* %23, i8** %2
br label %24
24: ; preds = %20, %17
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@.str = [54 x i8] c"WARN : msn : connection : receive : Buffer too small!\00"
@.str.1 = [55 x i8] c"INFO : msn : connection : receive : Connection ending.\00"
@.str.2 = [5 x i8] c"recv\00"
@.str.3 = [37 x i8] c"INFO : msn : connection : receive : \00"
define i8* @receive(i32 %0) {
%2 = tail call dereferenceable_or_null(8192) i8* @malloc(i32 8192)
%3 = tail call i32 @recv(i32 %0, i8* %2, i32 8192, i32 0)
%4 = icmp sgt i32 %3, 8192
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @debugPrint(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
br label %12
7: ; preds = %1
%8 = icmp eq i32 %3, -1
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = tail call i32 @debugPrint(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %14
12: ; preds = %5, %7
%13 = tail call i32 @debugPrintStr(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %14
14: ; preds = %12, %9
%15 = phi i8* [ null, %9 ], [ %2, %12 ]
ret i8* %15
}