#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 get_line(int sockfd, char *dest_buffer) {
  char *current;
  current = dest_buffer;
  int result;
  while ((result = recv(sockfd, current, 1, 0)) == 1) {
    if ((*current) == '\n') {
      *current = '\0';
      return strlen(dest_buffer);
    } else if ((*current) == '\0') {
      return strlen(dest_buffer);
    }
    current++;
  }
  return result;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%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>
mov    %eax,-0x1c(%rbp)
cmp    $0x1,%eax
jne    11b5 <get_line+0x95>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    117e <get_line+0x5e>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    11bb <get_line+0x9b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    119f <get_line+0x7f>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    11bb <get_line+0x9b>
jmp    11a4 <get_line+0x84>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1137 <get_line+0x17>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_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    1166 <get_line+0x46>
lea    0x1(%r14),%rbx
xchg   %ax,%ax
movzbl -0x1(%rbx),%eax
test   %al,%al
je     116f <get_line+0x4f>
cmp    $0xa,%al
je     116b <get_line+0x4b>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
add    $0x1,%rbx
cmp    $0x1,%eax
je     1140 <get_line+0x20>
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):
define i32 @get_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
%8 = load i8*, i8** %5
store i8* %8, i8** %6
br label %9
9: ; preds = %32, %2
%10 = load i32, i32* %4
%11 = load i8*, i8** %6
%12 = call i32 @recv(i32 %10, i8* %11, i32 1, i32 0)
store i32 %12, i32* %7
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %35
14: ; preds = %9
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i8*, i8** %6
store i8 0, i8* %20
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %3
br label %37
23: ; preds = %14
%24 = load i8*, i8** %6
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i8*, i8** %5
%30 = call i32 @strlen(i8* %29)
store i32 %30, i32* %3
br label %37
31: ; preds = %23
br label %32
32: ; preds = %31
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %6
br label %9
35: ; preds = %9
%36 = load i32, i32* %7
store i32 %36, i32* %3
br label %37
37: ; preds = %35, %28, %19
%38 = load i32, i32* %3
ret i32 %38
}

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