#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int recv_line(int, char *, int);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
char *recv_data(int sock) {
  int count_recv, buff_len = 65;
  char temp_recv[10];
  char *buff, *temp, *end = NULL;
  if (sock <= 0) {
    fprintf(stderr, "Incorrect socket passed\n");
    return NULL;
  }
  if ((buff = malloc(buff_len * sizeof(char))) == NULL) {
    fprintf(stderr, "Out of memmory\n");
    return NULL;
  }
  if ((count_recv = (recv_line(sock, buff, (65 - 1)))) <= 0) {
    if (count_recv = 0) {
      fprintf(stderr, "Connection to server lost\n");
      free(buff);
      return NULL;
    }
    if (count_recv < 0) {
      fprintf(stderr, "Error in connection\n");
      free(buff);
      return NULL;
    }
  }
  if ((end = strstr(buff, "\r\n")) != NULL) {
    end[2] = '\0';
    return buff;
  }
  while (end == NULL) {
    if ((temp = malloc(buff_len + 10)) == NULL) {
      fprintf(stderr, "Out of memmory\n");
      free(buff);
      return NULL;
    }
    memset(temp, 0, buff_len + 10);
    memcpy(temp, buff, ((buff_len - 1) * sizeof(char)));
    free(buff);
    buff = temp;
    if ((count_recv = (recv_line(sock, temp_recv, 10))) <= 0) {
      if (count_recv = 0) {
        fprintf(stderr, "Connection to server lost\n");
        free(buff);
        return NULL;
      }
      if (count_recv < 0) {
        fprintf(stderr, "Error in connection\n");
        free(buff);
        return NULL;
      }
    }
    memcpy(buff + buff_len - 1, temp_recv, count_recv * sizeof(char));
    buff_len += 10;
    end = strstr(buff, "\r\n");
  }
  end[2] = '\0';
  return buff;
}


x86 assembly (clang, -O0):
<recv_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x41,-0x14(%rbp)
movq   $0x0,-0x38(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     11b6 <recv_data+0x46>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    143d <recv_data+0x2cd>
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11f5 <recv_data+0x85>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    143d <recv_data+0x2cd>
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x40,%edx
call   1080 <recv_line@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jg     128d <recv_data+0x11d>
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
test   $0x1,%al
jne    1228 <recv_data+0xb8>
jmp    1253 <recv_data+0xe3>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    143d <recv_data+0x2cd>
cmpl   $0x0,-0x10(%rbp)
jge    1288 <recv_data+0x118>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    143d <recv_data+0x2cd>
jmp    128d <recv_data+0x11d>
mov    -0x28(%rbp),%rdi
lea    0xdc1(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     12c0 <recv_data+0x150>
mov    -0x38(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    143d <recv_data+0x2cd>
jmp    12c5 <recv_data+0x155>
cmpq   $0x0,-0x38(%rbp)
jne    142d <recv_data+0x2bd>
mov    -0x14(%rbp),%edi
add    $0xa,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1314 <recv_data+0x1a4>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
lea    0xd20(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    143d <recv_data+0x2cd>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    $0xa,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    $0xa,%edx
call   1080 <recv_line@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jg     13e9 <recv_data+0x279>
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
test   $0x1,%al
jne    1384 <recv_data+0x214>
jmp    13af <recv_data+0x23f>
mov    0x2c55(%rip),%rax
mov    (%rax),%edi
lea    0xc95(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    143d <recv_data+0x2cd>
cmpl   $0x0,-0x10(%rbp)
jge    13e4 <recv_data+0x274>
mov    0x2c20(%rip),%rax
mov    (%rax),%edi
lea    0xc7b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    143d <recv_data+0x2cd>
jmp    13e9 <recv_data+0x279>
mov    -0x28(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
add    $0xffffffffffffffff,%rdi
lea    -0x1e(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x14(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xc3a(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x38(%rbp)
jmp    12c5 <recv_data+0x155>
mov    -0x38(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jle    11c1 <recv_data+0x51>
mov    %edi,%r14d
mov    $0x41,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11d3 <recv_data+0x63>
mov    %rax,%r13
mov    %r14d,%edi
mov    %rax,%rsi
mov    $0x40,%edx
call   1080 <recv_line@plt>
lea    0xe7b(%rip),%rsi
mov    %r13,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     11fd <recv_data+0x8d>
movb   $0x0,0x2(%rax)
jmp    11eb <recv_data+0x7b>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
jmp    11e3 <recv_data+0x73>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1050 <fprintf@plt>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x40,%ebp
lea    0xe(%rsp),%r15
nopw   0x0(%rax,%rax,1)
lea    0xb(%rbp),%r12
mov    %r12d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1297 <recv_data+0x127>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1060 <memcpy@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0xa,%edx
call   1080 <recv_line@plt>
test   %eax,%eax
mov    $0x0,%ecx
cmovs  %ecx,%eax
mov    %rbx,%rdi
add    %rbp,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    %rbx,%rdi
lea    0xdaf(%rip),%rsi
call   1090 <strstr@plt>
add    $0xa,%rbp
mov    %rbx,%r13
test   %rax,%rax
je     1210 <recv_data+0xa0>
movb   $0x0,0x2(%rax)
mov    %rbx,%r13
jmp    11eb <recv_data+0x7b>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    11e8 <recv_data+0x78>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Incorrect socket passed\0A\00"
@.str.1 = [16 x i8] c"Out of memmory\0A\00"
@.str.2 = [27 x i8] c"Connection to server lost\0A\00"
@.str.3 = [21 x i8] c"Error in connection\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
define i8* @recv_data(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %3
store i32 65, i32* %5
store i8* null, i8** %9
%10 = load i32, i32* %3
%11 = icmp sle i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %122
15: ; preds = %1
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %122
25: ; preds = %15
%26 = load i32, i32* %3
%27 = load i8*, i8** %7
%28 = call i32 @recv_line(i32 %26, i8* %27, i32 64)
store i32 %28, i32* %4
%29 = icmp sle i32 %28, 0
br i1 %29, label %30, label %45
30: ; preds = %25
store i32 0, i32* %4
br i1 false, label %31, label %36
31: ; preds = %30
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%34 = load i8*, i8** %7
%35 = call i32 @free(i8* %34)
store i8* null, i8** %2
br label %122
36: ; preds = %30
%37 = load i32, i32* %4
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%42 = load i8*, i8** %7
%43 = call i32 @free(i8* %42)
store i8* null, i8** %2
br label %122
44: ; preds = %36
br label %45
45: ; preds = %44, %25
%46 = load i8*, i8** %7
%47 = call i8* @strstr(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i8* %47, i8** %9
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = load i8*, i8** %9
%51 = getelementptr inbounds i8, i8* %50, i64 2
store i8 0, i8* %51
%52 = load i8*, i8** %7
store i8* %52, i8** %2
br label %122
53: ; preds = %45
br label %54
54: ; preds = %102, %53
%55 = load i8*, i8** %9
%56 = icmp eq i8* %55, null
br i1 %56, label %57, label %118
57: ; preds = %54
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 10
%60 = call i8* @malloc(i32 %59)
store i8* %60, i8** %8
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %67
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%65 = load i8*, i8** %7
%66 = call i32 @free(i8* %65)
store i8* null, i8** %2
br label %122
67: ; preds = %57
%68 = load i8*, i8** %8
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 10
%71 = call i32 @memset(i8* %68, i32 0, i32 %70)
%72 = load i8*, i8** %8
%73 = load i8*, i8** %7
%74 = load i32, i32* %5
%75 = sub nsw i32 %74, 1
%76 = sext i32 %75 to i64
%77 = mul i64 %76, 1
%78 = trunc i64 %77 to i32
%79 = call i32 @memcpy(i8* %72, i8* %73, i32 %78)
%80 = load i8*, i8** %7
%81 = call i32 @free(i8* %80)
%82 = load i8*, i8** %8
store i8* %82, i8** %7
%83 = load i32, i32* %3
%84 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%85 = call i32 @recv_line(i32 %83, i8* %84, i32 10)
store i32 %85, i32* %4
%86 = icmp sle i32 %85, 0
br i1 %86, label %87, label %102
87: ; preds = %67
store i32 0, i32* %4
br i1 false, label %88, label %93
88: ; preds = %87
%89 = load i32, i32* @stderr
%90 = call i32 @fprintf(i32 %89, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%91 = load i8*, i8** %7
%92 = call i32 @free(i8* %91)
store i8* null, i8** %2
br label %122
93: ; preds = %87
%94 = load i32, i32* %4
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %101
96: ; preds = %93
%97 = load i32, i32* @stderr
%98 = call i32 @fprintf(i32 %97, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%99 = load i8*, i8** %7
%100 = call i32 @free(i8* %99)
store i8* null, i8** %2
br label %122
101: ; preds = %93
br label %102
102: ; preds = %101, %67
%103 = load i8*, i8** %7
%104 = load i32, i32* %5
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8, i8* %103, i64 %105
%107 = getelementptr inbounds i8, i8* %106, i64 -1
%108 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%109 = load i32, i32* %4
%110 = sext i32 %109 to i64
%111 = mul i64 %110, 1
%112 = trunc i64 %111 to i32
%113 = call i32 @memcpy(i8* %107, i8* %108, i32 %112)
%114 = load i32, i32* %5
%115 = add nsw i32 %114, 10
store i32 %115, i32* %5
%116 = load i8*, i8** %7
%117 = call i8* @strstr(i8* %116, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i8* %117, i8** %9
br label %54
118: ; preds = %54
%119 = load i8*, i8** %9
%120 = getelementptr inbounds i8, i8* %119, i64 2
store i8 0, i8* %120
%121 = load i8*, i8** %7
store i8* %121, i8** %2
br label %122
122: ; preds = %118, %96, %88, %62, %49, %39, %31, %22, %12
%123 = load i8*, i8** %2
ret i8* %123
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Incorrect socket passed\0A\00"
@.str.1 = [16 x i8] c"Out of memmory\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
define i8* @recv_data(i32 %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = icmp slt i32 %0, 1
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %47
8: ; preds = %1
%9 = tail call dereferenceable_or_null(65) i8* @malloc(i32 65)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %47
14: ; preds = %8
%15 = tail call i32 @recv_line(i32 %0, i8* %9, i32 64)
%16 = tail call i8* @strstr(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = getelementptr inbounds i8, i8* %16, i64 2
store i8 0, i8* %19
br label %47
20: ; preds = %14, %31
%21 = phi i64 [ %23, %31 ], [ 65, %14 ]
%22 = phi i8* [ %25, %31 ], [ %9, %14 ]
%23 = add nuw i64 %21, 10
%24 = trunc i64 %23 to i32
%25 = call i8* @malloc(i32 %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @free(i8* %22)
br label %47
31: ; preds = %20
%32 = call i32 @memset(i8* %25, i32 0, i32 %24)
%33 = trunc i64 %21 to i32
%34 = add i32 %33, -1
%35 = call i32 @memcpy(i8* %25, i8* %22, i32 %34)
%36 = call i32 @free(i8* %22)
%37 = call i32 @recv_line(i32 %0, i8* %3, i32 10)
%38 = icmp sgt i32 %37, 0
%39 = select i1 %38, i32 %37, i32 0
%40 = getelementptr inbounds i8, i8* %25, i64 -1
%41 = getelementptr inbounds i8, i8* %40, i64 %21
%42 = call i32 @memcpy(i8* %41, i8* %3, i32 %39)
%43 = call i8* @strstr(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%44 = icmp eq i8* %43, null
br i1 %44, label %20, label %45
45: ; preds = %31
%46 = getelementptr inbounds i8, i8* %43, i64 2
store i8 0, i8* %46
br label %47
47: ; preds = %45, %27, %18, %11, %5
%48 = phi i8* [ null, %5 ], [ null, %11 ], [ %9, %18 ], [ null, %27 ], [ %25, %45 ]
ret i8* %48
}