#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int F_OK;
int /*<<< orphan*/ O_RDONLY;
int R_OK;
int /*<<< orphan*/ _IOLBF;
int access(char *, int);
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ err_exit(char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int getopt(int, char **, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ print_usage(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                           int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  FILE *file;
  int c;
  int num_lines;
  char buf[4096];
  if (argc < 2 || (strcmp(argv[1], "--help") == 0)) {
    print_usage(EXIT_SUCCESS, argv[0]);
  }
  while ((c = getopt(argc, argv, "n:")) != -1) {
    switch (c) {
    case 'n':
      num_lines = atoi(optarg);
      num_lines = (num_lines > 0) ? num_lines : 10;
      break;
    default:
      print_usage(EXIT_FAILURE, argv[0]);
    }
  }
  if (argc == optind) {
    err_exit("missing file name\n");
  } else {
    if (access(argv[optind], F_OK | R_OK) == -1) {
      err_exit("cannot open %s for reading: %s\n", argv[optind],
               strerror(errno));
    }
  }
  fd = open(argv[optind], O_RDONLY);
  if (fd != -1) {
    file = fdopen(fd, "r");
    setvbuf(file, buf, _IOLBF, 4096);
    while (fgets(buf, 4096, file) != NULL) {
      printf("read line\n");
      printf("%s\n", buf);
    }
    fclose(file);
  } else {
    err_exit("Error on open: %s", strerror(errno));
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1221 <main+0x41>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdee(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1236 <main+0x56>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   10f0 <print_usage@plt>
jmp    123b <main+0x5b>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdbe(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     12cc <main+0xec>
mov    -0x24(%rbp),%eax
sub    $0x6e,%eax
jne    12b2 <main+0xd2>
jmp    126b <main+0x8b>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   10d0 <atoi@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    1294 <main+0xb4>
mov    -0x28(%rbp),%eax
mov    %eax,-0x1034(%rbp)
jmp    12a4 <main+0xc4>
mov    $0xa,%eax
mov    %eax,-0x1034(%rbp)
jmp    12a4 <main+0xc4>
mov    -0x1034(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    12c7 <main+0xe7>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   10f0 <print_usage@plt>
jmp    123b <main+0x5b>
mov    -0x8(%rbp),%eax
mov    0x2d02(%rip),%rcx
cmp    (%rcx),%eax
jne    12f1 <main+0x111>
lea    0xd25(%rip),%rdi
mov    $0x0,%al
call   1070 <err_exit@plt>
jmp    1366 <main+0x186>
mov    -0x10(%rbp),%rax
mov    0x2cdc(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2c8e(%rip),%rax
mov    (%rax),%esi
mov    0x2c9d(%rip),%rax
or     (%rax),%esi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
jne    1361 <main+0x181>
mov    -0x10(%rbp),%rax
mov    0x2caa(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x1040(%rbp)
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x1040(%rbp),%rsi
mov    %eax,%edx
lea    0xcc3(%rip),%rdi
mov    $0x0,%al
call   1070 <err_exit@plt>
jmp    1366 <main+0x186>
mov    -0x10(%rbp),%rax
mov    0x2c67(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2c61(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     1419 <main+0x239>
mov    -0x14(%rbp),%edi
lea    0xca0(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x1030(%rbp),%rsi
mov    0x2c08(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%ecx
call   1090 <setvbuf@plt>
lea    -0x1030(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     140b <main+0x22b>
lea    0xc55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1030(%rbp),%rsi
lea    0xc3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13c4 <main+0x1e4>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1437 <main+0x257>
mov    0x2ba8(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %eax,%esi
lea    0xc1a(%rip),%rdi
mov    $0x0,%al
call   1070 <err_exit@plt>
mov    0x2b6a(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x2,%edi
jl     120e <main+0x2e>
mov    0x8(%rbx),%rdi
lea    0xdfc(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    121f <main+0x3f>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rsi
call   10f0 <print_usage@plt>
lea    0xde1(%rip),%r14
mov    0x2dcb(%rip),%r15
mov    0x2d84(%rip),%r12
jmp    1248 <main+0x68>
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%edi
call   10d0 <atoi@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10c0 <getopt@plt>
cmp    $0x6e,%eax
je     1240 <main+0x60>
cmp    $0xffffffff,%eax
je     126d <main+0x8d>
mov    (%r12),%edi
mov    (%rbx),%rsi
call   10f0 <print_usage@plt>
jmp    1248 <main+0x68>
mov    0x2d64(%rip),%r14
movslq (%r14),%rax
cmp    %ebp,%eax
jne    128b <main+0xab>
lea    0xd88(%rip),%rdi
xor    %eax,%eax
call   1070 <err_exit@plt>
jmp    12d3 <main+0xf3>
mov    (%rbx,%rax,8),%rdi
mov    0x2d02(%rip),%rax
mov    0x2d13(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
jne    12d3 <main+0xf3>
movslq (%r14),%rax
mov    (%rbx,%rax,8),%rbp
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xd56(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <err_exit@plt>
movslq (%r14),%rax
mov    (%rbx,%rax,8),%rdi
mov    0x2cff(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
jne    1310 <main+0x130>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xd3d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <err_exit@plt>
jmp    138d <main+0x1ad>
lea    0xd26(%rip),%rsi
mov    %eax,%edi
call   1080 <fdopen@plt>
mov    %rax,%rbx
mov    0x2c98(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x1000,%ecx
call   1090 <setvbuf@plt>
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1385 <main+0x1a5>
lea    0xcf8(%rip),%r14
mov    %rsp,%rbp
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1360 <main+0x180>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2c14(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [3 x i8] c"n:\00"
@optarg = global i32 0
@EXIT_FAILURE = global i32 0
@optind = global i32 0
@.str.2 = [19 x i8] c"missing file name\0A\00"
@F_OK = global i32 0
@R_OK = global i32 0
@.str.3 = [32 x i8] c"cannot open %s for reading: %s\0A\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.4 = [2 x i8] c"r\00"
@_IOLBF = global i32 0
@.str.5 = [11 x i8] c"read line\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [18 x i8] c"Error on open: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %19, label %13
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %13, %2
%20 = load i32, i32* @EXIT_SUCCESS
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 @print_usage(i32 %20, i8* %23)
br label %25
25: ; preds = %19, %13
br label %26
26: ; preds = %49, %25
%27 = load i32, i32* %4
%28 = load i8**, i8*** %5
%29 = call i32 @getopt(i32 %27, i8** %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %29, i32* %8
%30 = icmp ne i32 %29, -1
br i1 %30, label %31, label %50
31: ; preds = %26
%32 = load i32, i32* %8
switch i32 %32, label %43 [
i32 110, label %33
]
33: ; preds = %31
%34 = load i32, i32* @optarg
%35 = call i32 @atoi(i32 %34)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = load i32, i32* %9
br label %41
40: ; preds = %33
br label %41
41: ; preds = %40, %38
%42 = phi i32 [ %39, %38 ], [ 10, %40 ]
store i32 %42, i32* %9
br label %49
43: ; preds = %31
%44 = load i32, i32* @EXIT_FAILURE
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = call i32 @print_usage(i32 %44, i8* %47)
br label %49
49: ; preds = %43, %41
br label %26
50: ; preds = %26
%51 = load i32, i32* %4
%52 = load i32, i32* @optind
%53 = icmp eq i32 %51, %52
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (i8*, ...) @err_exit(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %77
56: ; preds = %50
%57 = load i8**, i8*** %5
%58 = load i32, i32* @optind
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = load i32, i32* @F_OK
%63 = load i32, i32* @R_OK
%64 = or i32 %62, %63
%65 = call i32 @access(i8* %61, i32 %64)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %76
67: ; preds = %56
%68 = load i8**, i8*** %5
%69 = load i32, i32* @optind
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
%73 = load i32, i32* @errno
%74 = call i32 @strerror(i32 %73)
%75 = call i32 (i8*, ...) @err_exit(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %72, i32 %74)
br label %76
76: ; preds = %67, %56
br label %77
77: ; preds = %76, %54
%78 = load i8**, i8*** %5
%79 = load i32, i32* @optind
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8*, i8** %78, i64 %80
%82 = load i8*, i8** %81
%83 = load i32, i32* @O_RDONLY
%84 = call i32 @open(i8* %82, i32 %83)
store i32 %84, i32* %6
%85 = load i32, i32* %6
%86 = icmp ne i32 %85, -1
br i1 %86, label %87, label %106
87: ; preds = %77
%88 = load i32, i32* %6
%89 = call i32* @fdopen(i32 %88, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %89, i32** %7
%90 = load i32*, i32** %7
%91 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%92 = load i32, i32* @_IOLBF
%93 = call i32 @setvbuf(i32* %90, i8* %91, i32 %92, i32 4096)
br label %94
94: ; preds = %99, %87
%95 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%96 = load i32*, i32** %7
%97 = call i32* @fgets(i8* %95, i32 4096, i32* %96)
%98 = icmp ne i32* %97, null
br i1 %98, label %99, label %103
99: ; preds = %94
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%101 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %101)
br label %94
103: ; preds = %94
%104 = load i32*, i32** %7
%105 = call i32 @fclose(i32* %104)
br label %110
106: ; preds = %77
%107 = load i32, i32* @errno
%108 = call i32 @strerror(i32 %107)
%109 = call i32 (i8*, ...) @err_exit(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %108)
br label %110
110: ; preds = %106, %103
%111 = load i32, i32* @EXIT_SUCCESS
%112 = call i32 @exit(i32 %111)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [3 x i8] c"n:\00"
@optarg = global i32 0
@EXIT_FAILURE = global i32 0
@optind = global i32 0
@.str.2 = [19 x i8] c"missing file name\0A\00"
@F_OK = global i32 0
@R_OK = global i32 0
@.str.3 = [32 x i8] c"cannot open %s for reading: %s\0A\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.4 = [2 x i8] c"r\00"
@_IOLBF = global i32 0
@.str.7 = [18 x i8] c"Error on open: %s\00"
@str = [10 x i8] c"read line\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %6, %2
%12 = load i32, i32* @EXIT_SUCCESS
%13 = load i8*, i8** %1
%14 = tail call i32 @print_usage(i32 %12, i8* %13)
br label %15
15: ; preds = %11, %6
br label %16
16: ; preds = %25, %15
%17 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
switch i32 %17, label %21 [
i32 -1, label %26
i32 110, label %18
]
18: ; preds = %16
%19 = load i32, i32* @optarg
%20 = tail call i32 @atoi(i32 %19)
br label %25
21: ; preds = %16
%22 = load i32, i32* @EXIT_FAILURE
%23 = load i8*, i8** %1
%24 = tail call i32 @print_usage(i32 %22, i8* %23)
br label %25
25: ; preds = %21, %18
br label %16
26: ; preds = %16
%27 = load i32, i32* @optind
%28 = icmp eq i32 %27, %0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = tail call i32 (i8*, ...) @err_exit(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %48
31: ; preds = %26
%32 = sext i32 %27 to i64
%33 = getelementptr inbounds i8*, i8** %1, i64 %32
%34 = load i8*, i8** %33
%35 = load i32, i32* @F_OK
%36 = load i32, i32* @R_OK
%37 = or i32 %36, %35
%38 = tail call i32 @access(i8* %34, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %48
40: ; preds = %31
%41 = load i32, i32* @optind
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %1, i64 %42
%44 = load i8*, i8** %43
%45 = load i32, i32* @errno
%46 = tail call i32 @strerror(i32 %45)
%47 = tail call i32 (i8*, ...) @err_exit(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %44, i32 %46)
br label %48
48: ; preds = %31, %40, %29
%49 = load i32, i32* @optind
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %1, i64 %50
%52 = load i8*, i8** %51
%53 = load i32, i32* @O_RDONLY
%54 = tail call i32 @open(i8* %52, i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %69, label %56
56: ; preds = %48
%57 = tail call i32* @fdopen(i32 %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%58 = load i32, i32* @_IOLBF
%59 = call i32 @setvbuf(i32* %57, i8* %4, i32 %58, i32 4096)
%60 = call i32* @fgets(i8* %4, i32 4096, i32* %57)
%61 = icmp eq i32* %60, null
br i1 %61, label %67, label %62
62: ; preds = %56, %62
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%64 = call i32 @puts(i8* %4)
%65 = call i32* @fgets(i8* %4, i32 4096, i32* %57)
%66 = icmp eq i32* %65, null
br i1 %66, label %67, label %62
67: ; preds = %62, %56
%68 = call i32 @fclose(i32* %57)
br label %73
69: ; preds = %48
%70 = load i32, i32* @errno
%71 = tail call i32 @strerror(i32 %70)
%72 = tail call i32 (i8*, ...) @err_exit(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %69, %67
%74 = load i32, i32* @EXIT_SUCCESS
%75 = call i32 @exit(i32 %74)
unreachable
}