#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*/ tar_file_path;
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ Error(char *);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ rename_directory(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ wait(int /*<<< orphan*/ *);
bool create_tar_file(char *path) {
  char tar_file_path[4096] = {0};
  snprintf(tar_file_path, sizeof(tar_file_path), "%s.tar.gz", path);
  char *args[5] = {0};
  args[0] = "tar";
  args[1] = "-zcf";
  args[2] = tar_file_path;
  args[3] = path;
  args[4] = NULL;
  pid_t pid = fork();
  if (pid < 0) {
    Error("fork()");
  } else if (pid == 0) {
    execvp(args[0], args);
    exit(1);
  }
  pid = wait(NULL);
  rename_directory(path);
  return true;
}


x86 assembly (clang, -O0):
<create_tar_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1000,%esi
lea    0xe47(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x1040(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
lea    0xe32(%rip),%rax
mov    %rax,-0x1040(%rbp)
lea    0xe28(%rip),%rax
mov    %rax,-0x1038(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1030(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x1028(%rbp)
movq   $0x0,-0x1020(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x1048(%rbp)
cmpq   $0x0,-0x1048(%rbp)
jge    123e <create_tar_file+0xbe>
lea    0xddf(%rip),%rdi
call   1040 <Error@plt>
jmp    126e <create_tar_file+0xee>
cmpq   $0x0,-0x1048(%rbp)
jne    1269 <create_tar_file+0xe9>
mov    -0x1040(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
call   1070 <execvp@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    126e <create_tar_file+0xee>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <wait@plt>
mov    %rax,-0x1048(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rename_directory@plt>
mov    $0x1,%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_tar_file>:
push   %r14
push   %rbx
sub    $0x1038,%rsp
mov    %rdi,%rbx
lea    0x30(%rsp),%r14
mov    $0x1000,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe58(%rip),%rdx
mov    %r14,%rdi
mov    $0x1000,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
lea    0xe4b(%rip),%rax
mov    %rax,(%rsp)
lea    0xe44(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rbx,0x18(%rsp)
movq   $0x0,0x20(%rsp)
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1209 <create_tar_file+0x89>
jne    1215 <create_tar_file+0x95>
lea    0xe13(%rip),%rdi
mov    %rsp,%rsi
call   1070 <execvp@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe03(%rip),%rdi
call   1040 <Error@plt>
xor    %edi,%edi
call   1090 <wait@plt>
mov    %rbx,%rdi
call   1030 <rename_directory@plt>
mov    $0x1,%eax
add    $0x1038,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%s.tar.gz\00"
@.str.1 = [4 x i8] c"tar\00"
@.str.2 = [5 x i8] c"-zcf\00"
@.str.3 = [7 x i8] c"fork()\00"
define i32 @create_tar_file(i8* %0) {
%2 = alloca i8*
%3 = alloca [4096 x i8]
%4 = alloca [5 x i8*]
%5 = alloca i64
store i8* %0, i8** %2
%6 = bitcast [4096 x i8]* %3 to i8*
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%8 = load i8*, i8** %2
%9 = call i32 @snprintf(i8* %7, i32 4096, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = bitcast [5 x i8*]* %4 to i8*
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 2
store i8* %13, i8** %14
%15 = load i8*, i8** %2
%16 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 3
store i8* %15, i8** %16
%17 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 4
store i8* null, i8** %17
%18 = call i64 (...) @fork()
store i64 %18, i64* %5
%19 = load i64, i64* %5
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %1
%22 = call i32 @Error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %33
23: ; preds = %1
%24 = load i64, i64* %5
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 0
%28 = load i8*, i8** %27
%29 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 0
%30 = call i32 @execvp(i8* %28, i8** %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %23
br label %33
33: ; preds = %32, %21
%34 = call i64 @wait(i32* null)
store i64 %34, i64* %5
%35 = load i8*, i8** %2
%36 = call i32 @rename_directory(i8* %35)
ret i32 1
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s.tar.gz\00"
@.str.1 = [4 x i8] c"tar\00"
@.str.2 = [5 x i8] c"-zcf\00"
@.str.3 = [7 x i8] c"fork()\00"
define i32 @create_tar_file(i8* %0) {
%2 = alloca [4096 x i8]
%3 = alloca [5 x i8*]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 4096, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = bitcast [5 x i8*]* %3 to i8*
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 2
store i8* %4, i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 3
store i8* %0, i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 4
store i8* null, i8** %11
%12 = call i64 (...) @fork()
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @Error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %21
16: ; preds = %1
%17 = icmp eq i64 %12, 0
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = call i32 @execvp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %7)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %16, %14
%22 = call i64 @wait(i32* null)
%23 = call i32 @rename_directory(i8* %0)
ret i32 1
}