#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 read(int, char *, int);
void util_drain_fd(int fd, size_t lines) {
  char c;
  size_t i;
  for (i = 0; i < lines + (lines == 0); i++)
    while (read(fd, &c, 1) == 1 && (lines == 0 || c != '\n'))
      ;
}


x86 assembly (clang, -O0):
<util_drain_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmpq   $0x0,-0x10(%rbp)
sete   %dl
and    $0x1,%dl
movzbl %dl,%edx
movslq %edx,%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    11c0 <util_drain_fd+0xb0>
jmp    1151 <util_drain_fd+0x41>
mov    -0x4(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x21(%rbp)
jne    1195 <util_drain_fd+0x85>
mov    $0x1,%al
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x22(%rbp)
je     118f <util_drain_fd+0x7f>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11a5 <util_drain_fd+0x95>
jmp    11aa <util_drain_fd+0x9a>
jmp    1151 <util_drain_fd+0x41>
jmp    11af <util_drain_fd+0x9f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1127 <util_drain_fd+0x17>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_drain_fd>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %r15d,%r15d
test   %rsi,%rsi
sete   %r15b
add    %rsi,%r15
je     1172 <util_drain_fd+0x62>
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r12d,%r12d
lea    0xf(%rsp),%r14
jmp    1150 <util_drain_fd+0x40>
add    $0x1,%r12
cmp    %r15,%r12
je     1172 <util_drain_fd+0x62>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
jne    113a <util_drain_fd+0x2a>
test   %rbx,%rbx
je     1150 <util_drain_fd+0x40>
cmpb   $0xa,0xf(%rsp)
jne    1150 <util_drain_fd+0x40>
jmp    113a <util_drain_fd+0x2a>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @util_drain_fd(i32 %0, i64 %1) {
%3 = alloca i8
%4 = icmp eq i64 %1, 0
%5 = zext i1 %4 to i64
%6 = add i64 %5, %1
%7 = icmp eq i64 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %2, %17
%9 = phi i64 [ %18, %17 ], [ 0, %2 ]
br label %10
10: ; preds = %8, %13
%11 = call i32 @read(i32 %0, i8* %3, i32 1)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i8, i8* %3
%15 = icmp ne i8 %14, 10
%16 = select i1 %4, i1 true, i1 %15
br i1 %16, label %10, label %17
17: ; preds = %13, %10
%18 = add nuw i64 %9, 1
%19 = icmp eq i64 %18, %6
br i1 %19, label %20, label %8
20: ; preds = %17, %2
ret void
}