#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 client_read(int, char *, int *);
int /*<<< orphan*/ *strstr(char *, char *);
int client_read_line(int fd, char *buf, int *buffer_pos) {
  while ((strstr(buf, "\r\n") == NULL) && (strstr(buf, "\n") == NULL)) {
    int res = client_read(fd, buf, buffer_pos);
    if (res == -1)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<client_read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec2(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1d(%rbp)
jne    116f <client_read_line+0x4f>
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    117f <client_read_line+0x5f>
jmp    11ad <client_read_line+0x8d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <client_read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11a8 <client_read_line+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <client_read_line+0x94>
jmp    1133 <client_read_line+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_read_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r12d
lea    0xeb8(%rip),%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
jne    118a <client_read_line+0x5a>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    118a <client_read_line+0x5a>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <client_read@plt>
cmp    $0xffffffff,%eax
jne    1150 <client_read_line+0x20>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @client_read_line(i32 %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32* %2, i32** %7
br label %9
9: ; preds = %27, %3
%10 = load i8*, i8** %6
%11 = call i32* @strstr(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i8*, i8** %6
%15 = call i32* @strstr(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br label %17
17: ; preds = %13, %9
%18 = phi i1 [ false, %9 ], [ %16, %13 ]
br i1 %18, label %19, label %28
19: ; preds = %17
%20 = load i32, i32* %5
%21 = load i8*, i8** %6
%22 = load i32*, i32** %7
%23 = call i32 @client_read(i32 %20, i8* %21, i32* %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 -1, i32* %4
br label %29
27: ; preds = %19
br label %9
28: ; preds = %17
store i32 0, i32* %4
br label %29
29: ; preds = %28, %26
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
define i32 @client_read_line(i32 %0, i8* %1, i32* %2) {
br label %4
4: ; preds = %10, %3
%5 = tail call i32* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = tail call i8* @strchr(i8* dereferenceable(1) %1, i32 10)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @client_read(i32 %0, i8* %1, i32* %2)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %4
13: ; preds = %10, %7, %4
%14 = phi i32 [ -1, %10 ], [ 0, %4 ], [ 0, %7 ]
ret i32 %14
}