#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 == "\r\n"[eol_matched]) {
      eol_matched++;
      if (eol_matched == 2) {
        *(ptr + 1 - 2) = '\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    11c1 <recv_line+0xa1>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
movslq -0x1c(%rbp),%rdx
lea    0xe94(%rip),%rcx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11a9 <recv_line+0x89>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jne    11a4 <recv_line+0x84>
mov    -0x18(%rbp),%rax
movb   $0x0,-0x1(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    11c8 <recv_line+0xa8>
jmp    11b0 <recv_line+0x90>
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   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r12d
xor    %ebp,%ebp
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x1,%eax
jne    11b5 <recv_line+0x95>
lea    0x1(%r14),%rbx
lea    0xeb1(%rip),%r15
jmp    117e <recv_line+0x5e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
add    $0x1,%rbx
mov    %r13d,%ebp
cmp    $0x1,%eax
jne    11b5 <recv_line+0x95>
movzbl -0x1(%rbx),%eax
mov    %ebp,%ecx
movsbl (%rcx,%r15,1),%ecx
xor    %r13d,%r13d
cmp    %ecx,%eax
jne    1160 <recv_line+0x40>
mov    $0x1,%r13d
cmp    $0x1,%ebp
jne    1160 <recv_line+0x40>
movb   $0x0,-0x2(%rbx)
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <strlen@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
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 [3 x i8], [3 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, 2
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 -2
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):
@.str = [3 x i8] c"\0D\0A\00"
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 %25
5: ; preds = %2, %20
%6 = phi i32 [ %21, %20 ], [ 0, %2 ]
%7 = phi i8* [ %22, %20 ], [ %1, %2 ]
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = zext i32 %6 to i64
%11 = getelementptr inbounds [3 x i8], [3 x i8]* @.str, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %9, %13
br i1 %14, label %15, label %20
15: ; preds = %5
%16 = icmp eq i32 %6, 1
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = getelementptr inbounds i8, i8* %7, i64 -1
store i8 0, i8* %18
%19 = tail call i32 @strlen(i8* %1)
br label %25
20: ; preds = %5, %15
%21 = phi i32 [ 1, %15 ], [ 0, %5 ]
%22 = getelementptr inbounds i8, i8* %7, i64 1
%23 = tail call i32 @recv(i32 %0, i8* %22, i32 1, i32 0)
%24 = icmp eq i32 %23, 1
br i1 %24, label %5, label %25
25: ; preds = %20, %2, %17
%26 = phi i32 [ %19, %17 ], [ 0, %2 ], [ 0, %20 ]
ret i32 %26
}