#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 */

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int head(int n) {
  int i;
  char buffer[1024];
  i = 1;
  while (i <= n && (fgets(buffer, 1024, stdin) != NULL)) {
    fputs(buffer, stdout);
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<head>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
xor    %eax,%eax
cmp    -0x4(%rbp),%ecx
mov    %al,-0x411(%rbp)
jg     1170 <head+0x50>
lea    -0x410(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x411(%rbp)
mov    -0x411(%rbp),%al
test   $0x1,%al
jne    1183 <head+0x63>
jmp    11a6 <head+0x86>
lea    -0x410(%rbp),%rdi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1135 <head+0x15>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<head>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
test   %edi,%edi
jle    1176 <head+0x56>
mov    %edi,%ebx
mov    0x2ead(%rip),%r15
mov    %rsp,%r14
mov    0x2e93(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%edx
mov    %r14,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     1176 <head+0x56>
mov    (%r12),%esi
mov    %r14,%rdi
call   1030 <fputs@plt>
add    $0xffffffff,%ebx
jne    1150 <head+0x30>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
define i32 @head(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
store i32 %0, i32* %2
store i32 1, i32* %3
br label %5
5: ; preds = %16, %1
%6 = load i32, i32* %3
%7 = load i32, i32* %2
%8 = icmp sle i32 %6, %7
br i1 %8, label %9, label %14
9: ; preds = %5
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i32* @fgets(i8* %10, i32 1024, i32 %11)
%13 = icmp ne i32* %12, null
br label %14
14: ; preds = %9, %5
%15 = phi i1 [ false, %5 ], [ %13, %9 ]
br i1 %15, label %16, label %22
16: ; preds = %14
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%18 = load i32, i32* @stdout
%19 = call i32 @fputs(i8* %17, i32 %18)
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %5
22: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
define i32 @head(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = icmp slt i32 %0, 1
br i1 %4, label %15, label %5
5: ; preds = %1, %10
%6 = phi i32 [ %13, %10 ], [ 1, %1 ]
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %3, i32 1024, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = load i32, i32* @stdout
%12 = call i32 @fputs(i8* %3, i32 %11)
%13 = add nuw i32 %6, 1
%14 = icmp eq i32 %6, %0
br i1 %14, label %15, label %5
15: ; preds = %5, %10, %1
ret i32 0
}