#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*/ PATH_MAX;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int /*<<< orphan*/);
int system(char *);
int decompress_file(char *filename, char *new_filename) {
  int err;
  char command[255];
  if (filename == NULL || strlen(filename) <= 0)
    return -1;
  snprintf(command, 255, "gunzip %s", filename);
  err = system(command);
  if (err < 0) {
    perror("system");
    return -1;
  }
  if (new_filename != NULL) {
    int len;
    strncpy(new_filename, filename, PATH_MAX);
    len = strlen(filename);
    new_filename[len - 3] = '\0';
  }
  return 0;
}


x86 assembly (clang, -O0):
<decompress_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1180 <decompress_file+0x30>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jg     118c <decompress_file+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1224 <decompress_file+0xd4>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xff,%esi
lea    0xe5d(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x120(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11d9 <decompress_file+0x89>
lea    0xe42(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1224 <decompress_file+0xd4>
cmpq   $0x0,-0x18(%rbp)
je     121d <decompress_file+0xcd>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x124(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x124(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decompress_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     11c7 <decompress_file+0x77>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
jle    11c7 <decompress_file+0x77>
lea    0xe83(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xff,%esi
mov    %rbx,%rcx
call   1060 <snprintf@plt>
mov    %r15,%rdi
call   1050 <system@plt>
test   %eax,%eax
js     11d7 <decompress_file+0x87>
xor    %ebp,%ebp
test   %r14,%r14
je     11c7 <decompress_file+0x77>
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x3(%rax,%r14,1)
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2c(%rip),%rdi
call   1070 <perror@plt>
jmp    11c7 <decompress_file+0x77>

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

LLVM IR (-O2):
@.str = [10 x i8] c"gunzip %s\00"
@.str.1 = [7 x i8] c"system\00"
@PATH_MAX = global i32 0
define i32 @decompress_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 = icmp eq i8* %0, null
br i1 %5, label %24, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp slt i32 %7, 1
br i1 %8, label %24, label %9
9: ; preds = %6
%10 = call i32 @snprintf(i8* %4, i32 255, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = call i32 @system(i8* %4)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %24
15: ; preds = %9
%16 = icmp eq i8* %1, null
br i1 %16, label %24, label %17
17: ; preds = %15
%18 = load i32, i32* @PATH_MAX
%19 = call i32 @strncpy(i8* %1, i8* %0, i32 %18)
%20 = call i32 @strlen(i8* %0)
%21 = add nsw i32 %20, -3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %15, %17, %2, %6, %13
%25 = phi i32 [ -1, %13 ], [ -1, %6 ], [ -1, %2 ], [ 0, %17 ], [ 0, %15 ]
ret i32 %25
}