#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*/ argv;

/* Variables and functions */
int /*<<< orphan*/ my_printf(char *, char *);
scalar_t__ optind;
scalar_t__ tar_main(int, char **);
int untar_rootfs(char *filename, char *directory, int quiet, int no_write) {
  optind = 0;
  char *argv[] = {"tar", "-x", "-f", filename, "-C", directory, NULL};
  int argc = (int)(sizeof(argv) / sizeof(argv[0])) - 1;
  if (!quiet)
    my_printf("Untar: tar xf %s\n", filename);
  if (!no_write)
    if (tar_main(argc, argv) != 0)
      return 0;
  return 1;
}


x86 assembly (clang, -O0):
<untar_rootfs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    0x2eab(%rip),%rax
movq   $0x0,(%rax)
lea    0xeb5(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xea6(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xe96(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x6,-0x64(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11a9 <untar_rootfs+0x89>
mov    -0x10(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1030 <my_printf@plt>
cmpl   $0x0,-0x20(%rbp)
jne    11da <untar_rootfs+0xba>
mov    -0x64(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1040 <tar_main@plt>
cmp    $0x0,%rax
je     11d5 <untar_rootfs+0xb5>
movl   $0x0,-0x4(%rbp)
jmp    11e1 <untar_rootfs+0xc1>
jmp    11da <untar_rootfs+0xba>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<untar_rootfs>:
push   %rbx
sub    $0x40,%rsp
mov    %ecx,%ebx
mov    0x2eba(%rip),%rcx
movq   $0x0,(%rcx)
lea    0xec4(%rip),%rcx
mov    %rcx,(%rsp)
lea    0xebd(%rip),%rcx
mov    %rcx,0x8(%rsp)
lea    0xeb4(%rip),%rcx
mov    %rcx,0x10(%rsp)
mov    %rdi,0x18(%rsp)
lea    0xea6(%rip),%rcx
mov    %rcx,0x20(%rsp)
mov    %rsi,0x28(%rsp)
movq   $0x0,0x30(%rsp)
test   %edx,%edx
je     1181 <untar_rootfs+0x61>
test   %ebx,%ebx
jne    11ae <untar_rootfs+0x8e>
jmp    1197 <untar_rootfs+0x77>
mov    %rdi,%rax
lea    0xe82(%rip),%rdi
mov    %rax,%rsi
call   1030 <my_printf@plt>
test   %ebx,%ebx
jne    11ae <untar_rootfs+0x8e>
mov    %rsp,%rsi
mov    $0x6,%edi
call   1040 <tar_main@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11b3 <untar_rootfs+0x93>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@optind = global i64 0
@.str = [4 x i8] c"tar\00"
@.str.1 = [3 x i8] c"-x\00"
@.str.2 = [3 x i8] c"-f\00"
@.str.3 = [3 x i8] c"-C\00"
@.str.4 = [18 x i8] c"Untar: tar xf %s\0A\00"
define i32 @untar_rootfs(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [7 x i8*]
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i64 0, i64* @optind
%12 = getelementptr inbounds [7 x i8*], [7 x i8*]* %10, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds i8*, i8** %12, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds i8*, i8** %13, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %6
store i8* %16, i8** %15
%17 = getelementptr inbounds i8*, i8** %15, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %7
store i8* %19, i8** %18
%20 = getelementptr inbounds i8*, i8** %18, i64 1
store i8* null, i8** %20
store i32 6, i32* %11
%21 = load i32, i32* %8
%22 = icmp ne i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %4
%24 = load i8*, i8** %6
%25 = call i32 @my_printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %4
%27 = load i32, i32* %9
%28 = icmp ne i32 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %26
%30 = load i32, i32* %11
%31 = getelementptr inbounds [7 x i8*], [7 x i8*]* %10, i64 0, i64 0
%32 = call i64 @tar_main(i32 %30, i8** %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 0, i32* %5
br label %37
35: ; preds = %29
br label %36
36: ; preds = %35, %26
store i32 1, i32* %5
br label %37
37: ; preds = %36, %34
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
@optind = global i64 0
@.str = [4 x i8] c"tar\00"
@.str.1 = [3 x i8] c"-x\00"
@.str.2 = [3 x i8] c"-f\00"
@.str.3 = [3 x i8] c"-C\00"
@.str.4 = [18 x i8] c"Untar: tar xf %s\0A\00"
define i32 @untar_rootfs(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [7 x i8*]
store i64 0, i64* @optind
%6 = bitcast [7 x i8*]* %5 to i8*
%7 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i64 0, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i64 0, i64 3
store i8* %0, i8** %10
%11 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i64 0, i64 4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i64 0, i64 5
store i8* %1, i8** %12
%13 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i64 0, i64 6
store i8* null, i8** %13
%14 = icmp eq i32 %2, 0
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = tail call i32 @my_printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %15, %4
%18 = icmp eq i32 %3, 0
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = call i64 @tar_main(i32 6, i8** %7)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19, %17
br label %23
23: ; preds = %19, %22
%24 = phi i32 [ 1, %22 ], [ 0, %19 ]
ret i32 %24
}