#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 INT_MAX;
int atoi(char *);
int /*<<< orphan*/ cleancache(char *, int);
int /*<<< orphan*/ cleanlines(char **, int);
int /*<<< orphan*/ printf(char *, ...);
int readlines_tailqueue(char **, int *, char *, int);
int /*<<< orphan*/ writelines(char **, int, char *, int);
int main(int argc, char *argv[]) {
  int res;
  int ntail = 10;
  if (argc > 2) {
    printf("\nUsage:\n\t%s -n\n\tn -\tnumber of tailed lines\n", argv[0]);
    return 1;
  }
  if (argc == 2 && *(argv + 1)[0] == '-') {
    int tmp = atoi(argv[1] + 1);
    if (tmp > 0 && tmp < INT_MAX)
      ntail = tmp;
  }
  char cache[1000 * ntail];
  char *lineptr[ntail];
  cleanlines(lineptr, ntail);
  cleancache(cache, 1000 * ntail);
  res = readlines_tailqueue(lineptr, &ntail, cache, 1000 * ntail);
  if (!res) {
    writelines(lineptr, ntail, cache, 1000 * ntail);
    return 0;
  } else {
    switch (res) {
    case 1:
      printf("error: too long string in input\n");
      break;
    case 2:
      printf("error: cache too small to store %d strings, this shouldn`t "
             "happen...\n",
             ntail);
      break;
    default:
      printf("error: unknown error code occured\n");
      break;
    }
    return res;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xa,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11a8 <main+0x48>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1324 <main+0x1c4>
cmpl   $0x2,-0x8(%rbp)
jne    1201 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1201 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
add    $0x1,%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11fc <main+0x9c>
mov    -0x1c(%rbp),%eax
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%eax
jge    11fc <main+0x9c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1201 <main+0xa1>
mov    -0x18(%rbp),%eax
imul   $0x3e8,%eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%esi
call   1060 <cleanlines@plt>
mov    -0x48(%rbp),%rdi
imul   $0x3e8,-0x18(%rbp),%esi
call   1080 <cleancache@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rdx
imul   $0x3e8,-0x18(%rbp),%ecx
lea    -0x18(%rbp),%rsi
call   1030 <readlines_tailqueue@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    12b4 <main+0x154>
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%esi
imul   $0x3e8,-0x18(%rbp),%ecx
call   1050 <writelines@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    131d <main+0x1bd>
mov    -0x14(%rbp),%eax
mov    %eax,-0x54(%rbp)
sub    $0x1,%eax
je     12d9 <main+0x179>
jmp    12c8 <main+0x168>
mov    -0x54(%rbp),%eax
sub    $0x2,%eax
je     12ec <main+0x18c>
jmp    1302 <main+0x1a2>
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1310 <main+0x1b0>
mov    -0x18(%rbp),%esi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1310 <main+0x1b0>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0xa,-0x2c(%rbp)
cmp    $0x3,%edi
jl     11a6 <main+0x36>
mov    (%rsi),%rsi
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r14d
jmp    1288 <main+0x118>
mov    $0xa,%r14d
cmp    $0x2,%edi
jne    11d8 <main+0x68>
mov    0x8(%rsi),%rdi
cmpb   $0x2d,(%rdi)
jne    11d8 <main+0x68>
add    $0x1,%rdi
call   1080 <atoi@plt>
test   %eax,%eax
jle    11d8 <main+0x68>
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%eax
jge    11d8 <main+0x68>
mov    %eax,-0x2c(%rbp)
mov    %eax,%r14d
mov    %rsp,%r13
imul   $0x3e8,%r14d,%r12d
mov    %rsp,%r15
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %r14d,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14d,%esi
call   1070 <cleanlines@plt>
mov    %r15,%rdi
mov    %r12d,%esi
call   1090 <cleancache@plt>
lea    -0x2c(%rbp),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r12d,%ecx
call   1040 <readlines_tailqueue@plt>
mov    %eax,%r14d
cmp    $0x2,%eax
je     125d <main+0xed>
cmp    $0x1,%r14d
je     1270 <main+0x100>
test   %r14d,%r14d
jne    1279 <main+0x109>
mov    -0x2c(%rbp),%esi
imul   $0x3e8,%esi,%ecx
mov    %rbx,%rdi
mov    %r15,%rdx
call   1060 <writelines@plt>
jmp    1285 <main+0x115>
mov    -0x2c(%rbp),%esi
lea    0xdc5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1285 <main+0x115>
lea    0xdfb(%rip),%rdi
jmp    1280 <main+0x110>
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"\0AUsage:\0A\09%s -n\0A\09n -\09number of tailed lines\0A\00"
@INT_MAX = global i32 0
@.str.1 = [33 x i8] c"error: too long string in input\0A\00"
@.str.2 = [70 x i8] c"error: cache too small to store %d strings, this shouldn`t happen...\0A\00"
@.str.3 = [35 x i8] c"error: unknown error code occured\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 i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10, i32* %7
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 1, i32* %3
br label %83
20: ; preds = %2
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %46
23: ; preds = %20
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 45
br i1 %30, label %31, label %46
31: ; preds = %23
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %31
%40 = load i32, i32* %8
%41 = load i32, i32* @INT_MAX
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = load i32, i32* %8
store i32 %44, i32* %7
br label %45
45: ; preds = %43, %39, %31
br label %46
46: ; preds = %45, %23, %20
%47 = load i32, i32* %7
%48 = mul nsw i32 1000, %47
%49 = zext i32 %48 to i64
%50 = call i8* @llvm.stacksave()
store i8* %50, i8** %9
%51 = alloca i8, i64 %49
store i64 %49, i64* %10
%52 = load i32, i32* %7
%53 = zext i32 %52 to i64
%54 = alloca i8*, i64 %53
store i64 %53, i64* %11
%55 = load i32, i32* %7
%56 = call i32 @cleanlines(i8** %54, i32 %55)
%57 = load i32, i32* %7
%58 = mul nsw i32 1000, %57
%59 = call i32 @cleancache(i8* %51, i32 %58)
%60 = load i32, i32* %7
%61 = mul nsw i32 1000, %60
%62 = call i32 @readlines_tailqueue(i8** %54, i32* %7, i8* %51, i32 %61)
store i32 %62, i32* %6
%63 = load i32, i32* %6
%64 = icmp ne i32 %63, 0
br i1 %64, label %70, label %65
65: ; preds = %46
%66 = load i32, i32* %7
%67 = load i32, i32* %7
%68 = mul nsw i32 1000, %67
%69 = call i32 @writelines(i8** %54, i32 %66, i8* %51, i32 %68)
store i32 0, i32* %3
store i32 1, i32* %12
br label %81
70: ; preds = %46
%71 = load i32, i32* %6
switch i32 %71, label %77 [
i32 1, label %72
i32 2, label %74
]
72: ; preds = %70
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %79
74: ; preds = %70
%75 = load i32, i32* %7
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0), i32 %75)
br label %79
77: ; preds = %70
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %79
79: ; preds = %77, %74, %72
%80 = load i32, i32* %6
store i32 %80, i32* %3
store i32 1, i32* %12
br label %81
81: ; preds = %79, %65
%82 = load i8*, i8** %9
br label %83
83: ; preds = %81, %15
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [44 x i8] c"\0AUsage:\0A\09%s -n\0A\09n -\09number of tailed lines\0A\00"
@INT_MAX = global i32 0
@.str.2 = [70 x i8] c"error: cache too small to store %d strings, this shouldn`t happen...\0A\00"
@str = [32 x i8] c"error: too long string in input\00"
@str.4 = [34 x i8] c"error: unknown error code occured\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 10, i32* %3
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %47
9: ; preds = %2
%10 = icmp eq i32 %0, 2
br i1 %10, label %11, label %24
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 45
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %13, i64 1
%18 = tail call i32 @atoi(i8* %17)
%19 = icmp sgt i32 %18, 0
%20 = load i32, i32* @INT_MAX
%21 = icmp slt i32 %18, %20
%22 = select i1 %19, i1 %21, i1 false
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 %18, i32* %3
br label %24
24: ; preds = %16, %23, %11, %9
%25 = phi i32 [ 10, %16 ], [ %18, %23 ], [ 10, %11 ], [ 10, %9 ]
%26 = mul nsw i32 %25, 1000
%27 = zext i32 %26 to i64
%28 = tail call i8* @llvm.stacksave()
%29 = alloca i8, i64 %27
%30 = zext i32 %25 to i64
%31 = alloca i8*, i64 %30
%32 = call i32 @cleanlines(i8** %31, i32 %25)
%33 = call i32 @cleancache(i8* %29, i32 %26)
%34 = call i32 @readlines_tailqueue(i8** %31, i32* %3, i8* %29, i32 %26)
switch i32 %34, label %44 [
i32 0, label %35
i32 1, label %39
i32 2, label %41
]
35: ; preds = %24
%36 = load i32, i32* %3
%37 = mul nsw i32 %36, 1000
%38 = call i32 @writelines(i8** %31, i32 %36, i8* %29, i32 %37)
br label %46
39: ; preds = %24
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %46
41: ; preds = %24
%42 = load i32, i32* %3
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %46
44: ; preds = %24
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.4, i64 0, i64 0))
br label %46
46: ; preds = %39, %41, %44, %35
br label %47
47: ; preds = %46, %6
%48 = phi i32 [ 1, %6 ], [ %34, %46 ]
ret i32 %48
}