#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*/ err(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int getc(int /*<<< orphan*/ *);
int putchar(int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void head(FILE *fp, int cnt) {
  int ch;
  while (cnt--)
    while ((ch = getc(fp)) != EOF) {
      if (putchar(ch) == EOF)
        err(1, "stdout: %s", strerror(errno));
      if (ch == '\n')
        break;
    }
}


x86 assembly (clang, -O0):
<head>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11d4 <head+0x94>
jmp    1168 <head+0x28>
mov    -0x8(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%eax
je     11cf <head+0x8f>
mov    -0x10(%rbp),%edi
call   1030 <putchar@plt>
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%eax
jne    11bb <head+0x7b>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe4a(%rip),%rsi
call   1040 <err@plt>
cmpl   $0xa,-0x10(%rbp)
jne    11ca <head+0x8a>
jmp    11cf <head+0x8f>
jmp    1168 <head+0x28>
jmp    114f <head+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<head>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     11b8 <head+0x78>
mov    %esi,%r14d
mov    %rdi,%r12
mov    0x2e8c(%rip),%rbx
mov    0x2e75(%rip),%r13
lea    0xe96(%rip),%r15
jmp    1175 <head+0x35>
nopl   0x0(%rax)
test   %r14d,%r14d
je     11b8 <head+0x78>
add    $0xffffffff,%r14d
jmp    1185 <head+0x45>
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%ebp
je     1170 <head+0x30>
mov    %r12,%rdi
call   1060 <getc@plt>
cmp    (%rbx),%eax
je     1170 <head+0x30>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <putchar@plt>
cmp    (%rbx),%eax
jne    1180 <head+0x40>
mov    0x0(%r13),%edi
call   1050 <strerror@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <err@plt>
jmp    1180 <head+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [11 x i8] c"stdout: %s\00"
@errno = global i32 0
define void @head(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
br label %6
6: ; preds = %30, %2
%7 = load i32, i32* %4
%8 = add nsw i32 %7, -1
store i32 %8, i32* %4
%9 = icmp ne i32 %7, 0
br i1 %9, label %10, label %31
10: ; preds = %6
br label %11
11: ; preds = %29, %10
%12 = load i32*, i32** %3
%13 = call i32 @getc(i32* %12)
store i32 %13, i32* %5
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %30
16: ; preds = %11
%17 = load i32, i32* %5
%18 = call i32 @putchar(i32 %17)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* @errno
%23 = call i32 @strerror(i32 %22)
%24 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %21, %16
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %25
br label %30
29: ; preds = %25
br label %11
30: ; preds = %28, %11
br label %6
31: ; preds = %6
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [11 x i8] c"stdout: %s\00"
@errno = global i32 0
define void @head(i32* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %23, label %4
4: ; preds = %2, %21
%5 = phi i32 [ %6, %21 ], [ %1, %2 ]
%6 = add nsw i32 %5, -1
br label %7
7: ; preds = %4, %19
%8 = tail call i32 @getc(i32* %0)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %21, label %11
11: ; preds = %7
%12 = tail call i32 @putchar(i32 %8)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32, i32* @errno
%17 = tail call i32 @strerror(i32 %16)
%18 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %15, %11
%20 = icmp eq i32 %8, 10
br i1 %20, label %21, label %7
21: ; preds = %19, %7
%22 = icmp eq i32 %6, 0
br i1 %22, label %23, label %4
23: ; preds = %21, %2
ret void
}