#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 EOF;
int /*<<< orphan*/ exit(int);
int getc(int /*<<< orphan*/ *);
scalar_t__ putchar(int);
void do_head(FILE *f, long nlines) {
  int c;
  if (nlines == 0)
    return;
  while ((c = getc(f)) != EOF) {
    if (putchar(c) < 0)
      exit(1);
    if (c == '\n') {
      nlines--;
      if (nlines == 0)
        return;
    }
  }
}


x86 assembly (clang, -O0):
<do_head>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1150 <do_head+0x20>
jmp    11bc <do_head+0x8c>
jmp    1155 <do_head+0x25>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%eax
je     11bc <do_head+0x8c>
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
cmp    $0x0,%rax
jge    118c <do_head+0x5c>
mov    $0x1,%edi
call   1040 <exit@plt>
cmpl   $0xa,-0x14(%rbp)
jne    11b7 <do_head+0x87>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b2 <do_head+0x82>
jmp    11bc <do_head+0x8c>
jmp    11b7 <do_head+0x87>
jmp    1155 <do_head+0x25>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_head>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1186 <do_head+0x56>
mov    %rsi,%rbx
mov    %rdi,%r14
call   1050 <getc@plt>
mov    0x2e9a(%rip),%r15
cmp    (%r15),%eax
je     1186 <do_head+0x56>
mov    %eax,%ebp
jmp    116f <do_head+0x3f>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <getc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
je     1186 <do_head+0x56>
mov    %ebp,%edi
call   1030 <putchar@plt>
test   %rax,%rax
js     1191 <do_head+0x61>
cmp    $0xa,%ebp
jne    1160 <do_head+0x30>
add    $0xffffffffffffffff,%rbx
jne    1160 <do_head+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
define void @do_head(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
br label %32
9: ; preds = %2
br label %10
10: ; preds = %31, %9
%11 = load i32*, i32** %3
%12 = call i32 @getc(i32* %11)
store i32 %12, i32* %5
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %32
15: ; preds = %10
%16 = load i32, i32* %5
%17 = call i64 @putchar(i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i64, i64* %4
%26 = add nsw i64 %25, -1
store i64 %26, i64* %4
%27 = load i64, i64* %4
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
br label %32
30: ; preds = %24
br label %31
31: ; preds = %30, %21
br label %10
32: ; preds = %8, %29, %10
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @do_head(i32* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %25, label %4
4: ; preds = %2
%5 = tail call i32 @getc(i32* %0)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %25, label %8
8: ; preds = %4, %20
%9 = phi i32 [ %22, %20 ], [ %5, %4 ]
%10 = phi i64 [ %21, %20 ], [ %1, %4 ]
%11 = tail call i64 @putchar(i32 %9)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = icmp eq i32 %9, 10
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = add nsw i64 %10, -1
%19 = icmp eq i64 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %17, %15
%21 = phi i64 [ %18, %17 ], [ %10, %15 ]
%22 = tail call i32 @getc(i32* %0)
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %8
25: ; preds = %17, %20, %4, %2
ret void
}