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

/* Variables and functions */
int atoi(char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readlines(char **, int);
int /*<<< orphan*/ writelines(char **, int);
int main(int argc, char *argv[]) {
  int numlines = 10;
  char c;
  while (--argc > 0 && (*++argv)[0] == '-') {
    c = *(*argv + 1);
    if (isdigit(c)) {
      numlines = atoi(*argv + 1);
      if (numlines <= 0) {
        printf("\nillegal value\n");
        argc = -1;
      }
    } else {
      printf("\ntail: illegal option %c\n", c);
      argc = -1;
    }
  }
  if (argc != 0) {
    printf("Usage: tail -n");
  } else {
    char *lineptr[numlines];
    printf("\nDisplaying last %d lines\n", numlines);
    readlines(lineptr, numlines);
    writelines(lineptr, numlines);
  }
  printf("\n\n");
  return 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)
movl   $0xa,-0x14(%rbp)
mov    -0x8(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
jle    11a3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11b3 <main+0x63>
jmp    1228 <main+0xd8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x1(%rax),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     120a <main+0xba>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1205 <main+0xb5>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x8(%rbp)
jmp    1223 <main+0xd3>
movsbl -0x15(%rbp),%esi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x8(%rbp)
jmp    116d <main+0x1d>
cmpl   $0x0,-0x8(%rbp)
je     1245 <main+0xf5>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129c <main+0x14c>
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%esi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <readlines@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <writelines@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
cmp    $0x2,%edi
jl     11d2 <main+0x72>
mov    %rsi,%rbx
add    $0x8,%rbx
nopl   0x0(%rax)
mov    (%rbx),%rax
cmpb   $0x2d,(%rax)
jne    1247 <main+0xe7>
movsbl 0x1(%rax),%r14d
mov    %r14d,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1228 <main+0xc8>
mov    (%rbx),%rdi
add    $0x1,%rdi
call   1070 <atoi@plt>
test   %eax,%eax
jle    123b <main+0xdb>
add    $0xffffffff,%r15d
add    $0x8,%rbx
cmp    $0x1,%r15d
ja     1180 <main+0x20>
mov    %eax,%r14d
add    $0xffffffff,%r15d
test   %r15d,%r15d
jne    1247 <main+0xe7>
jmp    11e1 <main+0x81>
add    $0xffffffff,%r15d
mov    $0xa,%r14d
test   %r15d,%r15d
jne    1247 <main+0xe7>
mov    %rsp,%r15
mov    %r14d,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe26(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1080 <readlines@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1060 <writelines@plt>
mov    %r15,%rsp
jmp    1255 <main+0xf5>
lea    0xdd1(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1247 <main+0xe7>
lea    0xe02(%rip),%rdi
call   1040 <puts@plt>
lea    0xdcc(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdbc(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"\0Aillegal value\0A\00"
@.str.1 = [26 x i8] c"\0Atail: illegal option %c\0A\00"
@.str.2 = [15 x i8] c"Usage: tail -n\00"
@.str.3 = [27 x i8] c"\0ADisplaying last %d lines\0A\00"
@.str.4 = [3 x i8] c"\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10, i32* %6
br label %10
10: ; preds = %46, %2
%11 = load i32, i32* %4
%12 = add nsw i32 %11, -1
store i32 %12, i32* %4
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i32 1
store i8** %16, i8*** %5
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 45
br label %22
22: ; preds = %14, %10
%23 = phi i1 [ false, %10 ], [ %21, %14 ]
br i1 %23, label %24, label %47
24: ; preds = %22
%25 = load i8**, i8*** %5
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
store i8 %28, i8* %7
%29 = load i8, i8* %7
%30 = call i64 @isdigit(i8 signext %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %24
%33 = load i8**, i8*** %5
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = icmp sle i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %41
41: ; preds = %39, %32
br label %46
42: ; preds = %24
%43 = load i8, i8* %7
%44 = sext i8 %43 to i32
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %44)
store i32 -1, i32* %4
br label %46
46: ; preds = %42, %41
br label %10
47: ; preds = %22
%48 = load i32, i32* %4
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %64
52: ; preds = %47
%53 = load i32, i32* %6
%54 = zext i32 %53 to i64
%55 = call i8* @llvm.stacksave()
store i8* %55, i8** %8
%56 = alloca i8*, i64 %54
store i64 %54, i64* %9
%57 = load i32, i32* %6
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %6
%60 = call i32 @readlines(i8** %56, i32 %59)
%61 = load i32, i32* %6
%62 = call i32 @writelines(i8** %56, i32 %61)
%63 = load i8*, i8** %8
br label %64
64: ; preds = %52, %50
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [26 x i8] c"\0Atail: illegal option %c\0A\00"
@.str.2 = [15 x i8] c"Usage: tail -n\00"
@.str.3 = [27 x i8] c"\0ADisplaying last %d lines\0A\00"
@str = [2 x i8] c"\0A\00"
@str.5 = [15 x i8] c"\0Aillegal value\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add nsw i32 %0, -1
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %30
5: ; preds = %2, %27
%6 = phi i32 [ %28, %27 ], [ %3, %2 ]
%7 = phi i8** [ %8, %27 ], [ %1, %2 ]
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 45
br i1 %11, label %12, label %34
12: ; preds = %5
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i8, i8* %13
%15 = tail call i64 @isdigit(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %12
%18 = load i8*, i8** %8
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = tail call i32 @atoi(i8* %19)
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0))
br label %34
24: ; preds = %12
%25 = sext i8 %14 to i32
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %34
27: ; preds = %17
%28 = add nsw i32 %6, -1
%29 = icmp ugt i32 %6, 1
br i1 %29, label %5, label %30
30: ; preds = %27, %2
%31 = phi i32 [ 10, %2 ], [ %20, %27 ]
%32 = phi i32 [ %3, %2 ], [ %28, %27 ]
%33 = icmp eq i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %5, %22, %24, %30
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %43
36: ; preds = %30
%37 = zext i32 %31 to i64
%38 = tail call i8* @llvm.stacksave()
%39 = alloca i8*, i64 %37
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%41 = call i32 @readlines(i8** %39, i32 %31)
%42 = call i32 @writelines(i8** %39, i32 %31)
br label %43
43: ; preds = %36, %34
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret i32 0
}