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

/* Variables and functions */
int /*<<< orphan*/ *openPipe(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char const *, char *);
scalar_t__ stringEndsIn(char *, char *);
FILE *writeZippedFile(char *fileName, char append) {
  char buf[512];
  const char *op = (append) ? ">>" : ">";
  if (stringEndsIn(fileName, ".bz2") || stringEndsIn(fileName, ".bz"))
    sprintf(buf, "%s %s \"%s\"", "bzip2 -1", op, fileName);
  else if (stringEndsIn(fileName, ".Z"))
    sprintf(buf, "%s %s \"%s\"", "compress", op, fileName);
  else
    sprintf(buf, "%s %s \"%s\"", "gzip -1", op, fileName);
  return openPipe(buf, "w");
}


x86 assembly (clang, -O0):
<writeZippedFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%edx
lea    0xeb1(%rip),%rax
lea    0xea9(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x218(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1030 <stringEndsIn@plt>
cmp    $0x0,%rax
jne    1199 <writeZippedFile+0x69>
mov    -0x8(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1030 <stringEndsIn@plt>
cmp    $0x0,%rax
je     11c3 <writeZippedFile+0x93>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xe5a(%rip),%rsi
lea    0xe5e(%rip),%rdx
call   1050 <sprintf@plt>
jmp    1231 <writeZippedFile+0x101>
mov    -0x8(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1030 <stringEndsIn@plt>
cmp    $0x0,%rax
je     1207 <writeZippedFile+0xd7>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xe16(%rip),%rsi
lea    0xe26(%rip),%rdx
call   1050 <sprintf@plt>
jmp    122c <writeZippedFile+0xfc>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xdec(%rip),%rsi
lea    0xe05(%rip),%rdx
call   1050 <sprintf@plt>
jmp    1231 <writeZippedFile+0x101>
lea    -0x210(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1040 <openPipe@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeZippedFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xeb9(%rip),%rsi
call   1030 <stringEndsIn@plt>
lea    0xec1(%rip),%r15
test   %rax,%rax
jne    1193 <writeZippedFile+0x63>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
call   1030 <stringEndsIn@plt>
test   %rax,%rax
jne    1193 <writeZippedFile+0x63>
lea    0xeaa(%rip),%rsi
mov    %rbx,%rdi
call   1030 <stringEndsIn@plt>
test   %rax,%rax
lea    0xea4(%rip),%rax
lea    0xe94(%rip),%r15
cmove  %rax,%r15
test   %r14b,%r14b
lea    0xe64(%rip),%rax
lea    0xe5c(%rip),%rcx
cmove  %rax,%rcx
lea    0xe5d(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r15,%rdx
mov    %rbx,%r8
call   1050 <sprintf@plt>
lea    0xe6d(%rip),%rsi
mov    %rbp,%rdi
call   1040 <openPipe@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c">>\00"
@.str.1 = [2 x i8] c">\00"
@.str.2 = [5 x i8] c".bz2\00"
@.str.3 = [4 x i8] c".bz\00"
@.str.4 = [11 x i8] c"%s %s \22%s\22\00"
@.str.5 = [9 x i8] c"bzip2 -1\00"
@.str.6 = [3 x i8] c".Z\00"
@.str.7 = [9 x i8] c"compress\00"
@.str.8 = [8 x i8] c"gzip -1\00"
@.str.9 = [2 x i8] c"w\00"
define i32* @writeZippedFile(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca [512 x i8]
%6 = alloca i8*
store i8* %0, i8** %3
store i8 %1, i8* %4
%7 = load i8, i8* %4
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
%10 = zext i1 %9 to i64
%11 = select i1 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
store i8* %11, i8** %6
%12 = load i8*, i8** %3
%13 = call i64 @stringEndsIn(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i64 @stringEndsIn(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15, %2
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%21 = load i8*, i8** %6
%22 = load i8*, i8** %3
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %21, i8* %22)
br label %39
24: ; preds = %15
%25 = load i8*, i8** %3
%26 = call i64 @stringEndsIn(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%30 = load i8*, i8** %6
%31 = load i8*, i8** %3
%32 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* %30, i8* %31)
br label %38
33: ; preds = %24
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%35 = load i8*, i8** %6
%36 = load i8*, i8** %3
%37 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %35, i8* %36)
br label %38
38: ; preds = %33, %28
br label %39
39: ; preds = %38, %19
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%41 = call i32* @openPipe(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
ret i32* %41
}

LLVM IR (-O2):
@.str = [3 x i8] c">>\00"
@.str.1 = [2 x i8] c">\00"
@.str.2 = [5 x i8] c".bz2\00"
@.str.3 = [4 x i8] c".bz\00"
@.str.4 = [11 x i8] c"%s %s \22%s\22\00"
@.str.5 = [9 x i8] c"bzip2 -1\00"
@.str.6 = [3 x i8] c".Z\00"
@.str.7 = [9 x i8] c"compress\00"
@.str.8 = [8 x i8] c"gzip -1\00"
@.str.9 = [2 x i8] c"w\00"
define i32* @writeZippedFile(i8* %0, i8 signext %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @stringEndsIn(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = tail call i64 @stringEndsIn(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i64 @stringEndsIn(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0)
br label %14
14: ; preds = %10, %2, %7
%15 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), %7 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), %2 ], [ %13, %10 ]
%16 = icmp eq i8 %1, 0
%17 = select i1 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
%18 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %15, i8* %17, i8* %0)
%19 = call i32* @openPipe(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
ret i32* %19
}