#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, char *, int, int /*<<< orphan*/);
int strlen(char *);
int recv_line(int sockfd, char *dest_buffer) {
  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
movsbl (%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    11b2 <recv_line+0x92>
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    11b2 <recv_line+0x92>
movzbl -0x1(%rbx),%eax
mov    %ebp,%ecx
xor    %r13d,%r13d
cmp    (%rcx,%r15,1),%al
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 = sext 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 %23
5: ; preds = %2, %18
%6 = phi i32 [ %19, %18 ], [ 0, %2 ]
%7 = phi i8* [ %20, %18 ], [ %1, %2 ]
%8 = load i8, i8* %7
%9 = zext i32 %6 to i64
%10 = getelementptr inbounds [3 x i8], [3 x i8]* @.str, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %8, %11
br i1 %12, label %13, label %18
13: ; preds = %5
%14 = icmp eq i32 %6, 1
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = getelementptr inbounds i8, i8* %7, i64 -1
store i8 0, i8* %16
%17 = tail call i32 @strlen(i8* %1)
br label %23
18: ; preds = %5, %13
%19 = phi i32 [ 1, %13 ], [ 0, %5 ]
%20 = getelementptr inbounds i8, i8* %7, i64 1
%21 = tail call i32 @recv(i32 %0, i8* %20, i32 1, i32 0)
%22 = icmp eq i32 %21, 1
br i1 %22, label %5, label %23
23: ; preds = %18, %2, %15
%24 = phi i32 [ %17, %15 ], [ 0, %2 ], [ 0, %18 ]
ret i32 %24
}