#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*/ json_file;
typedef int /*<<< orphan*/ exif_cmd;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char const *);
int snprintf(char *, int, char *, char const *, ...);
int system(char *);
int /*<<< orphan*/ unlink(char *);
void dng_restore_metadata(const char *dng_file) {
  printf("%-16s: restoring metadata\n", dng_file);
  char json_file[1000];
  int len = snprintf(json_file, sizeof(json_file), "%s", dng_file);
  json_file[len - 3] = 'j';
  json_file[len - 2] = 's';
  json_file[len - 1] = 'o';
  json_file[len - 0] = 'n';
  json_file[len + 1] = '\0';
  char exif_cmd[1000];
  snprintf(exif_cmd, sizeof(exif_cmd),
           "exiftool \"-json=%s\" \"%s\" -q -overwrite_original", json_file,
           dng_file);
  int r = system(exif_cmd);
  if (r != 0) {
    printf("%-16s: could not restore metadata\n", dng_file);
    return;
  }
  unlink(json_file);
}


x86 assembly (clang, -O0):
<dng_restore_metadata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea6(%rip),%rdi
call   1050 <printf@plt>
lea    -0x3f0(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x3e8,%esi
lea    0xea5(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    %eax,-0x3f4(%rbp)
mov    -0x3f4(%rbp),%eax
sub    $0x3,%eax
cltq
movb   $0x6a,-0x3f0(%rbp,%rax,1)
6a
mov    -0x3f4(%rbp),%eax
sub    $0x2,%eax
cltq
movb   $0x73,-0x3f0(%rbp,%rax,1)
73
mov    -0x3f4(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x6f,-0x3f0(%rbp,%rax,1)
6f
mov    -0x3f4(%rbp),%eax
sub    $0x0,%eax
cltq
movb   $0x6e,-0x3f0(%rbp,%rax,1)
6e
mov    -0x3f4(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x3f0(%rbp,%rax,1)
lea    -0x7e0(%rbp),%rdi
lea    -0x3f0(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    $0x3e8,%esi
lea    0xe1e(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x7e0(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x7e4(%rbp)
cmpl   $0x0,-0x7e4(%rbp)
je     123b <dng_restore_metadata+0xfb>
mov    -0x8(%rbp),%rsi
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
jmp    1247 <dng_restore_metadata+0x107>
lea    -0x3f0(%rbp),%rdi
call   1030 <unlink@plt>
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dng_restore_metadata>:
push   %r15
push   %r14
push   %rbx
sub    $0x7e0,%rsp
mov    %rdi,%rbx
lea    0xeaa(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xeb6(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x3e8,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
cltq
movl   $0x6e6f736a,-0x3(%rax,%r14,1)
6f 6e
movb   $0x0,0x1(%rax,%r14,1)
lea    0xe8c(%rip),%rdx
lea    0x3f0(%rsp),%r15
mov    %r15,%rdi
mov    $0x3e8,%esi
mov    %r14,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r15,%rdi
call   1040 <system@plt>
test   %eax,%eax
je     11cc <dng_restore_metadata+0x8c>
lea    0xe8c(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    11d4 <dng_restore_metadata+0x94>
mov    %rsp,%rdi
call   1030 <unlink@plt>
add    $0x7e0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"%-16s: restoring metadata\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [48 x i8] c"exiftool \22-json=%s\22 \22%s\22 -q -overwrite_original\00"
@.str.3 = [35 x i8] c"%-16s: could not restore metadata\0A\00"
define void @dng_restore_metadata(i8* %0) {
%2 = alloca i8*
%3 = alloca [1000 x i8]
%4 = alloca i32
%5 = alloca [1000 x i8]
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%10 = load i8*, i8** %2
%11 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %9, i32 1000, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %14
store i8 106, i8* %15
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %18
store i8 115, i8* %19
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %22
store i8 111, i8* %23
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 0
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %26
store i8 110, i8* %27
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %30
store i8 0, i8* %31
%32 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%34 = load i8*, i8** %2
%35 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %32, i32 1000, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %34)
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%37 = call i32 @system(i8* %36)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %1
%41 = load i8*, i8** %2
%42 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %41)
br label %46
43: ; preds = %1
%44 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%45 = call i32 @unlink(i8* %44)
br label %46
46: ; preds = %43, %40
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"%-16s: restoring metadata\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [48 x i8] c"exiftool \22-json=%s\22 \22%s\22 -q -overwrite_original\00"
@.str.3 = [35 x i8] c"%-16s: could not restore metadata\0A\00"
define void @dng_restore_metadata(i8* %0) {
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i8]
%4 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 1000, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = add nsw i32 %6, -3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %8
store i8 106, i8* %9
%10 = add nsw i32 %6, -2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %11
store i8 115, i8* %12
%13 = add nsw i32 %6, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %14
store i8 111, i8* %15
%16 = sext i32 %6 to i64
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %16
store i8 110, i8* %17
%18 = add nsw i32 %6, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %19
store i8 0, i8* %20
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%22 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %21, i32 1000, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %0)
%23 = call i32 @system(i8* %21)
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %1
%26 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %29
27: ; preds = %1
%28 = call i32 @unlink(i8* %5)
br label %29
29: ; preds = %27, %25
ret void
}