#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 */
typedef int /*<<< orphan*/ sym;
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ assert(char const *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
ssize_t recvline(int fd, char *buf, size_t size, const char *d, size_t dlen) {
  assert(buf);
  assert(d);
  size_t eolindex = 0;
  size_t received = 0;
  while (received < size && eolindex < dlen) {
    char sym;
    ssize_t rc = recv(fd, &sym, sizeof(sym), 0);
    if (0 >= rc) {
      return (rc);
    }
    if (d[eolindex] == sym) {
      ++eolindex;
    } else {
      eolindex = 0;
    }
    buf[received++] = sym;
  }
  return (received);
}


x86 assembly (clang, -O0):
<recvline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x28(%rbp),%rdi
call   1040 <assert@plt>
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x51(%rbp)
jae    117e <recvline+0x5e>
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
setb   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    118e <recvline+0x6e>
jmp    120d <recvline+0xed>
mov    -0xc(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x50(%rbp)
xor    %eax,%eax
cmp    -0x50(%rbp),%rax
jl     11be <recvline+0x9e>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1215 <recvline+0xf5>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x41(%rbp),%ecx
cmp    %ecx,%eax
jne    11e7 <recvline+0xc7>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11ef <recvline+0xcf>
movq   $0x0,-0x38(%rbp)
mov    -0x41(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x40(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    115d <recvline+0x3d>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recvline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %edi,0x4(%rsp)
mov    %rsi,%rdi
call   1040 <assert@plt>
mov    %r15,%rdi
call   1040 <assert@plt>
xor    %ebp,%ebp
test   %r12,%r12
je     11aa <recvline+0x8a>
test   %r14,%r14
je     11aa <recvline+0x8a>
mov    %r14,%r13
xor    %ebp,%ebp
xor    %r14d,%r14d
nop
mov    0x4(%rsp),%edi
lea    0x3(%rsp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jle    11a7 <recvline+0x87>
movzbl 0x3(%rsp),%eax
cmp    %al,(%r15,%r14,1)
je     1190 <recvline+0x70>
xor    %r14d,%r14d
jmp    1194 <recvline+0x74>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    %r12,%rbp
jae    11aa <recvline+0x8a>
cmp    %r13,%r14
jb     1160 <recvline+0x40>
jmp    11aa <recvline+0x8a>
mov    %rax,%rbp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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