#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 */
scalar_t__ get_line(char *);
int shift_up(char **, int, int);
int /*<<< orphan*/ strcpy(char *, char *);
void get_tail(char *tail_array[], int tail_length) {
  char line[1000];
  char *tail_buffer_array[tail_length];
  {
    int element = tail_length;
    while (--element >= 0)
      tail_buffer_array[element] = tail_array[element];
  };
  int element = tail_length;
  while (get_line(line) > 0) {
    element = shift_up(tail_array, tail_length, element);
    strcpy(tail_buffer_array[element], line);
  }
}


x86 assembly (clang, -O0):
<get_tail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x408(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x420(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x410(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x414(%rbp)
mov    -0x414(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x414(%rbp)
cmp    $0x0,%eax
jl     11b9 <get_tail+0x89>
mov    -0x420(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x414(%rbp),%rdx
mov    (%rcx,%rdx,8),%rdx
movslq -0x414(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    117b <get_tail+0x4b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x418(%rbp)
lea    -0x400(%rbp),%rdi
call   1040 <get_line@plt>
cmp    $0x0,%rax
jle    1215 <get_tail+0xe5>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x418(%rbp),%edx
call   1050 <shift_up@plt>
mov    %eax,%ecx
mov    -0x420(%rbp),%rax
mov    %ecx,-0x418(%rbp)
movslq -0x418(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x400(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11c2 <get_tail+0x92>
mov    -0x408(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tail>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
mov    %rsp,-0x30(%rbp)
mov    %esi,%edx
mov    %rsp,%r12
lea    0xf(,%rdx,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
test   %esi,%esi
jle    1188 <get_tail+0x48>
shl    $0x3,%rdx
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <memcpy@plt>
lea    -0x420(%rbp),%rdi
call   1040 <get_line@plt>
test   %rax,%rax
jle    11da <get_tail+0x9a>
lea    -0x420(%rbp),%r13
mov    %r15d,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
call   1060 <shift_up@plt>
mov    %eax,%ebx
cltq
mov    (%r12,%rax,8),%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
call   1040 <get_line@plt>
test   %rax,%rax
jg     11b0 <get_tail+0x70>
mov    -0x30(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @get_tail(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca [1000 x i8]
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8*, i64 %11
store i64 %11, i64* %7
%14 = load i32, i32* %4
store i32 %14, i32* %8
br label %15
15: ; preds = %19, %2
%16 = load i32, i32* %8
%17 = add nsw i32 %16, -1
store i32 %17, i32* %8
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i8**, i8*** %3
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %13, i64 %26
store i8* %24, i8** %27
br label %15
28: ; preds = %15
%29 = load i32, i32* %4
store i32 %29, i32* %9
br label %30
30: ; preds = %34, %28
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%32 = call i64 @get_line(i8* %31)
%33 = icmp sgt i64 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %30
%35 = load i8**, i8*** %3
%36 = load i32, i32* %4
%37 = load i32, i32* %9
%38 = call i32 @shift_up(i8** %35, i32 %36, i32 %37)
store i32 %38, i32* %9
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %13, i64 %40
%42 = load i8*, i8** %41
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%44 = call i32 @strcpy(i8* %42, i8* %43)
br label %30
45: ; preds = %30
%46 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
define void @get_tail(i8** %0, i32 %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = zext i32 %1 to i64
%6 = tail call i8* @llvm.stacksave()
%7 = alloca i8*, i64 %5
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = bitcast i8** %7 to i8*
%11 = bitcast i8** %0 to i8*
%12 = shl nuw nsw i64 %5, 3
br label %13
13: ; preds = %9, %2
%14 = call i64 @get_line(i8* %4)
%15 = icmp sgt i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %13, %16
%17 = phi i32 [ %18, %16 ], [ %1, %13 ]
%18 = call i32 @shift_up(i8** %0, i32 %1, i32 %17)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %7, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 @strcpy(i8* %21, i8* %4)
%23 = call i64 @get_line(i8* %4)
%24 = icmp sgt i64 %23, 0
br i1 %24, label %16, label %25
25: ; preds = %16, %13
ret void
}