#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*/ SEEK_CUR;
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char);
int nextLine(char c, FILE *fd, unsigned int file_size, int in_function) {
  if (in_function)
    printf("%c", c);
  while (c != '\n' && (unsigned)ftell(fd) < file_size) {
    fread(&c, 1, sizeof(char), fd);
    if (in_function)
      printf("%c", c);
  }
  fseek(fd, -1, SEEK_CUR);
  return ftell(fd);
}


x86 assembly (clang, -O0):
<nextLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1172 <nextLine+0x32>
lea    0xe97(%rip),%rdi
movsbl -0x1(%rbp),%esi
call   1040 <printf@plt>
jmp    1177 <nextLine+0x37>
movsbl -0x1(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     119b <nextLine+0x5b>
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
cmp    -0x14(%rbp),%eax
setb   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11ab <nextLine+0x6b>
jmp    11de <nextLine+0x9e>
mov    -0x10(%rbp),%rcx
lea    -0x1(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmpl   $0x0,-0x18(%rbp)
je     11d9 <nextLine+0x99>
lea    0xe30(%rip),%rdi
movsbl -0x1(%rbp),%esi
call   1040 <printf@plt>
jmp    1177 <nextLine+0x37>
mov    -0x10(%rbp),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nextLine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %edi,%r15d
mov    %r15b,0x7(%rsp)
test   %ecx,%ecx
je     1170 <nextLine+0x30>
movsbl %r15b,%esi
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
cmp    $0xa,%r15b
jne    11a2 <nextLine+0x62>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0xffffffff,%esi
call   1060 <fseek@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <ftell@plt>
lea    0x7(%rsp),%r15
lea    0xe52(%rip),%r12
jmp    11b5 <nextLine+0x75>
cmp    $0xa,%bl
je     1176 <nextLine+0x36>
mov    %rbp,%rdi
call   1050 <ftell@plt>
cmp    %r14d,%eax
jae    1176 <nextLine+0x36>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
movzbl 0x7(%rsp),%ebx
test   %r13d,%r13d
je     11b0 <nextLine+0x70>
movsbl %bl,%esi
mov    %r12,%rdi
call   1040 <printf@plt>
jmp    11b0 <nextLine+0x70>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@SEEK_CUR = global i32 0
define i32 @nextLine(i8 signext %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i8
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i8 %0, i8* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %8
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = load i8, i8* %5
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %12)
br label %14
14: ; preds = %11, %4
br label %15
15: ; preds = %34, %14
%16 = load i8, i8* %5
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 10
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i32*, i32** %6
%21 = call i32 @ftell(i32* %20)
%22 = load i32, i32* %7
%23 = icmp ult i32 %21, %22
br label %24
24: ; preds = %19, %15
%25 = phi i1 [ false, %15 ], [ %23, %19 ]
br i1 %25, label %26, label %35
26: ; preds = %24
%27 = load i32*, i32** %6
%28 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %27)
%29 = load i32, i32* %8
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i8, i8* %5
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %32)
br label %34
34: ; preds = %31, %26
br label %15
35: ; preds = %24
%36 = load i32*, i32** %6
%37 = load i32, i32* @SEEK_CUR
%38 = call i32 @fseek(i32* %36, i32 -1, i32 %37)
%39 = load i32*, i32** %6
%40 = call i32 @ftell(i32* %39)
ret i32 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@SEEK_CUR = global i32 0
define i32 @nextLine(i8 signext %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = alloca i8
store i8 %0, i8* %5
%6 = icmp eq i32 %3, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %0)
br label %9
9: ; preds = %7, %4
%10 = icmp eq i8 %0, 10
br i1 %10, label %21, label %11
11: ; preds = %9, %19
%12 = tail call i32 @ftell(i32* %1)
%13 = icmp ult i32 %12, %2
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %1)
%16 = load i8, i8* %5
br i1 %6, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %16)
br label %19
19: ; preds = %14, %17
%20 = icmp eq i8 %16, 10
br i1 %20, label %21, label %11
21: ; preds = %11, %19, %9
%22 = load i32, i32* @SEEK_CUR
%23 = tail call i32 @fseek(i32* %1, i32 -1, i32 %22)
%24 = tail call i32 @ftell(i32* %1)
ret i32 %24
}