#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 atoi(int /*<<< orphan*/);
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 getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  int opt;
  long nlines = 10;
  while ((opt = getopt(argc, argv, "n:")) != -1) {
    switch (opt) {
    case 'n':
      nlines = atoi(optarg);
      break;
    case '?':
      fprintf(stderr, "Usage: %s [-n LINES] [file...]\n", argv[0]);
      exit(1);
    }
  }
  if (optind == argc) {
    do_head(stdin, nlines);
  } else {
    int i;
    for (i = optind; 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    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0xa,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe54(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1224 <main+0xa4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x3f,%eax
je     11f9 <main+0x79>
jmp    11d1 <main+0x51>
mov    -0x34(%rbp),%eax
sub    $0x6e,%eax
jne    121f <main+0x9f>
jmp    11e2 <main+0x62>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %rax,-0x20(%rbp)
jmp    121f <main+0x9f>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf3(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    119e <main+0x1e>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    124e <main+0xce>
mov    0x2da3(%rip),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <do_head@plt>
jmp    12d1 <main+0x151>
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12cc <main+0x14c>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12a8 <main+0x128>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <do_head@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    125a <main+0xda>
jmp    12d1 <main+0x151>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%ebp
mov    $0xa,%r14d
lea    0xe63(%rip),%r15
mov    0x2e54(%rip),%rbx
jmp    11b0 <main+0x30>
mov    (%rbx),%edi
call   1090 <atoi@plt>
mov    %rax,%r14
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   1080 <getopt@plt>
cmp    $0x6e,%eax
je     11a6 <main+0x26>
cmp    $0xffffffff,%eax
je     11ef <main+0x6f>
cmp    $0x3f,%eax
jne    11b0 <main+0x30>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xe23(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2de2(%rip),%rax
movslq (%rax),%rbx
cmp    %ebp,%ebx
jne    1216 <main+0x96>
mov    0x2ddc(%rip),%rax
mov    (%rax),%rdi
mov    %r14,%rsi
call   1050 <do_head@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
cmp    %ebp,%ebx
jge    1260 <main+0xe0>
movslq %ebp,%r13
lea    0xdff(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%rbx,8),%rdi
mov    %r15,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1267 <main+0xe7>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <do_head@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1230 <main+0xb0>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    (%r12,%rbx,8),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

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

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