#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 scalar_t__ int32_t;

/* Variables and functions */
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int http_recv_line(int fd, char *buff, int bufLen) {
  int32_t i = 0;
  int32_t iret = 0;
  char c = 0;
  while ('\n' != c) {
    iret = recv(fd, &c, 1, 0);
    if (iret < 0) {
      return iret;
    }
    buff[i++] = c;
    if (i == bufLen)
      break;
  }
  return i - 1;
}


x86 assembly (clang, -O0):
<http_recv_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movb   $0x0,-0x29(%rbp)
movsbl -0x29(%rbp),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
je     11a9 <http_recv_line+0x99>
mov    -0x8(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    1175 <http_recv_line+0x65>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11b4 <http_recv_line+0xa4>
mov    -0x29(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jne    11a4 <http_recv_line+0x94>
jmp    11a9 <http_recv_line+0x99>
jmp    1136 <http_recv_line+0x26>
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_recv_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%r12d
movb   $0x0,0xf(%rsp)
movslq %edx,%rax
mov    $0x1,%ebp
sub    %rax,%rbp
mov    $0xffffffffffffffff,%rbx
lea    0xf(%rsp),%r15
xchg   %ax,%ax
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
js     1175 <http_recv_line+0x65>
movzbl 0xf(%rsp),%eax
lea    (%rbx,%rbp,1),%rcx
mov    %al,0x1(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0xffffffffffffffff,%rcx
je     1178 <http_recv_line+0x68>
cmp    $0xa,%al
jne    1140 <http_recv_line+0x30>
jmp    1178 <http_recv_line+0x68>
mov    %rax,%rbx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @http_recv_line(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i64 0, i64* %8
store i64 0, i64* %9
store i8 0, i8* %10
br label %11
11: ; preds = %34, %3
%12 = load i8, i8* %10
%13 = sext i8 %12 to i32
%14 = icmp ne i32 10, %13
br i1 %14, label %15, label %35
15: ; preds = %11
%16 = load i32, i32* %5
%17 = call i64 @recv(i32 %16, i8* %10, i32 1, i32 0)
store i64 %17, i64* %9
%18 = load i64, i64* %9
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i64, i64* %9
%22 = trunc i64 %21 to i32
store i32 %22, i32* %4
br label %39
23: ; preds = %15
%24 = load i8, i8* %10
%25 = load i8*, i8** %6
%26 = load i64, i64* %8
%27 = add nsw i64 %26, 1
store i64 %27, i64* %8
%28 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 %24, i8* %28
%29 = load i64, i64* %8
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = icmp eq i64 %29, %31
br i1 %32, label %33, label %34
33: ; preds = %23
br label %35
34: ; preds = %23
br label %11
35: ; preds = %33, %11
%36 = load i64, i64* %8
%37 = sub nsw i64 %36, 1
%38 = trunc i64 %37 to i32
store i32 %38, i32* %4
br label %39
39: ; preds = %35, %20
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
define i32 @http_recv_line(i32 %0, i8* nocapture writeonly %1, i32 %2) {
%4 = alloca i8
store i8 0, i8* %4
%5 = sext i32 %2 to i64
br label %6
6: ; preds = %3, %10
%7 = phi i64 [ 0, %3 ], [ %12, %10 ]
%8 = call i64 @recv(i32 %0, i8* %4, i32 1, i32 0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %6
%11 = load i8, i8* %4
%12 = add nuw nsw i64 %7, 1
%13 = getelementptr inbounds i8, i8* %1, i64 %7
store i8 %11, i8* %13
%14 = icmp ne i64 %12, %5
%15 = icmp ne i8 %11, 10
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %6, label %17
17: ; preds = %10, %6
%18 = phi i64 [ %8, %6 ], [ %7, %10 ]
%19 = trunc i64 %18 to i32
ret i32 %19
}