#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 */
long atol(char *);
int /*<<< orphan*/ do_head(int /*<<< orphan*/ *, long);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  long nlines;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s n [file file...]\n", argv[0]);
    exit(1);
  }
  nlines = atol(argv[1]);
  if (argc == 2) {
    do_head(stdin, nlines);
  } else {
    int i;
    for (i = 2; i < argc; i++) {
      FILE *f;
      f = fopen(argv[i], "r");
      if (!f) {
        perror(argv[i]);
        exit(1);
      }
      do_head(f, nlines);
      fclose(f);
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b6 <main+0x46>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atol@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11e9 <main+0x79>
mov    0x2e10(%rip),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <do_head@plt>
jmp    1267 <main+0xf7>
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1262 <main+0xf2>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe0d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    123e <main+0xce>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <do_head@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f0 <main+0x80>
jmp    1267 <main+0xf7>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jg     11a5 <main+0x35>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe6a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %edi,%ebp
mov    0x8(%r14),%rdi
call   1060 <atol@plt>
mov    %rax,%r12
cmp    $0x2,%ebp
jne    11d1 <main+0x61>
mov    0x2e29(%rip),%rax
mov    (%rax),%rdi
mov    %r12,%rsi
call   1050 <do_head@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    %ebp,%r13d
mov    $0x2,%ebx
lea    0xe3c(%rip),%r15
mov    (%r14,%rbx,8),%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1217 <main+0xa7>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
call   1050 <do_head@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11e0 <main+0x70>
xor    %edi,%edi
call   1090 <exit@plt>
mov    %ebx,%eax
mov    (%r14,%rax,8),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s n [file file...]\0A\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @atol(i8* %21)
store i64 %22, i64* %6
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 2
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i32*, i32** @stdin
%27 = load i64, i64* %6
%28 = call i32 @do_head(i32* %26, i64 %27)
br label %61
29: ; preds = %18
store i32 2, i32* %7
br label %30
30: ; preds = %57, %29
%31 = load i32, i32* %7
%32 = load i32, i32* %4
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %60
34: ; preds = %30
%35 = load i8**, i8*** %5
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %40, i32** %8
%41 = load i32*, i32** %8
%42 = icmp ne i32* %41, null
br i1 %42, label %51, label %43
43: ; preds = %34
%44 = load i8**, i8*** %5
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 @perror(i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %34
%52 = load i32*, i32** %8
%53 = load i64, i64* %6
%54 = call i32 @do_head(i32* %52, i64 %53)
%55 = load i32*, i32** %8
%56 = call i32 @fclose(i32* %55)
br label %57
57: ; preds = %51
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %30
60: ; preds = %30
br label %61
61: ; preds = %60, %25
%62 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s n [file file...]\0A\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @atol(i8* %11)
%13 = icmp eq i32 %0, 2
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = zext i32 %0 to i64
br label %19
16: ; preds = %9
%17 = load i32*, i32** @stdin
%18 = tail call i32 @do_head(i32* %17, i64 %12)
br label %36
19: ; preds = %14, %31
%20 = phi i64 [ 2, %14 ], [ %34, %31 ]
%21 = getelementptr inbounds i8*, i8** %1, i64 %20
%22 = load i8*, i8** %21
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %31
25: ; preds = %19
%26 = and i64 %20, 4294967295
%27 = getelementptr inbounds i8*, i8** %1, i64 %26
%28 = load i8*, i8** %27
%29 = tail call i32 @perror(i8* %28)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %19
%32 = tail call i32 @do_head(i32* %23, i64 %12)
%33 = tail call i32 @fclose(i32* %23)
%34 = add nuw nsw i64 %20, 1
%35 = icmp eq i64 %34, %15
br i1 %35, label %36, label %19
36: ; preds = %31, %16
%37 = tail call i32 @exit(i32 0)
unreachable
}