#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, int, int);
int file_exists(char *);
int get_entries(int *);
int /*<<< orphan*/ get_entry_offsets(char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int extract_tar_entries(char *tarname, int overwrite, 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: Extracting %d entries from archive.\n\n", entries);
  }
  int i;
  for (i = 0; i < entries; i++) {
    extract_entry(tarname, offsets[i], overwrite, verbose, 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<extract_tar_entries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <file_exists@plt>
cmp    $0xffffffff,%eax
jne    1195 <extract_tar_entries+0x45>
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <extract_tar_entries+0xdf>
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,-0x18(%rbp)
jne    11d5 <extract_tar_entries+0x85>
mov    -0x9c64(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x9c68(%rbp)
mov    -0x9c68(%rbp),%eax
cmp    -0x9c64(%rbp),%eax
jge    1228 <extract_tar_entries+0xd8>
mov    -0x10(%rbp),%rdi
movslq -0x9c68(%rbp),%rax
mov    -0x9c60(%rbp,%rax,4),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    $0x1,%r8d
call   1070 <extract_entry@plt>
mov    -0x9c68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c68(%rbp)
jmp    11df <extract_tar_entries+0x8f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x9c70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_tar_entries>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x9c48,%rsp
mov    %edx,%r12d
mov    %esi,%r14d
mov    %rdi,%r13
call   1030 <file_exists@plt>
cmp    $0xffffffff,%eax
je     11d4 <extract_tar_entries+0x84>
mov    %rsp,%r15
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <get_entry_offsets@plt>
mov    %r15,%rdi
call   1050 <get_entries@plt>
mov    %eax,%r15d
cmp    $0x1,%r12d
jne    11a4 <extract_tar_entries+0x54>
lea    0xe93(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15d,%r15d
jle    11d0 <extract_tar_entries+0x80>
mov    %r15d,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
mov    (%rsp,%rbx,4),%esi
mov    %r13,%rdi
mov    %r14d,%edx
mov    %r12d,%ecx
mov    $0x1,%r8d
call   1070 <extract_entry@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <extract_tar_entries+0x60>
xor    %eax,%eax
jmp    11ea <extract_tar_entries+0x9a>
lea    0xe25(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x9c48,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 = [53 x i8] c"tarino-native: Extracting %d entries from archive.\0A\0A\00"
define i32 @extract_tar_entries(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [10000 x i32]
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = call i32 @file_exists(i8* %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %4
br label %46
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = getelementptr inbounds [10000 x i32], [10000 x i32]* %8, i64 0, i64 0
%20 = call i32 @get_entry_offsets(i8* %18, i32* %19)
%21 = getelementptr inbounds [10000 x i32], [10000 x i32]* %8, i64 0, i64 0
%22 = call i32 @get_entries(i32* %21)
store i32 %22, i32* %9
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i32, i32* %9
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %17
store i32 0, i32* %10
br label %29
29: ; preds = %42, %28
%30 = load i32, i32* %10
%31 = load i32, i32* %9
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load i8*, i8** %5
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10000 x i32], [10000 x i32]* %8, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = call i32 @extract_entry(i8* %34, i32 %38, i32 %39, i32 %40, i32 1)
br label %42
42: ; preds = %33
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %29
45: ; preds = %29
store i32 0, i32* %4
br label %46
46: ; preds = %45, %14
%47 = load i32, i32* %4
ret i32 %47
}

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