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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char const *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *,
                            char const *);
int system(char *);
int /*<<< orphan*/ unlink(char const *);
int /*<<< orphan*/ verify_raw_embedding(char const *, char const *);
void embed_original_raw(const char *dng_file, const char *raw_file,
                        int delete_original) {
  printf("%-16s: %s into %s\n", raw_file,
         delete_original ? "moving" : "copying", dng_file);
  char exif_cmd[1000];
  snprintf(exif_cmd, sizeof(exif_cmd),
           "exiftool \"%s\" \"-OriginalRawFileData<=%s\" "
           "\"-OriginalRawFileName=%s\" -overwrite_original -q",
           dng_file, raw_file, raw_file);
  int r = system(exif_cmd);
  if (r != 0) {
    printf("%-16s: could not embed original raw\n", dng_file);
    return;
  }
  if (!verify_raw_embedding(dng_file, raw_file)) {
    printf("%-16s: verification of %s failed\n", dng_file, raw_file);
    return;
  }
  if (delete_original) {
    unlink(raw_file);
  }
}


x86 assembly (clang, -O0):
<embed_original_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
lea    0xea6(%rip),%rdx
lea    0xe98(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x8(%rbp),%rcx
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x10(%rbp),%r9
mov    $0x3e8,%esi
lea    0xe6f(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x400(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x404(%rbp)
cmpl   $0x0,-0x404(%rbp)
je     11ee <embed_original_raw+0x9e>
mov    -0x8(%rbp),%rsi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1232 <embed_original_raw+0xe2>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <verify_raw_embedding@plt>
cmp    $0x0,%eax
jne    121f <embed_original_raw+0xcf>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1232 <embed_original_raw+0xe2>
cmpl   $0x0,-0x14(%rbp)
je     1232 <embed_original_raw+0xe2>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<embed_original_raw>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3e8,%rsp
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
test   %edx,%edx
lea    0xeab(%rip),%rax
lea    0xe9d(%rip),%rdx
cmove  %rax,%rdx
lea    0xe7f(%rip),%rdi
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe90(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %r14,%rcx
mov    %rbx,%r8
mov    %rbx,%r9
call   1060 <snprintf@plt>
mov    %rbp,%rdi
call   1040 <system@plt>
test   %eax,%eax
je     11d6 <embed_original_raw+0x86>
lea    0xebe(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <verify_raw_embedding@plt>
test   %eax,%eax
je     11f4 <embed_original_raw+0xa4>
test   %r15d,%r15d
je     11c8 <embed_original_raw+0x78>
mov    %rbx,%rdi
call   1030 <unlink@plt>
jmp    11c8 <embed_original_raw+0x78>
lea    0xea6(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c8 <embed_original_raw+0x78>

LLVM IR (-O0):
@.str = [19 x i8] c"%-16s: %s into %s\0A\00"
@.str.1 = [7 x i8] c"moving\00"
@.str.2 = [8 x i8] c"copying\00"
@.str.3 = [90 x i8] c"exiftool \22%s\22 \22-OriginalRawFileData<=%s\22 \22-OriginalRawFileName=%s\22 -overwrite_original -q\00"
@.str.4 = [37 x i8] c"%-16s: could not embed original raw\0A\00"
@.str.5 = [34 x i8] c"%-16s: verification of %s failed\0A\00"
define void @embed_original_raw(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1000 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
%14 = load i8*, i8** %4
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %13, i8* %14)
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = load i8*, i8** %5
%20 = call i32 @snprintf(i8* %16, i32 1000, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %18, i8* %19)
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%22 = call i32 @system(i8* %21)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %3
%26 = load i8*, i8** %4
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %26)
br label %43
28: ; preds = %3
%29 = load i8*, i8** %4
%30 = load i8*, i8** %5
%31 = call i32 @verify_raw_embedding(i8* %29, i8* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %28
%34 = load i8*, i8** %4
%35 = load i8*, i8** %5
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %34, i8* %35)
br label %43
37: ; preds = %28
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i8*, i8** %5
%42 = call i32 @unlink(i8* %41)
br label %43
43: ; preds = %25, %33, %40, %37
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"%-16s: %s into %s\0A\00"
@.str.1 = [7 x i8] c"moving\00"
@.str.2 = [8 x i8] c"copying\00"
@.str.3 = [90 x i8] c"exiftool \22%s\22 \22-OriginalRawFileData<=%s\22 \22-OriginalRawFileName=%s\22 -overwrite_original -q\00"
@.str.4 = [37 x i8] c"%-16s: could not embed original raw\0A\00"
@.str.5 = [34 x i8] c"%-16s: verification of %s failed\0A\00"
define void @embed_original_raw(i8* %0, i8* %1, i32 %2) {
%4 = alloca [1000 x i8]
%5 = icmp eq i32 %2, 0
%6 = select i1 %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0)
%7 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %6, i8* %0)
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%9 = call i32 @snprintf(i8* %8, i32 1000, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1, i8* %1)
%10 = call i32 @system(i8* %8)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %22
14: ; preds = %3
%15 = call i32 @verify_raw_embedding(i8* %0, i8* %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %1)
br label %22
19: ; preds = %14
br i1 %5, label %22, label %20
20: ; preds = %19
%21 = call i32 @unlink(i8* %1)
br label %22
22: ; preds = %19, %20, %17, %12
ret void
}