#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*/ tmp;
typedef int /*<<< orphan*/ compress_cmd;

/* Variables and functions */
char *find_adobe_dng_converter();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rename(char const *, char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
int system(char *);
int /*<<< orphan*/ unlink(char *);
void dng_compress(const char *source, int lossy) {
  const char *adobe_dng = find_adobe_dng_converter();
  if (adobe_dng) {
    printf("Found %s\n", adobe_dng);
  } else {
    printf("Adobe DNG Converter not found.\n");
    return;
  }
  printf("Compressing %s...\n", source);
  char tmp[1000];
  snprintf(tmp, sizeof(tmp), "%s.DNG", source);
  rename(source, tmp);
  char compress_cmd[1000];
  char *start = "";
  snprintf(compress_cmd, sizeof(compress_cmd),
           "%s\"%s\" -dng1.4 %s -o \"%s\" \"%s\"", start, adobe_dng,
           lossy ? "-lossy" : "", source, tmp);
  printf("%s\n", compress_cmd);
  int r = system(compress_cmd);
  if (r != 0) {
    printf("Adobe DNG Converter returned error(%d).\n", r);
    rename(tmp, source);
  } else {
    unlink(tmp);
  }
}


x86 assembly (clang, -O0):
<dng_compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1080 <find_adobe_dng_converter@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119f <dng_compress+0x3f>
mov    -0x18(%rbp),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11b2 <dng_compress+0x52>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ba <dng_compress+0x15a>
mov    -0x8(%rbp),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x3e8,%esi
lea    0xe62(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1070 <rename@plt>
lea    0xe99(%rip),%rax
mov    %rax,-0x7f8(%rbp)
lea    -0x7f0(%rbp),%rdi
mov    -0x7f8(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0xc(%rbp),%edx
lea    0xe76(%rip),%r9
lea    0xe40(%rip),%rax
cmp    $0x0,%edx
cmovne %rax,%r9
mov    -0x8(%rbp),%r10
lea    -0x400(%rbp),%rax
mov    $0x3e8,%esi
lea    0xe03(%rip),%rdx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x7f0(%rbp),%rsi
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x7f0(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x7fc(%rbp)
cmpl   $0x0,-0x7fc(%rbp)
je     12ae <dng_compress+0x14e>
mov    -0x7fc(%rbp),%esi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <rename@plt>
jmp    12ba <dng_compress+0x15a>
lea    -0x400(%rbp),%rdi
call   1030 <unlink@plt>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dng_compress>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x7e0,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
xor    %eax,%eax
call   1090 <find_adobe_dng_converter@plt>
test   %rax,%rax
je     1250 <dng_compress+0xe0>
mov    %rax,%rbx
lea    0xe61(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe5c(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x3e8,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <rename@plt>
test   %r15d,%r15d
lea    0xe87(%rip),%rcx
lea    0xe51(%rip),%r9
cmove  %rcx,%r9
lea    0xe27(%rip),%rdx
lea    0x3f0(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %rbx,%r8
xor    %eax,%eax
push   %r12
push   %r14
call   1070 <snprintf@plt>
add    $0x10,%rsp
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1050 <system@plt>
test   %eax,%eax
je     126b <dng_compress+0xfb>
lea    0xe10(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1080 <rename@plt>
jmp    1273 <dng_compress+0x103>
lea    0xe1c(%rip),%rdi
add    $0x7e0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
mov    %rsp,%rdi
call   1030 <unlink@plt>
add    $0x7e0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Found %s\0A\00"
@.str.1 = [32 x i8] c"Adobe DNG Converter not found.\0A\00"
@.str.2 = [19 x i8] c"Compressing %s...\0A\00"
@.str.3 = [7 x i8] c"%s.DNG\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [31 x i8] c"%s\22%s\22 -dng1.4 %s -o \22%s\22 \22%s\22\00"
@.str.6 = [7 x i8] c"-lossy\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@.str.8 = [41 x i8] c"Adobe DNG Converter returned error(%d).\0A\00"
define void @dng_compress(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [1000 x i8]
%7 = alloca [1000 x i8]
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = call i8* (...) @find_adobe_dng_converter()
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %52
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %21, i32 1000, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %3
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%26 = call i32 @rename(i8* %24, i8* %25)
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8** %8
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%28 = load i8*, i8** %8
%29 = load i8*, i8** %5
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)
%34 = load i8*, i8** %3
%35 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%36 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %27, i32 1000, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %28, i8* %29, i8* %33, i8* %34, i8* %35)
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%40 = call i32 @system(i8* %39)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %18
%44 = load i32, i32* %9
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%47 = load i8*, i8** %3
%48 = call i32 @rename(i8* %46, i8* %47)
br label %52
49: ; preds = %18
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%51 = call i32 @unlink(i8* %50)
br label %52
52: ; preds = %16, %49, %43
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"Found %s\0A\00"
@.str.2 = [19 x i8] c"Compressing %s...\0A\00"
@.str.3 = [7 x i8] c"%s.DNG\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [31 x i8] c"%s\22%s\22 -dng1.4 %s -o \22%s\22 \22%s\22\00"
@.str.6 = [7 x i8] c"-lossy\00"
@.str.8 = [41 x i8] c"Adobe DNG Converter returned error(%d).\0A\00"
@str = [31 x i8] c"Adobe DNG Converter not found.\00"
define void @dng_compress(i8* %0, i32 %1) {
%3 = alloca [1000 x i8]
%4 = alloca [1000 x i8]
%5 = tail call i8* (...) @find_adobe_dng_converter()
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %5)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%11 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 1000, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%12 = call i32 @rename(i8* %0, i8* %10)
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%14 = icmp eq i32 %1, 0
%15 = select i1 %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0)
%16 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %13, i32 1000, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* %15, i8* %0, i8* %10)
%17 = call i32 @puts(i8* %13)
%18 = call i32 @system(i8* %13)
%19 = icmp eq i32 %18, 0
br i1 %19, label %25, label %22
20: ; preds = %2
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %28
22: ; preds = %7
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), i32 %18)
%24 = call i32 @rename(i8* %10, i8* %0)
br label %27
25: ; preds = %7
%26 = call i32 @unlink(i8* %10)
br label %27
27: ; preds = %25, %22
br label %28
28: ; preds = %27, %20
ret void
}