#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*/ err(int, char *);
char *fgetln(int /*<<< orphan*/ *, size_t *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void head(FILE *fp, int cnt) {
  char *cp;
  size_t error, readlen;
  while (cnt && (cp = fgetln(fp, &readlen)) != NULL) {
    error = fwrite(cp, sizeof(char), readlen, stdout);
    if (error != readlen)
      err(1, "stdout");
    cnt--;
  }
}


x86 assembly (clang, -O0):
<head>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x29(%rbp)
je     1169 <head+0x39>
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <fgetln@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1179 <head+0x49>
jmp    11c5 <head+0x95>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    0x2e58(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1050 <fwrite@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11b7 <head+0x87>
mov    $0x1,%edi
lea    0xe4e(%rip),%rsi
call   1030 <err@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    113f <head+0xf>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<head>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
je     11a1 <head+0x71>
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x8(%rsp),%r15
mov    0x2e8e(%rip),%r13
lea    0xea7(%rip),%r12
jmp    1165 <head+0x35>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
je     11a1 <head+0x71>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <fgetln@plt>
test   %rax,%rax
je     11a1 <head+0x71>
mov    0x8(%rsp),%rdx
mov    0x0(%r13),%ecx
mov    %rax,%rdi
mov    $0x1,%esi
call   1050 <fwrite@plt>
cmp    0x8(%rsp),%rax
je     1160 <head+0x30>
mov    $0x1,%edi
mov    %r12,%rsi
call   1030 <err@plt>
jmp    1160 <head+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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