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

/* Variables and functions */
char EOF;
int /*<<< orphan*/ exit(int);
char fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  int i = 0, n = -1;
  char c[1024];
  char *ep;
  char *prog = *argv;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s [-n lines | -c bytes]\n", prog);
    exit(1);
  }
  n = strtol(argv[2], &ep, 10);
  if (*ep || n <= 0) {
    fprintf(stderr, "Illegal count!\n");
    exit(2);
  }
  if (*argv[1] == '-') {
    switch (*(argv[1] + 1)) {
    case 'c':
      while ((c[0] = fgetc(stdin)) != EOF && i < n) {
        printf("%c", c[0]);
        i++;
      }
      break;
    case 'n':
      memset(c, '\n', sizeof(c));
      while (fgets(c, sizeof(c), stdin) != NULL && i < n) {
        printf("%s", c);
        memset(c, '\n', sizeof(c));
        i++;
      }
      break;
    default:
      fprintf(stderr, "Unknown options!\n");
      exit(3);
    }
  } else {
    fprintf(stderr, "Illegal options!\n");
    exit(4);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x430(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11d7 <main+0x67>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    -0x430(%rbp),%rdx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x428(%rbp),%rsi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1210 <main+0xa0>
cmpl   $0x0,-0x18(%rbp)
jg     1231 <main+0xc1>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    13c4 <main+0x254>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x434(%rbp)
sub    $0x63,%eax
je     1279 <main+0x109>
jmp    1265 <main+0xf5>
mov    -0x434(%rbp),%eax
sub    $0x6e,%eax
je     12f9 <main+0x189>
jmp    139e <main+0x22e>
jmp    127e <main+0x10e>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   1050 <fgetc@plt>
mov    %al,-0x420(%rbp)
movsbl %al,%ecx
mov    0x2d44(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x435(%rbp)
je     12be <main+0x14e>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
setl   %al
mov    %al,-0x435(%rbp)
mov    -0x435(%rbp),%al
test   $0x1,%al
jne    12d1 <main+0x161>
jmp    12f4 <main+0x184>
movsbl -0x420(%rbp),%esi
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    127e <main+0x10e>
jmp    13bf <main+0x24f>
lea    -0x420(%rbp),%rdi
mov    $0xa,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    0x2ccb(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x436(%rbp)
je     134d <main+0x1dd>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
setl   %al
mov    %al,-0x436(%rbp)
mov    -0x436(%rbp),%al
test   $0x1,%al
jne    1360 <main+0x1f0>
jmp    1399 <main+0x229>
lea    -0x420(%rbp),%rsi
lea    0xcc6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    $0xa,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    130f <main+0x19f>
jmp    13bf <main+0x24f>
mov    0x2c2b(%rip),%rax
mov    (%rax),%edi
lea    0xc89(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
jmp    13e5 <main+0x275>
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
lea    0xc75(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x4,%edi
call   1090 <exit@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    12d0 <main+0x150>
mov    0x10(%rbx),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1090 <strtol@plt>
mov    %eax,%r12d
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    12f4 <main+0x174>
test   %r12d,%r12d
jle    12f4 <main+0x174>
mov    0x8(%rbx),%rax
cmpb   $0x2d,(%rax)
jne    1315 <main+0x195>
movsbl 0x1(%rax),%eax
cmp    $0x6e,%eax
je     1238 <main+0xb8>
cmp    $0x63,%eax
jne    1336 <main+0x1b6>
mov    0x2dfa(%rip),%r14
mov    (%r14),%edi
call   1060 <fgetc@plt>
mov    0x2de3(%rip),%rbp
cmp    0x0(%rbp),%al
je     12be <main+0x13e>
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    (%r14),%edi
call   1060 <fgetc@plt>
cmp    0x0(%rbp),%al
je     12be <main+0x13e>
lea    0x1(%rbx),%ecx
cmp    %r12d,%ebx
mov    %ecx,%ebx
jl     1210 <main+0x90>
jmp    12be <main+0x13e>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    0x2d92(%rip),%r15
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     12be <main+0x13e>
mov    $0x1,%ebp
lea    0xdba(%rip),%r14
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     12be <main+0x13e>
lea    0x1(%rbp),%eax
cmp    %r12d,%ebp
mov    %eax,%ebp
jl     1280 <main+0x100>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rdx
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0xd1d(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
lea    0xd1d(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
lea    0xd21(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>
mov    0x2c93(%rip),%rax
mov    (%rax),%edi
lea    0xcee(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s [-n lines | -c bytes]\0A\00"
@.str.1 = [16 x i8] c"Illegal count!\0A\00"
@stdin = global i32 0
@EOF = global i8 0
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [18 x i8] c"Unknown options!\0A\00"
@.str.5 = [18 x i8] c"Illegal options!\0A\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 [1024 x i8]
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 -1, i32* %7
%11 = load i8**, i8*** %5
%12 = load i8*, i8** %11
store i8* %12, i8** %10
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %10
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @strtol(i8* %23, i8** %9, i32 10)
store i32 %24, i32* %7
%25 = load i8*, i8** %9
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %20
%30 = load i32, i32* %7
%31 = icmp sle i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29, %20
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 2)
unreachable
36: ; preds = %29
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 45
br i1 %42, label %43, label %100
43: ; preds = %36
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
switch i32 %49, label %95 [
i32 99, label %50
i32 110, label %73
]
50: ; preds = %43
br label %51
51: ; preds = %65, %50
%52 = load i32, i32* @stdin
%53 = call signext i8 @fgetc(i32 %52)
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8 %53, i8* %54
%55 = sext i8 %53 to i32
%56 = load i8, i8* @EOF
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %55, %57
br i1 %58, label %59, label %63
59: ; preds = %51
%60 = load i32, i32* %6
%61 = load i32, i32* %7
%62 = icmp slt i32 %60, %61
br label %63
63: ; preds = %59, %51
%64 = phi i1 [ false, %51 ], [ %62, %59 ]
br i1 %64, label %65, label %72
65: ; preds = %63
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %68)
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
store i32 %71, i32* %6
br label %51
72: ; preds = %63
br label %99
73: ; preds = %43
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%75 = call i32 @memset(i8* %74, i8 signext 10, i32 1024)
br label %76
76: ; preds = %87, %73
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%78 = load i32, i32* @stdin
%79 = call i32* @fgets(i8* %77, i32 1024, i32 %78)
%80 = icmp ne i32* %79, null
br i1 %80, label %81, label %85
81: ; preds = %76
%82 = load i32, i32* %6
%83 = load i32, i32* %7
%84 = icmp slt i32 %82, %83
br label %85
85: ; preds = %81, %76
%86 = phi i1 [ false, %76 ], [ %84, %81 ]
br i1 %86, label %87, label %94
87: ; preds = %85
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %88)
%90 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%91 = call i32 @memset(i8* %90, i8 signext 10, i32 1024)
%92 = load i32, i32* %6
%93 = add nsw i32 %92, 1
store i32 %93, i32* %6
br label %76
94: ; preds = %85
br label %99
95: ; preds = %43
%96 = load i32, i32* @stderr
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%98 = call i32 @exit(i32 3)
unreachable
99: ; preds = %94, %72
br label %104
100: ; preds = %36
%101 = load i32, i32* @stderr
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%103 = call i32 @exit(i32 4)
unreachable
104: ; preds = %99
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s [-n lines | -c bytes]\0A\00"
@.str.1 = [16 x i8] c"Illegal count!\0A\00"
@stdin = global i32 0
@EOF = global i8 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [18 x i8] c"Unknown options!\0A\00"
@.str.5 = [18 x i8] c"Illegal options!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %9)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @strtol(i8* %15, i8** %4, i32 10)
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
%20 = icmp slt i32 %16, 1
%21 = select i1 %19, i1 true, i1 %20
br i1 %21, label %22, label %26
22: ; preds = %13
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @exit(i32 2)
unreachable
26: ; preds = %13
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 45
br i1 %30, label %31, label %71
31: ; preds = %26
%32 = getelementptr inbounds i8, i8* %28, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
switch i32 %34, label %67 [
i32 99, label %35
i32 110, label %52
]
35: ; preds = %31
%36 = load i32, i32* @stdin
%37 = tail call signext i8 @fgetc(i32 %36)
%38 = load i8, i8* @EOF
%39 = icmp eq i8 %37, %38
br i1 %39, label %75, label %40
40: ; preds = %35, %40
%41 = phi i8 [ %47, %40 ], [ %37, %35 ]
%42 = phi i32 [ %45, %40 ], [ 0, %35 ]
%43 = sext i8 %41 to i32
%44 = tail call i32 @putchar(i32 %43)
%45 = add nuw nsw i32 %42, 1
%46 = load i32, i32* @stdin
%47 = tail call signext i8 @fgetc(i32 %46)
%48 = load i8, i8* @EOF
%49 = icmp ne i8 %47, %48
%50 = icmp slt i32 %45, %16
%51 = select i1 %49, i1 %50, i1 false
br i1 %51, label %40, label %75
52: ; preds = %31
%53 = call i32 @memset(i8* %5, i8 signext 10, i32 1024)
%54 = load i32, i32* @stdin
%55 = call i32* @fgets(i8* %5, i32 1024, i32 %54)
%56 = icmp eq i32* %55, null
br i1 %56, label %75, label %57
57: ; preds = %52, %57
%58 = phi i32 [ %61, %57 ], [ 0, %52 ]
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%60 = call i32 @memset(i8* %5, i8 signext 10, i32 1024)
%61 = add nuw nsw i32 %58, 1
%62 = load i32, i32* @stdin
%63 = call i32* @fgets(i8* %5, i32 1024, i32 %62)
%64 = icmp ne i32* %63, null
%65 = icmp slt i32 %61, %16
%66 = select i1 %64, i1 %65, i1 false
br i1 %66, label %57, label %75
67: ; preds = %31
%68 = load i32, i32* @stderr
%69 = tail call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%70 = tail call i32 @exit(i32 3)
unreachable
71: ; preds = %26
%72 = load i32, i32* @stderr
%73 = tail call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%74 = tail call i32 @exit(i32 4)
unreachable
75: ; preds = %57, %40, %35, %52
ret i32 0
}