#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 /*<<< orphan*/ mock_get_c_wait(char *, size_t);
int mock_get_line_wait(char *s, int len, size_t delay) {
  int count = 0;
  while (count < len - 1) {
    char c;
    if (!mock_get_c_wait(&c, delay))
      break;
    if (c == 0)
      break;
    *s++ = c;
    count++;
    if (c == '\n')
      break;
  }
  *s = '\0';
  return count;
}


x86 assembly (clang, -O0):
<mock_get_line_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    119c <mock_get_line_wait+0x8c>
mov    -0x18(%rbp),%rsi
lea    -0x1d(%rbp),%rdi
call   1030 <mock_get_c_wait@plt>
cmp    $0x0,%eax
jne    1156 <mock_get_line_wait+0x46>
jmp    119c <mock_get_line_wait+0x8c>
movsbl -0x1d(%rbp),%eax
cmp    $0x0,%eax
jne    1168 <mock_get_line_wait+0x58>
jmp    119c <mock_get_line_wait+0x8c>
mov    -0x1d(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0xa,%eax
jne    1197 <mock_get_line_wait+0x87>
jmp    119c <mock_get_line_wait+0x8c>
jmp    112a <mock_get_line_wait+0x1a>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mock_get_line_wait>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %r14d,%r14d
cmp    $0x2,%esi
jl     1172 <mock_get_line_wait+0x62>
mov    %rdx,%r15
mov    %esi,%r13d
lea    -0x1(%r13),%r14d
mov    $0x1,%ebp
lea    0x7(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <mock_get_c_wait@plt>
test   %eax,%eax
je     116c <mock_get_line_wait+0x5c>
movzbl 0x7(%rsp),%eax
test   %al,%al
je     116c <mock_get_line_wait+0x5c>
mov    %al,(%rbx)
add    $0x1,%rbx
cmp    $0xa,%al
je     116f <mock_get_line_wait+0x5f>
add    $0x1,%ebp
cmp    %ebp,%r13d
jne    1140 <mock_get_line_wait+0x30>
jmp    1172 <mock_get_line_wait+0x62>
add    $0xffffffff,%ebp
mov    %ebp,%r14d
movb   $0x0,(%rbx)
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mock_get_line_wait(i8* %0, i32 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64 %2, i64* %6
store i32 0, i32* %7
br label %9
9: ; preds = %34, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %35
14: ; preds = %9
%15 = load i64, i64* %6
%16 = call i32 @mock_get_c_wait(i8* %8, i64 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %14
br label %35
19: ; preds = %14
%20 = load i8, i8* %8
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
br label %35
24: ; preds = %19
%25 = load i8, i8* %8
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
store i8 %25, i8* %26
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
%30 = load i8, i8* %8
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 10
br i1 %32, label %33, label %34
33: ; preds = %24
br label %35
34: ; preds = %24
br label %9
35: ; preds = %33, %23, %18, %9
%36 = load i8*, i8** %4
store i8 0, i8* %36
%37 = load i32, i32* %7
ret i32 %37
}

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