#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*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *get_line_from_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int head(int len, FILE *fp) {
  int i;
  char *input;
  for (i = 0; i < len; i++) {
    if ((input = get_line_from_file(fp)) == NULL)
      break;
    fputs(input, stdout);
    free(input);
  }
  return 0;
}


x86 assembly (clang, -O0):
<head>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1197 <head+0x67>
mov    -0x10(%rbp),%rdi
call   1050 <get_line_from_file@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    116e <head+0x3e>
jmp    1197 <head+0x67>
mov    -0x20(%rbp),%rdi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <head+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<head>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    1178 <head+0x48>
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e99(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <get_line_from_file@plt>
test   %rax,%rax
je     1178 <head+0x48>
mov    %rax,%rbx
mov    (%r15),%esi
mov    %rax,%rdi
call   1040 <fputs@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0xffffffff,%ebp
jne    1150 <head+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define i32 @head(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 0, i32* %5
br label %7
7: ; preds = %22, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %25
11: ; preds = %7
%12 = load i32*, i32** %4
%13 = call i8* @get_line_from_file(i32* %12)
store i8* %13, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %11
br label %25
16: ; preds = %11
%17 = load i8*, i8** %6
%18 = load i32, i32* @stdout
%19 = call i32 @fputs(i8* %17, i32 %18)
%20 = load i8*, i8** %6
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %16
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %7
25: ; preds = %15, %7
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
define i32 @head(i32 %0, i32* %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %14
4: ; preds = %2, %8
%5 = phi i32 [ %12, %8 ], [ 0, %2 ]
%6 = tail call i8* @get_line_from_file(i32* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = load i32, i32* @stdout
%10 = tail call i32 @fputs(i8* %6, i32 %9)
%11 = tail call i32 @free(i8* %6)
%12 = add nuw nsw i32 %5, 1
%13 = icmp eq i32 %12, %0
br i1 %13, label %14, label %4
14: ; preds = %8, %4, %2
ret i32 0
}