#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 */
#define EWOULDBLOCK 128
int /*<<< orphan*/ MSG_ERRQUEUE;
int /*<<< orphan*/ debugPrint(char *);
int /*<<< orphan*/ debugPrintInt(char *, int);
int /*<<< orphan*/ debugPrintStr(char *, char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ realloc(char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
char *recvNonBlock(int streamID, int *stopPtr) {
  char *readBlock;
  readBlock = malloc(8192);
  memset(readBlock, 0, 8192);
  char *line = malloc(8192);
  memset(line, 0, 8192);
  int ret = 0;
  while (1) {
    int len = recv(streamID, line, 8192, MSG_ERRQUEUE);
    debugPrintStr(" INFO : connection : recvNonBlock : line : ", line);
    debugPrintInt(" INFO : connection : recvNonBlock : length : ", len);
    debugPrintInt(" INFO : connection : recvNonBlock : stop flag : ", *stopPtr);
    switch (len) {
    case -1:
      debugPrint("WARN : msn : connection : recvNonBlock : Socket Error");
      ret = 1;
      break;
    case 0:
      debugPrint("INFO : msn : connection : recvNonBlock : Socket Close");
      ret = 1;
      break;
    case EWOULDBLOCK:
      debugPrint("INFO : msn : connection : recvNonBlock : EAGAIN Block");
      ret = 1;
      break;
    default:
      readBlock = (char *)realloc(readBlock, strlen(readBlock) + strlen(line));
      sprintf(readBlock, "%s%s", readBlock, line);
      memset(line, 0, 8192);
      ret = 1;
    }
    if (ret == 1 || *stopPtr == 1) {
      break;
    }
  }
  readBlock[strlen(readBlock) - 1] = 0;
  return readBlock;
}


x86 assembly (clang, -O0):
<recvNonBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
mov    $0x2000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    0x2df0(%rip),%rax
mov    (%rax),%ecx
mov    $0x2000,%edx
call   1030 <recv@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xdf6(%rip),%rdi
call   1040 <debugPrintStr@plt>
mov    -0x28(%rbp),%esi
lea    0xe13(%rip),%rdi
call   1070 <debugPrintInt@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe2f(%rip),%rdi
call   1070 <debugPrintInt@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0xffffffff,%eax
je     1267 <recvNonBlock+0xd7>
jmp    1244 <recvNonBlock+0xb4>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
je     127f <recvNonBlock+0xef>
jmp    1254 <recvNonBlock+0xc4>
mov    -0x2c(%rbp),%eax
sub    $0x80,%eax
je     1297 <recvNonBlock+0x107>
jmp    12af <recvNonBlock+0x11f>
lea    0xe1d(%rip),%rdi
call   10a0 <debugPrint@plt>
movl   $0x1,-0x24(%rbp)
jmp    130d <recvNonBlock+0x17d>
lea    0xe3b(%rip),%rdi
call   10a0 <debugPrint@plt>
movl   $0x1,-0x24(%rbp)
jmp    130d <recvNonBlock+0x17d>
lea    0xe59(%rip),%rdi
call   10a0 <debugPrint@plt>
movl   $0x1,-0x24(%rbp)
jmp    130d <recvNonBlock+0x17d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rdi
add    %eax,%esi
call   1090 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe3c(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
movl   $0x1,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     1324 <recvNonBlock+0x194>
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jne    1329 <recvNonBlock+0x199>
jmp    132e <recvNonBlock+0x19e>
jmp    11e2 <recvNonBlock+0x52>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recvNonBlock>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x2000,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
mov    $0x2000,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2000,%edx
call   1030 <recv@plt>
mov    %eax,%ebp
lea    0xe0b(%rip),%rdi
mov    %rbx,%rsi
call   1040 <debugPrintStr@plt>
lea    0xe28(%rip),%rdi
mov    %ebp,%esi
call   1070 <debugPrintInt@plt>
mov    (%r15),%esi
lea    0xe45(%rip),%rdi
call   1070 <debugPrintInt@plt>
cmp    $0x80,%ebp
je     1239 <recvNonBlock+0xa9>
test   %ebp,%ebp
je     1247 <recvNonBlock+0xb7>
cmp    $0xffffffff,%ebp
jne    1255 <recvNonBlock+0xc5>
lea    0xe59(%rip),%rdi
call   10a0 <debugPrint@plt>
jmp    129a <recvNonBlock+0x10a>
lea    0xeb7(%rip),%rdi
call   10a0 <debugPrint@plt>
jmp    129a <recvNonBlock+0x10a>
lea    0xe73(%rip),%rdi
call   10a0 <debugPrint@plt>
jmp    129a <recvNonBlock+0x10a>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    %eax,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1090 <realloc@plt>
mov    %rax,%r14
lea    0xeb0(%rip),%rsi
mov    %rax,%rdi
mov    %rax,%rdx
mov    %rbx,%rcx
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MSG_ERRQUEUE = global i32 0
@.str = [44 x i8] c" INFO : connection : recvNonBlock : line : \00"
@.str.1 = [46 x i8] c" INFO : connection : recvNonBlock : length : \00"
@.str.2 = [49 x i8] c" INFO : connection : recvNonBlock : stop flag : \00"
@.str.3 = [54 x i8] c"WARN : msn : connection : recvNonBlock : Socket Error\00"
@.str.4 = [54 x i8] c"INFO : msn : connection : recvNonBlock : Socket Close\00"
@.str.5 = [54 x i8] c"INFO : msn : connection : recvNonBlock : EAGAIN Block\00"
@.str.6 = [5 x i8] c"%s%s\00"
define i8* @recvNonBlock(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%9 = call i8* @malloc(i32 8192)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 @memset(i8* %10, i32 0, i32 8192)
%12 = call i8* @malloc(i32 8192)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = call i32 @memset(i8* %13, i32 0, i32 8192)
store i32 0, i32* %7
br label %15
15: ; preds = %2, %57
%16 = load i32, i32* %3
%17 = load i8*, i8** %6
%18 = load i32, i32* @MSG_ERRQUEUE
%19 = call i32 @recv(i32 %16, i8* %17, i32 8192, i32 %18)
store i32 %19, i32* %8
%20 = load i8*, i8** %6
%21 = call i32 @debugPrintStr(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %8
%23 = call i32 @debugPrintInt(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32*, i32** %4
%25 = load i32, i32* %24
%26 = call i32 @debugPrintInt(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %8
switch i32 %27, label %34 [
i32 -1, label %28
i32 0, label %30
i32 128, label %32
]
28: ; preds = %15
%29 = call i32 @debugPrint(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %7
br label %49
30: ; preds = %15
%31 = call i32 @debugPrint(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %7
br label %49
32: ; preds = %15
%33 = call i32 @debugPrint(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %7
br label %49
34: ; preds = %15
%35 = load i8*, i8** %5
%36 = load i8*, i8** %5
%37 = call i32 @strlen(i8* %36)
%38 = load i8*, i8** %6
%39 = call i32 @strlen(i8* %38)
%40 = add nsw i32 %37, %39
%41 = call i64 @realloc(i8* %35, i32 %40)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %5
%43 = load i8*, i8** %5
%44 = load i8*, i8** %5
%45 = load i8*, i8** %6
%46 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %44, i8* %45)
%47 = load i8*, i8** %6
%48 = call i32 @memset(i8* %47, i32 0, i32 8192)
store i32 1, i32* %7
br label %49
49: ; preds = %34, %32, %30, %28
%50 = load i32, i32* %7
%51 = icmp eq i32 %50, 1
br i1 %51, label %56, label %52
52: ; preds = %49
%53 = load i32*, i32** %4
%54 = load i32, i32* %53
%55 = icmp eq i32 %54, 1
br i1 %55, label %56, label %57
56: ; preds = %52, %49
br label %58
57: ; preds = %52
br label %15
58: ; preds = %56
%59 = load i8*, i8** %5
%60 = load i8*, i8** %5
%61 = call i32 @strlen(i8* %60)
%62 = sub nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %59, i64 %63
store i8 0, i8* %64
%65 = load i8*, i8** %5
ret i8* %65
}

LLVM IR (-O2):
@MSG_ERRQUEUE = global i32 0
@.str = [44 x i8] c" INFO : connection : recvNonBlock : line : \00"
@.str.1 = [46 x i8] c" INFO : connection : recvNonBlock : length : \00"
@.str.2 = [49 x i8] c" INFO : connection : recvNonBlock : stop flag : \00"
@.str.3 = [54 x i8] c"WARN : msn : connection : recvNonBlock : Socket Error\00"
@.str.4 = [54 x i8] c"INFO : msn : connection : recvNonBlock : Socket Close\00"
@.str.5 = [54 x i8] c"INFO : msn : connection : recvNonBlock : EAGAIN Block\00"
@.str.6 = [5 x i8] c"%s%s\00"
define i8* @recvNonBlock(i32 %0, i32* nocapture %1) {
%3 = tail call dereferenceable_or_null(8192) i8* @malloc(i32 8192)
%4 = tail call i32 @memset(i8* %3, i32 0, i32 8192)
%5 = tail call dereferenceable_or_null(8192) i8* @malloc(i32 8192)
%6 = tail call i32 @memset(i8* %5, i32 0, i32 8192)
%7 = load i32, i32* @MSG_ERRQUEUE
%8 = tail call i32 @recv(i32 %0, i8* %5, i32 8192, i32 %7)
%9 = tail call i32 @debugPrintStr(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = tail call i32 @debugPrintInt(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%11 = load i32, i32* %1
%12 = tail call i32 @debugPrintInt(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %11)
switch i32 %8, label %19 [
i32 -1, label %13
i32 0, label %15
i32 128, label %17
]
13: ; preds = %2
%14 = tail call i32 @debugPrint(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
br label %27
15: ; preds = %2
%16 = tail call i32 @debugPrint(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
br label %27
17: ; preds = %2
%18 = tail call i32 @debugPrint(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
br label %27
19: ; preds = %2
%20 = tail call i32 @strlen(i8* %3)
%21 = tail call i32 @strlen(i8* %5)
%22 = add nsw i32 %21, %20
%23 = tail call i64 @realloc(i8* %3, i32 %22)
%24 = inttoptr i64 %23 to i8*
%25 = tail call i32 @sprintf(i8* dereferenceable(1) %24, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %24, i8* %5)
%26 = tail call i32 @memset(i8* %5, i32 0, i32 8192)
br label %27
27: ; preds = %13, %15, %17, %19
%28 = phi i8* [ %24, %19 ], [ %3, %17 ], [ %3, %15 ], [ %3, %13 ]
%29 = tail call i32 @strlen(i8* %28)
%30 = add nsw i32 %29, -1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 0, i8* %32
ret i8* %28
}