#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__ recv(int, char *, int, int /*<<< orphan*/);
int strlen(char *);
int recv_new(int fd, char *buffer) {
  char *p = buffer;
  int eol_matched = 0;
  while (recv(fd, p, 1, 0) != 0) {
    if (*p == "\r\n"[eol_matched]) {
      ++eol_matched;
      if (eol_matched == 2) {
        *(p + 1 - 2) = '\0';
        return (strlen(buffer));
      }
    } else {
      eol_matched = 0;
    }
    p++;
  }
  return (0);
}


x86 assembly (clang, -O0):
<recv_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
je     11c2 <recv_new+0xa2>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
movslq -0x1c(%rbp),%rdx
lea    0xe93(%rip),%rcx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11aa <recv_new+0x8a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jne    11a5 <recv_new+0x85>
mov    -0x18(%rbp),%rax
movb   $0x0,-0x1(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    11c9 <recv_new+0xa9>
jmp    11b1 <recv_new+0x91>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113e <recv_new+0x1e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_new>:
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>
test   %rax,%rax
je     11b2 <recv_new+0x92>
lea    0x1(%r14),%rbx
lea    0xeb1(%rip),%r15
jmp    117e <recv_new+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
test   %rax,%rax
je     11b2 <recv_new+0x92>
movzbl -0x1(%rbx),%eax
mov    %ebp,%ecx
xor    %r13d,%r13d
cmp    (%rcx,%r15,1),%al
jne    1160 <recv_new+0x40>
mov    $0x1,%r13d
cmp    $0x1,%ebp
jne    1160 <recv_new+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_new(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
%8 = load i8*, i8** %5
store i8* %8, i8** %6
store i32 0, i32* %7
br label %9
9: ; preds = %37, %2
%10 = load i32, i32* %4
%11 = load i8*, i8** %6
%12 = call i64 @recv(i32 %10, i8* %11, i32 1, i32 0)
%13 = icmp ne i64 %12, 0
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_new(i32 %0, i8* %1) {
%3 = tail call i64 @recv(i32 %0, i8* %1, i32 1, i32 0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %23, label %5
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 i64 @recv(i32 %0, i8* %20, i32 1, i32 0)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %5
23: ; preds = %18, %2, %15
%24 = phi i32 [ %17, %15 ], [ 0, %2 ], [ 0, %18 ]
ret i32 %24
}