#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 */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ system(char *);
int db_gzip(char *fn, char **argv) {
  printf("Gzipping database...");
  char *s = calloc(1, 30);
  strcat(s, argv[0]);
  strcat(s, "/");
  strcat(s, "unsorted");
  char *str = malloc(60);
  sprintf(str, "bash -c \"cd %s && gzip *\"", s);
  system(str);
  free(str);
  free(s);
}


x86 assembly (clang, -O0):
<db_gzip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
mov    $0x1e,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1080 <strcat@plt>
mov    $0x3c,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe34(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <system@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_gzip>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xe81(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
mov    $0x1e,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
mov    (%r14),%rsi
mov    %rax,%rdi
call   1080 <strcat@plt>
lea    0xe6d(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
lea    0xe60(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
mov    $0x3c,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe4d(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Gzipping database...\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [9 x i8] c"unsorted\00"
@.str.3 = [26 x i8] c"bash -c \22cd %s && gzip *\22\00"
define i32 @db_gzip(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
%8 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%9 = call i8* @calloc(i32 1, i32 30)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @strcat(i8* %10, i8* %13)
%15 = load i8*, i8** %6
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %6
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%19 = call i8* @malloc(i32 60)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = load i8*, i8** %6
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %7
%24 = call i32 @system(i8* %23)
%25 = load i8*, i8** %7
%26 = call i32 @free(i8* %25)
%27 = load i8*, i8** %6
%28 = call i32 @free(i8* %27)
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [21 x i8] c"Gzipping database...\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [9 x i8] c"unsorted\00"
@.str.3 = [26 x i8] c"bash -c \22cd %s && gzip *\22\00"
define i32 @db_gzip(i8* nocapture readnone %0, i8** nocapture %1) {
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = tail call dereferenceable_or_null(30) i8* @calloc(i32 1, i32 30)
%5 = load i8*, i8** %1
%6 = tail call i32 @strcat(i8* %4, i8* %5)
%7 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call dereferenceable_or_null(60) i8* @malloc(i32 60)
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%11 = tail call i32 @system(i8* %9)
%12 = tail call i32 @free(i8* %9)
%13 = tail call i32 @free(i8* %4)
ret i32 undef
}