#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 /*<<< orphan*/ extract_entry(char *, int, int /*<<< orphan*/, int,
                                 int /*<<< orphan*/);
int file_exists(char *);
int get_entries(int *);
int /*<<< orphan*/ get_entry_offsets(char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int list_tar_entries(char *tarname, int verbose) {
  if (file_exists(tarname) == -1) {
    printf("tarino-native: Archive \'%s\' does not exist.\n", tarname);
    return -1;
  }
  int offsets[10000];
  get_entry_offsets(tarname, offsets);
  int entries = get_entries(offsets);
  if (verbose == 1) {
    printf("tarino-native: Listing %d entries from archive.\n\n", entries);
  }
  int i;
  for (i = 0; i < entries; i++) {
    extract_entry(tarname, offsets[i], 0, verbose, 0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<list_tar_entries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <file_exists@plt>
cmp    $0xffffffff,%eax
jne    1192 <list_tar_entries+0x42>
mov    -0x10(%rbp),%rsi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <list_tar_entries+0xd9>
mov    -0x10(%rbp),%rdi
lea    -0x9c60(%rbp),%rsi
call   1060 <get_entry_offsets@plt>
lea    -0x9c60(%rbp),%rdi
call   1050 <get_entries@plt>
mov    %eax,-0x9c64(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    11d2 <list_tar_entries+0x82>
mov    -0x9c64(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x9c68(%rbp)
mov    -0x9c68(%rbp),%eax
cmp    -0x9c64(%rbp),%eax
jge    1222 <list_tar_entries+0xd2>
mov    -0x10(%rbp),%rdi
movslq -0x9c68(%rbp),%rax
mov    -0x9c60(%rbp,%rax,4),%esi
mov    -0x14(%rbp),%ecx
xor    %r8d,%r8d
mov    %r8d,%edx
call   1070 <extract_entry@plt>
mov    -0x9c68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c68(%rbp)
jmp    11dc <list_tar_entries+0x8c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x9c70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_tar_entries>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x9c40,%rsp
mov    %esi,%r15d
mov    %rdi,%r12
call   1030 <file_exists@plt>
cmp    $0xffffffff,%eax
je     11d0 <list_tar_entries+0x80>
mov    %rsp,%r14
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <get_entry_offsets@plt>
mov    %r14,%rdi
call   1050 <get_entries@plt>
mov    %eax,%r14d
cmp    $0x1,%r15d
jne    119f <list_tar_entries+0x4f>
lea    0xe98(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
jle    11cc <list_tar_entries+0x7c>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%rsp,%rbx,4),%esi
mov    %r12,%rdi
xor    %edx,%edx
mov    %r15d,%ecx
xor    %r8d,%r8d
call   1070 <extract_entry@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <list_tar_entries+0x60>
xor    %eax,%eax
jmp    11e6 <list_tar_entries+0x96>
lea    0xe29(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x9c40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"tarino-native: Archive '%s' does not exist.\0A\00"
@.str.1 = [50 x i8] c"tarino-native: Listing %d entries from archive.\0A\0A\00"
define i32 @list_tar_entries(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [10000 x i32]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32 @file_exists(i8* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 -1, i32* %3
br label %43
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = getelementptr inbounds [10000 x i32], [10000 x i32]* %6, i64 0, i64 0
%18 = call i32 @get_entry_offsets(i8* %16, i32* %17)
%19 = getelementptr inbounds [10000 x i32], [10000 x i32]* %6, i64 0, i64 0
%20 = call i32 @get_entries(i32* %19)
store i32 %20, i32* %7
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i32, i32* %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %23, %15
store i32 0, i32* %8
br label %27
27: ; preds = %39, %26
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %42
31: ; preds = %27
%32 = load i8*, i8** %4
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [10000 x i32], [10000 x i32]* %6, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %5
%38 = call i32 @extract_entry(i8* %32, i32 %36, i32 0, i32 %37, i32 0)
br label %39
39: ; preds = %31
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %27
42: ; preds = %27
store i32 0, i32* %3
br label %43
43: ; preds = %42, %12
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [45 x i8] c"tarino-native: Archive '%s' does not exist.\0A\00"
@.str.1 = [50 x i8] c"tarino-native: Listing %d entries from archive.\0A\0A\00"
define i32 @list_tar_entries(i8* %0, i32 %1) {
%3 = alloca [10000 x i32]
%4 = tail call i32 @file_exists(i8* %0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %28
8: ; preds = %2
%9 = bitcast [10000 x i32]* %3 to i8*
%10 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 0
%11 = call i32 @get_entry_offsets(i8* %0, i32* %10)
%12 = call i32 @get_entries(i32* %10)
%13 = icmp eq i32 %1, 1
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %16
16: ; preds = %14, %8
%17 = icmp sgt i32 %12, 0
br i1 %17, label %18, label %27
18: ; preds = %16
%19 = zext i32 %12 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %25, %20 ]
%22 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = call i32 @extract_entry(i8* %0, i32 %23, i32 0, i32 %1, i32 0)
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %19
br i1 %26, label %27, label %20
27: ; preds = %20, %16
br label %28
28: ; preds = %27, %6
%29 = phi i32 [ -1, %6 ], [ 0, %27 ]
ret i32 %29
}