#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 recv(int, unsigned char *, int, int /*<<< orphan*/);
int strlen(unsigned char *);
int recv_line(int sockfd, unsigned char *dest_buffer) {
  unsigned char *ptr;
  int eol_matched = 0;
  ptr = dest_buffer;
  while (recv(sockfd, ptr, 1, 0) == 1) {
    if (*ptr == "\0"[eol_matched]) {
      eol_matched++;
      if (eol_matched == 1) {
        *(ptr + 1 - 1) = '\0';
        return strlen(dest_buffer);
      }
    } else {
      eol_matched = 0;
    }
    ptr++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<recv_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x1,%eax
jne    11c0 <recv_line+0xa0>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
movslq -0x1c(%rbp),%rdx
lea    0xe94(%rip),%rcx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11a8 <recv_line+0x88>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    11a3 <recv_line+0x83>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    11c7 <recv_line+0xa7>
jmp    11af <recv_line+0x8f>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113e <recv_line+0x1e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_line>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x1,%eax
jne    1160 <recv_line+0x40>
lea    0x1(%r14),%rbx
xchg   %ax,%ax
cmpb   $0x0,-0x1(%rbx)
je     1167 <recv_line+0x47>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
add    $0x1,%rbx
cmp    $0x1,%eax
je     1140 <recv_line+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
movb   $0x0,-0x1(%rbx)
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <strlen@plt>

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

LLVM IR (-O2):
define i32 @recv_line(i32 %0, i8* %1) {
%3 = tail call i32 @recv(i32 %0, i8* %1, i32 1, i32 0)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %15
5: ; preds = %2, %11
%6 = phi i8* [ %12, %11 ], [ %1, %2 ]
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
store i8 0, i8* %6
%10 = tail call i32 @strlen(i8* %1)
br label %15
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %6, i64 1
%13 = tail call i32 @recv(i32 %0, i8* %12, i32 1, i32 0)
%14 = icmp eq i32 %13, 1
br i1 %14, label %5, label %15
15: ; preds = %11, %2, %9
%16 = phi i32 [ %10, %9 ], [ 0, %2 ], [ 0, %11 ]
ret i32 %16
}