#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*/ O_RDONLY;
int STDIN_FILENO;
int /*<<< orphan*/ call_error(char const *);
int /*<<< orphan*/ close(int);
scalar_t__ extract_next_file(int);
int open(char const *, int /*<<< orphan*/);
int extract_tarball(const char *tar_path) {
  int fd;
  if (tar_path) {
    if ((fd = open(tar_path, O_RDONLY)) == -1) {
      call_error(tar_path);
    }
  } else {
    fd = STDIN_FILENO;
  }
  while (extract_next_file(fd))
    ;
  if (fd > 2)
    close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<extract_tarball>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1183 <extract_tarball+0x43>
mov    -0x8(%rbp),%rdi
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    117e <extract_tarball+0x3e>
mov    -0x8(%rbp),%rdi
call   1040 <call_error@plt>
jmp    118f <extract_tarball+0x4f>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    1194 <extract_tarball+0x54>
mov    -0xc(%rbp),%edi
call   1060 <extract_next_file@plt>
cmp    $0x0,%rax
je     11ab <extract_tarball+0x6b>
jmp    1194 <extract_tarball+0x54>
cmpl   $0x2,-0xc(%rbp)
jle    11bd <extract_tarball+0x7d>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_tarball>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1170 <extract_tarball+0x30>
mov    %rdi,%r14
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1180 <extract_tarball+0x40>
mov    %r14,%rdi
call   1040 <call_error@plt>
mov    $0xffffffff,%ebx
jmp    1180 <extract_tarball+0x40>
mov    0x2e61(%rip),%rax
mov    (%rax),%ebx
nopl   0x0(%rax)
mov    %ebx,%edi
call   1060 <extract_next_file@plt>
test   %rax,%rax
jne    1180 <extract_tarball+0x40>
cmp    $0x3,%ebx
jl     1198 <extract_tarball+0x58>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@STDIN_FILENO = global i32 0
define i32 @extract_tarball(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i8*, i8** %2
%13 = call i32 @call_error(i8* %12)
br label %14
14: ; preds = %11, %6
br label %17
15: ; preds = %1
%16 = load i32, i32* @STDIN_FILENO
store i32 %16, i32* %3
br label %17
17: ; preds = %15, %14
br label %18
18: ; preds = %22, %17
%19 = load i32, i32* %3
%20 = call i64 @extract_next_file(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
br label %18
23: ; preds = %18
%24 = load i32, i32* %3
%25 = icmp sgt i32 %24, 2
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %3
%28 = call i32 @close(i32 %27)
br label %29
29: ; preds = %26, %23
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@STDIN_FILENO = global i32 0
define i32 @extract_tarball(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = tail call i32 @call_error(i8* %0)
br label %11
9: ; preds = %1
%10 = load i32, i32* @STDIN_FILENO
br label %11
11: ; preds = %3, %7, %9
%12 = phi i32 [ -1, %7 ], [ %5, %3 ], [ %10, %9 ]
br label %13
13: ; preds = %13, %11
%14 = tail call i64 @extract_next_file(i32 %12)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %13
16: ; preds = %13
%17 = icmp sgt i32 %12, 2
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = tail call i32 @close(i32 %12)
br label %20
20: ; preds = %18, %16
ret i32 0
}