#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
long get_tail_length(int, char **);
int /*<<< orphan*/ print_tail(long, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  long tail_length = get_tail_length(argc, argv);
  FILE *input = (argc > 1) ? fopen(argv[argc - 1], "r") : NULL;
  print_tail(tail_length, input);
  (void)fclose(input);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <get_tail_length@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1196 <main+0x56>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe78(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    11a1 <main+0x61>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    11a1 <main+0x61>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <print_tail@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %edi,%ebx
call   1050 <get_tail_length@plt>
mov    %rax,%r14
cmp    $0x2,%ebx
jl     116f <main+0x2f>
add    $0xffffffff,%ebx
mov    (%r15,%rbx,8),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
jmp    1171 <main+0x31>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <print_tail@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i64 @get_tail_length(i32 %8, i8** %9)
store i64 %10, i64* %6
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %14, i64 %17
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %22
21: ; preds = %2
br label %22
22: ; preds = %21, %13
%23 = phi i32* [ %20, %13 ], [ null, %21 ]
store i32* %23, i32** %7
%24 = load i64, i64* %6
%25 = load i32*, i32** %7
%26 = call i32 @print_tail(i64 %24, i32* %25)
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 @get_tail_length(i32 %0, i8** %1)
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = add nsw i32 %0, -1
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %2, %5
%12 = phi i32* [ %10, %5 ], [ null, %2 ]
%13 = tail call i32 @print_tail(i64 %3, i32* %12)
%14 = tail call i32 @fclose(i32* %12)
ret i32 0
}