#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int c_byLine(FILE *f, char *buf, int n) {
  int read = 0, i = 0;
  for (; i < n; i++) {
    if (!fread(buf + i, 1, 1, f))
      break;
    read++;
    if (*(buf + i) == '\0')
      break;
    if (*(buf + i) == '\n') {
      *(buf + i) = '\0';
      break;
    }
  }
  return read;
}


x86 assembly (clang, -O0):
<c_byLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c2 <c_byLine+0xb2>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%eax
jne    1166 <c_byLine+0x56>
jmp    11c2 <c_byLine+0xb2>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1189 <c_byLine+0x79>
jmp    11c2 <c_byLine+0xb2>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11af <c_byLine+0x9f>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11c2 <c_byLine+0xb2>
jmp    11b4 <c_byLine+0xa4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <c_byLine+0x21>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_byLine>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edx,%edx
jle    1163 <c_byLine+0x53>
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%r15d
xor    %r13d,%r13d
nopl   0x0(%rax)
lea    (%r14,%r13,1),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     116c <c_byLine+0x5c>
movzbl (%rbx),%eax
test   %al,%al
je     1168 <c_byLine+0x58>
cmp    $0xa,%al
je     1171 <c_byLine+0x61>
add    $0x1,%r13
cmp    %r13,%r15
jne    1130 <c_byLine+0x20>
jmp    117a <c_byLine+0x6a>
xor    %r15d,%r15d
jmp    117a <c_byLine+0x6a>
add    $0x1,%r13d
mov    %r13d,%r15d
jmp    117a <c_byLine+0x6a>
lea    0x1(%r13),%r15d
movb   $0x0,(%r14,%r13,1)
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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