#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 */
struct ccd_frame {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ asprintf(char **, char *, char *, char *);
int /*<<< orphan*/ fits_filename(char *, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ system(char *);
int write_fits_frame(struct ccd_frame *, char *);
int write_gz_fits_frame(struct ccd_frame *fr, char *fn, char *gzcmd) {
  char *text;
  char lb[1024];
  int ret;
  if (gzcmd == NULL)
    return write_fits_frame(fr, fn);
  strncpy(lb, fn, 1024);
  fits_filename(lb, 1024);
  ret = write_fits_frame(fr, lb);
  if (!ret) {
    asprintf(&text, "%s %s", gzcmd, lb);
    system(text);
    free(text);
  }
  return ret;
}


x86 assembly (clang, -O0):
<write_gz_fits_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1197 <write_gz_fits_frame+0x37>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <write_fits_frame@plt>
mov    %eax,-0x4(%rbp)
jmp    1216 <write_gz_fits_frame+0xb6>
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x400,%edx
call   1040 <strncpy@plt>
lea    -0x430(%rbp),%rdi
mov    $0x400,%esi
call   1060 <fits_filename@plt>
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1070 <write_fits_frame@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x0,-0x434(%rbp)
jne    120d <write_gz_fits_frame+0xad>
mov    -0x20(%rbp),%rdx
lea    -0x430(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1080 <asprintf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <system@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x434(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_gz_fits_frame>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rdi,%rbx
test   %rdx,%rdx
je     11e1 <write_gz_fits_frame+0x81>
mov    %rdx,%r14
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x400,%edx
call   1040 <strncpy@plt>
mov    %r15,%rdi
mov    $0x400,%esi
call   1060 <fits_filename@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <write_fits_frame@plt>
test   %eax,%eax
jne    11d4 <write_gz_fits_frame+0x74>
lea    0xe54(%rip),%rsi
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    %r14,%rdx
call   1080 <asprintf@plt>
mov    0x8(%rsp),%rdi
call   1050 <system@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <write_fits_frame@plt>

LLVM IR (-O0):
%struct.ccd_frame = type { i32 }
@.str = [6 x i8] c"%s %s\00"
define i32 @write_gz_fits_frame(%struct.ccd_frame* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.ccd_frame*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [1024 x i8]
%10 = alloca i32
store %struct.ccd_frame* %0, %struct.ccd_frame** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %7
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load %struct.ccd_frame*, %struct.ccd_frame** %5
%15 = load i8*, i8** %6
%16 = call i32 @write_fits_frame(%struct.ccd_frame* %14, i8* %15)
store i32 %16, i32* %4
br label %38
17: ; preds = %3
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%19 = load i8*, i8** %6
%20 = call i32 @strncpy(i8* %18, i8* %19, i32 1024)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%22 = call i32 @fits_filename(i8* %21, i32 1024)
%23 = load %struct.ccd_frame*, %struct.ccd_frame** %5
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%25 = call i32 @write_fits_frame(%struct.ccd_frame* %23, i8* %24)
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = icmp ne i32 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %17
%29 = load i8*, i8** %7
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%31 = call i32 @asprintf(i8** %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %30)
%32 = load i8*, i8** %8
%33 = call i32 @system(i8* %32)
%34 = load i8*, i8** %8
%35 = call i32 @free(i8* %34)
br label %36
36: ; preds = %28, %17
%37 = load i32, i32* %10
store i32 %37, i32* %4
br label %38
38: ; preds = %36, %13
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
%struct.ccd_frame = type { i32 }
@.str = [6 x i8] c"%s %s\00"
define i32 @write_gz_fits_frame(%struct.ccd_frame* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = bitcast i8** %4 to i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = icmp eq i8* %2, null
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @write_fits_frame(%struct.ccd_frame* %0, i8* %1)
br label %22
11: ; preds = %3
%12 = call i32 @strncpy(i8* %7, i8* %1, i32 1024)
%13 = call i32 @fits_filename(i8* %7, i32 1024)
%14 = call i32 @write_fits_frame(%struct.ccd_frame* %0, i8* %7)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %7)
%18 = load i8*, i8** %4
%19 = call i32 @system(i8* %18)
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %11, %16, %9
%23 = phi i32 [ %10, %9 ], [ 0, %16 ], [ %14, %11 ]
ret i32 %23
}