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

/* Variables and functions */
int /*<<< orphan*/ eprintf(char *, char const *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
void head(FILE *fp, const char *fname, size_t n) {
  char *buf = NULL;
  size_t i = 0, size = 0;
  ssize_t len;
  while (i < n && (len = getline(&buf, &size, fp)) > 0) {
    fwrite(buf, 1, len, stdout);
    i += (len && (buf[len - 1] == '\n'));
  }
  free(buf);
  if (ferror(fp))
    eprintf("getline %s:", fname);
}


x86 assembly (clang, -O0):
<head>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x35(%rbp)
jae    11ac <head+0x5c>
mov    -0x8(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <getline@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
setg   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    11bc <head+0x6c>
jmp    1216 <head+0xc6>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    0x2e16(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1070 <fwrite@plt>
xor    %eax,%eax
cmpl   $0x0,-0x34(%rbp)
mov    %al,-0x36(%rbp)
je     11ff <head+0xaf>
mov    -0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x36(%rbp)
mov    -0x36(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
cltq
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    117c <head+0x2c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1242 <head+0xf2>
mov    -0x10(%rbp),%rsi
lea    0xdc3(%rip),%rdi
call   1050 <eprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<head>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
movq   $0x0,(%rsp)
movq   $0x0,0x10(%rsp)
test   %rdx,%rdx
mov    %rsi,0x8(%rsp)
je     11d7 <head+0x87>
mov    %rdx,%rbx
xor    %r14d,%r14d
mov    %rsp,%r12
lea    0x10(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1060 <getline@plt>
mov    (%rsp),%rdi
test   %eax,%eax
jle    11d9 <head+0x89>
mov    %eax,%ebp
mov    0x2e31(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    %ebp,%edx
call   1070 <fwrite@plt>
mov    (%rsp),%rdi
add    $0xffffffff,%ebp
xor    %eax,%eax
cmpb   $0xa,(%rdi,%rbp,1)
sete   %al
add    %rax,%r14
cmp    %rbx,%r14
jb     1190 <head+0x40>
jmp    11d9 <head+0x89>
xor    %edi,%edi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     11fc <head+0xac>
lea    0xe0e(%rip),%rdi
mov    0x8(%rsp),%rsi
call   1050 <eprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [12 x i8] c"getline %s:\00"
define void @head(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i8* null, i8** %7
store i64 0, i64* %8
store i64 0, i64* %9
br label %11
11: ; preds = %37, %3
%12 = load i64, i64* %8
%13 = load i64, i64* %6
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32*, i32** %4
%17 = call i32 @getline(i8** %7, i64* %9, i32* %16)
store i32 %17, i32* %10
%18 = icmp sgt i32 %17, 0
br label %19
19: ; preds = %15, %11
%20 = phi i1 [ false, %11 ], [ %18, %15 ]
br i1 %20, label %21, label %43
21: ; preds = %19
%22 = load i8*, i8** %7
%23 = load i32, i32* %10
%24 = load i32, i32* @stdout
%25 = call i32 @fwrite(i8* %22, i32 1, i32 %23, i32 %24)
%26 = load i32, i32* %10
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %21
%29 = load i8*, i8** %7
%30 = load i32, i32* %10
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br label %37
37: ; preds = %28, %21
%38 = phi i1 [ false, %21 ], [ %36, %28 ]
%39 = zext i1 %38 to i32
%40 = sext i32 %39 to i64
%41 = load i64, i64* %8
%42 = add i64 %41, %40
store i64 %42, i64* %8
br label %11
43: ; preds = %19
%44 = load i8*, i8** %7
%45 = call i32 @free(i8* %44)
%46 = load i32*, i32** %4
%47 = call i64 @ferror(i32* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = load i8*, i8** %5
%51 = call i32 @eprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %49, %43
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [12 x i8] c"getline %s:\00"
define void @head(i32* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%8 = icmp eq i64 %2, 0
br i1 %8, label %26, label %9
9: ; preds = %3, %14
%10 = phi i64 [ %24, %14 ], [ 0, %3 ]
%11 = call i32 @getline(i8** %4, i64* %5, i32* %0)
%12 = icmp sgt i32 %11, 0
%13 = load i8*, i8** %4
br i1 %12, label %14, label %26
14: ; preds = %9
%15 = load i32, i32* @stdout
%16 = call i32 @fwrite(i8* %13, i32 1, i32 %11, i32 %15)
%17 = load i8*, i8** %4
%18 = add nsw i32 %11, -1
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
%23 = zext i1 %22 to i64
%24 = add nuw i64 %10, %23
%25 = icmp ult i64 %24, %2
br i1 %25, label %9, label %26
26: ; preds = %14, %9, %3
%27 = phi i8* [ null, %3 ], [ %13, %9 ], [ %17, %14 ]
%28 = call i32 @free(i8* %27)
%29 = call i64 @ferror(i32* %0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %26
%32 = call i32 @eprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %33
33: ; preds = %31, %26
ret void
}