#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 PATH_MAX;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int system(char *);
int compress_file(char *filename, char *new_filename) {
  int err;
  char command[255];
  char nf[PATH_MAX];
  if (filename == NULL || strlen(filename) <= 0)
    return -1;
  snprintf(nf, PATH_MAX, "%s.gz", filename);
  snprintf(command, 255, "gzip -c -9 %s > %s", filename, nf);
  err = system(command);
  if (err < 0) {
    perror("system");
    return -1;
  }
  if (new_filename != NULL)
    strcpy(new_filename, nf);
  return 0;
}


x86 assembly (clang, -O0):
<compress_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x128(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x140(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b6 <compress_file+0x66>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jg     11cc <compress_file+0x7c>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x134(%rbp)
jmp    127a <compress_file+0x12a>
mov    -0x140(%rbp),%rdi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
lea    0xe19(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x140(%rbp),%r8
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xff,%esi
lea    0xdfa(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x120(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    124e <compress_file+0xfe>
lea    0xde6(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x134(%rbp)
jmp    127a <compress_file+0x12a>
cmpq   $0x0,-0x18(%rbp)
je     1269 <compress_file+0x119>
mov    -0x140(%rbp),%rsi
mov    -0x18(%rbp),%rdi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x134(%rbp)
mov    -0x128(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsp,%r13
mov    0x2e82(%rip),%r14
mov    (%r14),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    $0xffffffff,%r15d
test   %rdi,%rdi
je     11f8 <compress_file+0xa8>
mov    %rdi,%r12
mov    %rsi,-0x30(%rbp)
call   1040 <strlen@plt>
test   %rax,%rax
jle    11f8 <compress_file+0xa8>
mov    (%r14),%esi
lea    0xe58(%rip),%rdx
mov    %rbx,%rdi
mov    %r12,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
lea    0xe4a(%rip),%rdx
lea    -0x130(%rbp),%r14
mov    %r14,%rdi
mov    $0xff,%esi
mov    %r12,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r14,%rdi
call   1050 <system@plt>
test   %eax,%eax
js     120d <compress_file+0xbd>
mov    -0x30(%rbp),%rdi
test   %rdi,%rdi
je     11f5 <compress_file+0xa5>
mov    %rbx,%rsi
call   1030 <strcpy@plt>
xor    %r15d,%r15d
mov    %r13,%rsp
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe05(%rip),%rdi
call   1070 <perror@plt>
jmp    11f8 <compress_file+0xa8>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s.gz\00"
@.str.1 = [19 x i8] c"gzip -c -9 %s > %s\00"
@.str.2 = [7 x i8] c"system\00"
define i32 @compress_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [255 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i64 @strlen(i8* %18)
%20 = icmp sle i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17, %2
store i32 -1, i32* %3
store i32 1, i32* %10
br label %42
22: ; preds = %17
%23 = load i32, i32* @PATH_MAX
%24 = load i8*, i8** %4
%25 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %14, i32 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %4
%28 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %26, i32 255, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %14)
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%30 = call i32 @system(i8* %29)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %22
%34 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %10
br label %42
35: ; preds = %22
%36 = load i8*, i8** %5
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i8*, i8** %5
%40 = call i32 @strcpy(i8* %39, i8* %14)
br label %41
41: ; preds = %38, %35
store i32 0, i32* %3
store i32 1, i32* %10
br label %42
42: ; preds = %41, %33, %21
%43 = load i8*, i8** %8
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s.gz\00"
@.str.1 = [19 x i8] c"gzip -c -9 %s > %s\00"
@.str.2 = [7 x i8] c"system\00"
define i32 @compress_file(i8* %0, i8* %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = icmp eq i8* %0, null
br i1 %9, label %25, label %10
10: ; preds = %2
%11 = tail call i64 @strlen(i8* %0)
%12 = icmp slt i64 %11, 1
br i1 %12, label %25, label %13
13: ; preds = %10
%14 = load i32, i32* @PATH_MAX
%15 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %8, i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%16 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %4, i32 255, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %8)
%17 = call i32 @system(i8* %4)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %25
21: ; preds = %13
%22 = icmp eq i8* %1, null
br i1 %22, label %25, label %23
23: ; preds = %21
%24 = call i32 @strcpy(i8* %1, i8* %8)
br label %25
25: ; preds = %21, %23, %2, %10, %19
%26 = phi i32 [ -1, %19 ], [ -1, %10 ], [ -1, %2 ], [ 0, %23 ], [ 0, %21 ]
ret i32 %26
}