#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 recv_line(int sock, void *buff, int max) {
  int recv_count = 0, ret_stat;
  char *scan = buff;
  while (1) {
    if ((ret_stat = recv(sock, scan, 1, 0)) > 0) {
      recv_count++;
      if (recv_count == max)
        return recv_count;
      if (scan[0] == '\r') {
        scan++;
        if ((ret_stat = recv(sock, scan, 1, 0)) > 0) {
          recv_count++;
          if (recv_count == max)
            return recv_count;
          if (scan[0] == '\n')
            return recv_count;
        } else
          return ret_stat;
      }
      scan++;
    } else
      return ret_stat;
  }
}


x86 assembly (clang, -O0):
<recv_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    120c <recv_line+0xfc>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1170 <recv_line+0x60>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121c <recv_line+0x10c>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    11fb <recv_line+0xeb>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11eb <recv_line+0xdb>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11cb <recv_line+0xbb>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121c <recv_line+0x10c>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11e6 <recv_line+0xd6>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121c <recv_line+0x10c>
jmp    11f6 <recv_line+0xe6>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121c <recv_line+0x10c>
jmp    11fb <recv_line+0xeb>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1217 <recv_line+0x107>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121c <recv_line+0x10c>
jmp    1131 <recv_line+0x21>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %edi,%r15d
xor    %ebx,%ebx
jmp    113c <recv_line+0x2c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%ebx
add    $0x1,%rbp
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1184 <recv_line+0x74>
lea    0x1(%rbx),%eax
cmp    %r14d,%eax
je     1188 <recv_line+0x78>
cmpb   $0xd,0x0(%rbp)
jne    1130 <recv_line+0x20>
add    $0x1,%rbp
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1184 <recv_line+0x74>
add    $0x2,%ebx
cmp    %r14d,%ebx
je     1188 <recv_line+0x78>
cmpb   $0xa,0x0(%rbp)
jne    1132 <recv_line+0x22>
jmp    118b <recv_line+0x7b>
mov    %eax,%ebx
jmp    118b <recv_line+0x7b>
mov    %r14d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @recv_line(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
%11 = load i8*, i8** %6
store i8* %11, i8** %10
br label %12
12: ; preds = %3, %63
%13 = load i32, i32* %5
%14 = load i8*, i8** %10
%15 = call i32 @recv(i32 %13, i8* %14, i32 1, i32 0)
store i32 %15, i32* %9
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %61
17: ; preds = %12
%18 = load i32, i32* %8
%19 = add nsw i32 %18, 1
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = load i32, i32* %8
store i32 %24, i32* %4
br label %64
25: ; preds = %17
%26 = load i8*, i8** %10
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 13
br i1 %30, label %31, label %58
31: ; preds = %25
%32 = load i8*, i8** %10
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %10
%34 = load i32, i32* %5
%35 = load i8*, i8** %10
%36 = call i32 @recv(i32 %34, i8* %35, i32 1, i32 0)
store i32 %36, i32* %9
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %55
38: ; preds = %31
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = load i32, i32* %7
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = load i32, i32* %8
store i32 %45, i32* %4
br label %64
46: ; preds = %38
%47 = load i8*, i8** %10
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 10
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = load i32, i32* %8
store i32 %53, i32* %4
br label %64
54: ; preds = %46
br label %57
55: ; preds = %31
%56 = load i32, i32* %9
store i32 %56, i32* %4
br label %64
57: ; preds = %54
br label %58
58: ; preds = %57, %25
%59 = load i8*, i8** %10
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %10
br label %63
61: ; preds = %12
%62 = load i32, i32* %9
store i32 %62, i32* %4
br label %64
63: ; preds = %58
br label %12
64: ; preds = %61, %55, %52, %44, %23
%65 = load i32, i32* %4
ret i32 %65
}

LLVM IR (-O2):
define i32 @recv_line(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 @recv(i32 %0, i8* %1, i32 1, i32 0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %30
6: ; preds = %3, %24
%7 = phi i8* [ %27, %24 ], [ %1, %3 ]
%8 = phi i32 [ %25, %24 ], [ 0, %3 ]
%9 = add nsw i32 %8, 1
%10 = icmp eq i32 %9, %2
br i1 %10, label %30, label %11
11: ; preds = %6
%12 = load i8, i8* %7
%13 = icmp eq i8 %12, 13
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %7, i64 1
%16 = tail call i32 @recv(i32 %0, i8* %15, i32 1, i32 0)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %14
%19 = add nsw i32 %8, 2
%20 = icmp eq i32 %19, %2
br i1 %20, label %30, label %21
21: ; preds = %18
%22 = load i8, i8* %15
%23 = icmp eq i8 %22, 10
br i1 %23, label %30, label %24
24: ; preds = %21, %11
%25 = phi i32 [ %19, %21 ], [ %9, %11 ]
%26 = phi i8* [ %15, %21 ], [ %7, %11 ]
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = tail call i32 @recv(i32 %0, i8* %27, i32 1, i32 0)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %6, label %30
30: ; preds = %6, %18, %21, %14, %24, %3
%31 = phi i32 [ %4, %3 ], [ %28, %24 ], [ %16, %14 ], [ %19, %21 ], [ %2, %18 ], [ %2, %6 ]
ret i32 %31
}