#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 */
scalar_t__ malloc(int);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
*my_sock_recv_line(int sock) {
  int pos = 0;
  char c;
  int buf_len;
  char *buf_str;
  buf_str = (char *)malloc(10 * sizeof(char));
  buf_len = 10;
  c = '\0';
  while ((c != '\n') && (c != '>')) {
    recv(sock, &c, sizeof(char), 0);
    buf_str[pos] = c;
    pos++;
    if (pos == buf_len) {
      buf_len += 10;
      buf_str = (char *)realloc(buf_str, buf_len * sizeof(char));
    }
  }
  buf_str[pos] = '\0';
  return (char *)buf_str;
}


x86 assembly (clang, -O0):
<my_sock_recv_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0xa,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0xa,-0x10(%rbp)
movb   $0x0,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     117a <my_sock_recv_line+0x4a>
movsbl -0x9(%rbp),%eax
cmp    $0x3e,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    118a <my_sock_recv_line+0x5a>
jmp    11e5 <my_sock_recv_line+0xb5>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x9(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11e0 <my_sock_recv_line+0xb0>
mov    -0x10(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x18(%rbp)
jmp    115b <my_sock_recv_line+0x2b>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_sock_recv_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
mov    $0xa,%ebp
mov    $0xa,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
movb   $0x0,0xf(%rsp)
xor    %ebx,%ebx
lea    0xf(%rsp),%r15
xor    %eax,%eax
jmp    1175 <my_sock_recv_line+0x45>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0xf(%rsp),%eax
cmp    $0xa,%al
je     11b5 <my_sock_recv_line+0x85>
cmp    $0x3e,%al
je     11b5 <my_sock_recv_line+0x85>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movzbl 0xf(%rsp),%eax
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
mov    %ebp,%eax
cmp    %rax,%rbx
jne    1170 <my_sock_recv_line+0x40>
add    $0xa,%ebp
mov    %r12,%rdi
mov    %ebp,%esi
call   1050 <realloc@plt>
mov    %rax,%r12
jmp    1170 <my_sock_recv_line+0x40>
mov    %ebx,%eax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @my_sock_recv_line(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %2
store i32 0, i32* %3
%7 = call i64 @malloc(i32 10)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %6
store i32 10, i32* %5
store i8 0, i8* %4
br label %9
9: ; preds = %42, %1
%10 = load i8, i8* %4
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 10
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i8, i8* %4
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 62
br label %17
17: ; preds = %13, %9
%18 = phi i1 [ false, %9 ], [ %16, %13 ]
br i1 %18, label %19, label %43
19: ; preds = %17
%20 = load i32, i32* %2
%21 = call i32 @recv(i32 %20, i8* %4, i32 1, i32 0)
%22 = load i8, i8* %4
%23 = load i8*, i8** %6
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 %22, i8* %26
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = load i32, i32* %5
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %19
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 10
store i32 %34, i32* %5
%35 = load i8*, i8** %6
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = mul i64 %37, 1
%39 = trunc i64 %38 to i32
%40 = call i64 @realloc(i8* %35, i32 %39)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %6
br label %42
42: ; preds = %32, %19
br label %9
43: ; preds = %17
%44 = load i8*, i8** %6
%45 = load i32, i32* %3
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %6
%49 = bitcast i8* %48 to i32*
ret i32* %49
}

LLVM IR (-O2):
define i32* @my_sock_recv_line(i32 %0) {
%2 = alloca i8
%3 = tail call i64 @malloc(i32 10)
%4 = inttoptr i64 %3 to i8*
store i8 0, i8* %2
br label %5
5: ; preds = %21, %1
%6 = phi i64 [ %14, %21 ], [ 0, %1 ]
%7 = phi i8 [ %24, %21 ], [ 0, %1 ]
%8 = phi i32 [ %22, %21 ], [ 10, %1 ]
%9 = phi i8* [ %23, %21 ], [ %4, %1 ]
switch i8 %7, label %10 [
i8 62, label %25
i8 10, label %25
]
10: ; preds = %5
%11 = call i32 @recv(i32 %0, i8* %2, i32 1, i32 0)
%12 = load i8, i8* %2
%13 = getelementptr inbounds i8, i8* %9, i64 %6
store i8 %12, i8* %13
%14 = add nuw i64 %6, 1
%15 = zext i32 %8 to i64
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = add nsw i32 %8, 10
%19 = call i64 @realloc(i8* %9, i32 %18)
%20 = inttoptr i64 %19 to i8*
br label %21
21: ; preds = %17, %10
%22 = phi i32 [ %18, %17 ], [ %8, %10 ]
%23 = phi i8* [ %20, %17 ], [ %9, %10 ]
%24 = load i8, i8* %2
br label %5
25: ; preds = %5, %5
%26 = and i64 %6, 4294967295
%27 = getelementptr inbounds i8, i8* %9, i64 %26
store i8 0, i8* %27
%28 = bitcast i8* %9 to i32*
ret i32* %28
}