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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char const *, char const *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int verify_raw_embedding(const char *dng_file, const char *raw_file) {
  int ans = 0;
  FILE *fr = 0, *fd = 0;
  char *bufr = 0, *bufd = 0;
  fr = fopen(raw_file, "rb");
  if (!fr)
    goto end;
  char exif_cmd[1000];
  snprintf(exif_cmd, sizeof(exif_cmd),
           "exiftool \"%s\" -OriginalRawFileData -b", dng_file);
  fd = popen(exif_cmd, "r");
  if (!fd)
    goto end;
  bufr = malloc(1024 * 1024);
  if (!bufr)
    goto end;
  bufd = malloc(1024 * 1024);
  if (!bufd)
    goto end;
  int total = 0;
  while (1) {
    int a = fread(bufr, 1, 1024 * 1024, fr);
    int b = fread(bufd, 1, 1024 * 1024, fd);
    if (a != b) {
      break;
    }
    if (memcmp(bufr, bufd, a)) {
      break;
    }
    if (a <= 0 && total > 0) {
      printf("%-16s: verified %s (%d bytes)\n", dng_file, raw_file, total);
      ans = 1;
      break;
    }
    total += a;
  }
end:
  if (fr)
    fclose(fr);
  if (fd)
    fclose(fd);
  if (bufr)
    free(bufr);
  if (bufd)
    free(bufd);
  return ans;
}


x86 assembly (clang, -O0):
<verify_raw_embedding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ee <verify_raw_embedding+0x5e>
jmp    1346 <verify_raw_embedding+0x1b6>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x3e8,%esi
lea    0xdfe(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1231 <verify_raw_embedding+0xa1>
jmp    1346 <verify_raw_embedding+0x1b6>
mov    $0x100000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    124f <verify_raw_embedding+0xbf>
jmp    1346 <verify_raw_embedding+0x1b6>
mov    $0x100000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    126d <verify_raw_embedding+0xdd>
jmp    1346 <verify_raw_embedding+0x1b6>
movl   $0x0,-0x424(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100000,%edx
call   1040 <fread@plt>
mov    %eax,-0x428(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100000,%edx
call   1040 <fread@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x428(%rbp),%eax
cmp    -0x42c(%rbp),%eax
je     12c8 <verify_raw_embedding+0x138>
jmp    1341 <verify_raw_embedding+0x1b1>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x428(%rbp),%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
je     12ea <verify_raw_embedding+0x15a>
jmp    1341 <verify_raw_embedding+0x1b1>
cmpl   $0x0,-0x428(%rbp)
jg     132a <verify_raw_embedding+0x19a>
cmpl   $0x0,-0x424(%rbp)
jle    132a <verify_raw_embedding+0x19a>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x424(%rbp),%ecx
lea    0xd12(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    1341 <verify_raw_embedding+0x1b1>
mov    -0x428(%rbp),%eax
add    -0x424(%rbp),%eax
mov    %eax,-0x424(%rbp)
jmp    1277 <verify_raw_embedding+0xe7>
jmp    1346 <verify_raw_embedding+0x1b6>
cmpq   $0x0,-0x20(%rbp)
je     135a <verify_raw_embedding+0x1ca>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
je     136e <verify_raw_embedding+0x1de>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x30(%rbp)
je     1382 <verify_raw_embedding+0x1f2>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x38(%rbp)
je     1396 <verify_raw_embedding+0x206>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_raw_embedding>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %rsi,%rbx
mov    %rdi,%r13
lea    0xe52(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1333 <verify_raw_embedding+0x1a3>
mov    %rax,%r12
lea    0xe37(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %r13,%rcx
call   1070 <snprintf@plt>
lea    0xe41(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <popen@plt>
test   %rax,%rax
je     12fc <verify_raw_embedding+0x16c>
mov    %rax,%rbp
mov    $0x100000,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
xor    %r14d,%r14d
test   %rax,%rax
je     12f4 <verify_raw_embedding+0x164>
mov    %r13,(%rsp)
mov    %rbx,0x8(%rsp)
mov    $0x100000,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     12f4 <verify_raw_embedding+0x164>
mov    %rax,%r13
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %eax,%r14d
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
mov    %rbp,%rbx
mov    %rbp,%rcx
call   1040 <fread@plt>
cmp    %eax,%r14d
jne    1306 <verify_raw_embedding+0x176>
xor    %ebp,%ebp
jmp    12b9 <verify_raw_embedding+0x129>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %r14d,%ebp
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %eax,%r14d
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    %eax,%r14d
jne    1348 <verify_raw_embedding+0x1b8>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   1080 <memcmp@plt>
test   %rax,%rax
jne    1348 <verify_raw_embedding+0x1b8>
test   %r14d,%r14d
jg     1280 <verify_raw_embedding+0xf0>
test   %ebp,%ebp
jle    1280 <verify_raw_embedding+0xf0>
lea    0xd4f(%rip),%rdi
mov    (%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    %ebp,%ecx
call   1060 <printf@plt>
mov    $0x1,%r14d
jmp    134b <verify_raw_embedding+0x1bb>
xor    %r13d,%r13d
mov    %rbp,%rbx
jmp    1309 <verify_raw_embedding+0x179>
mov    %r12,%rdi
call   1050 <fclose@plt>
jmp    1333 <verify_raw_embedding+0x1a3>
xor    %r14d,%r14d
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %r15,%r15
je     1326 <verify_raw_embedding+0x196>
mov    %r15,%rdi
call   1030 <free@plt>
test   %r13,%r13
je     1333 <verify_raw_embedding+0x1a3>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
mov    %r12,%rdi
call   1050 <fclose@plt>
test   %rbx,%rbx
jne    1311 <verify_raw_embedding+0x181>
jmp    1319 <verify_raw_embedding+0x189>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [38 x i8] c"exiftool \22%s\22 -OriginalRawFileData -b\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [31 x i8] c"%-16s: verified %s (%d bytes)\0A\00"
define i32 @verify_raw_embedding(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [1000 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32* null, i32** %6
store i32* null, i32** %7
store i8* null, i8** %8
store i8* null, i8** %9
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %2
br label %73
19: ; preds = %2
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = call i32 @snprintf(i8* %20, i32 1000, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%24 = call i32* @popen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %7
%25 = load i32*, i32** %7
%26 = icmp ne i32* %25, null
br i1 %26, label %28, label %27
27: ; preds = %19
br label %73
28: ; preds = %19
%29 = call i8* @malloc(i32 1048576)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = icmp ne i8* %30, null
br i1 %31, label %33, label %32
32: ; preds = %28
br label %73
33: ; preds = %28
%34 = call i8* @malloc(i32 1048576)
store i8* %34, i8** %9
%35 = load i8*, i8** %9
%36 = icmp ne i8* %35, null
br i1 %36, label %38, label %37
37: ; preds = %33
br label %73
38: ; preds = %33
store i32 0, i32* %11
br label %39
39: ; preds = %38, %68
%40 = load i8*, i8** %8
%41 = load i32*, i32** %6
%42 = call i32 @fread(i8* %40, i32 1, i32 1048576, i32* %41)
store i32 %42, i32* %12
%43 = load i8*, i8** %9
%44 = load i32*, i32** %7
%45 = call i32 @fread(i8* %43, i32 1, i32 1048576, i32* %44)
store i32 %45, i32* %13
%46 = load i32, i32* %12
%47 = load i32, i32* %13
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %50
49: ; preds = %39
br label %72
50: ; preds = %39
%51 = load i8*, i8** %8
%52 = load i8*, i8** %9
%53 = load i32, i32* %12
%54 = call i64 @memcmp(i8* %51, i8* %52, i32 %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %50
br label %72
57: ; preds = %50
%58 = load i32, i32* %12
%59 = icmp sle i32 %58, 0
br i1 %59, label %60, label %68
60: ; preds = %57
%61 = load i32, i32* %11
%62 = icmp sgt i32 %61, 0
br i1 %62, label %63, label %68
63: ; preds = %60
%64 = load i8*, i8** %3
%65 = load i8*, i8** %4
%66 = load i32, i32* %11
%67 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %64, i8* %65, i32 %66)
store i32 1, i32* %5
br label %72
68: ; preds = %60, %57
%69 = load i32, i32* %12
%70 = load i32, i32* %11
%71 = add nsw i32 %70, %69
store i32 %71, i32* %11
br label %39
72: ; preds = %63, %56, %49
br label %73
73: ; preds = %72, %37, %32, %27, %18
%74 = load i32*, i32** %6
%75 = icmp ne i32* %74, null
br i1 %75, label %76, label %79
76: ; preds = %73
%77 = load i32*, i32** %6
%78 = call i32 @fclose(i32* %77)
br label %79
79: ; preds = %76, %73
%80 = load i32*, i32** %7
%81 = icmp ne i32* %80, null
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = load i32*, i32** %7
%84 = call i32 @fclose(i32* %83)
br label %85
85: ; preds = %82, %79
%86 = load i8*, i8** %8
%87 = icmp ne i8* %86, null
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = load i8*, i8** %8
%90 = call i32 @free(i8* %89)
br label %91
91: ; preds = %88, %85
%92 = load i8*, i8** %9
%93 = icmp ne i8* %92, null
br i1 %93, label %94, label %97
94: ; preds = %91
%95 = load i8*, i8** %9
%96 = call i32 @free(i8* %95)
br label %97
97: ; preds = %94, %91
%98 = load i32, i32* %5
ret i32 %98
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [38 x i8] c"exiftool \22%s\22 -OriginalRawFileData -b\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [31 x i8] c"%-16s: verified %s (%d bytes)\0A\00"
define i32 @verify_raw_embedding(i8* %0, i8* %1) {
%3 = alloca [1000 x i8]
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %59, label %6
6: ; preds = %2
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%8 = call i32 @snprintf(i8* %7, i32 1000, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = call i32* @popen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 @fclose(i32* %4)
br label %59
13: ; preds = %6
%14 = call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%15 = icmp eq i8* %14, null
br i1 %15, label %39, label %16
16: ; preds = %13
%17 = call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%18 = icmp eq i8* %17, null
br i1 %18, label %39, label %19
19: ; preds = %16
%20 = call i32 @fread(i8* %14, i32 1, i32 1048576, i32* %4)
%21 = call i32 @fread(i8* %17, i32 1, i32 1048576, i32* %9)
%22 = icmp eq i32 %20, %21
br i1 %22, label %28, label %39
23: ; preds = %33
%24 = add nsw i32 %29, %30
%25 = call i32 @fread(i8* %14, i32 1, i32 1048576, i32* %4)
%26 = call i32 @fread(i8* %17, i32 1, i32 1048576, i32* %9)
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %42
28: ; preds = %19, %23
%29 = phi i32 [ %25, %23 ], [ %20, %19 ]
%30 = phi i32 [ %24, %23 ], [ 0, %19 ]
%31 = call i64 @memcmp(i8* %14, i8* %17, i32 %29)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %28
%34 = icmp slt i32 %29, 1
%35 = icmp sgt i32 %30, 0
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %37, label %23
37: ; preds = %33
%38 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1, i32 %30)
br label %42
39: ; preds = %16, %13, %19
%40 = phi i8* [ %17, %19 ], [ null, %13 ], [ null, %16 ]
%41 = call i32 @fclose(i32* %4)
br label %45
42: ; preds = %28, %23, %37
%43 = phi i32 [ 1, %37 ], [ 0, %23 ], [ 0, %28 ]
%44 = call i32 @fclose(i32* %4)
br i1 %10, label %49, label %45
45: ; preds = %39, %42
%46 = phi i8* [ %40, %39 ], [ %17, %42 ]
%47 = phi i32 [ 0, %39 ], [ %43, %42 ]
%48 = call i32 @fclose(i32* %9)
br label %49
49: ; preds = %45, %42
%50 = phi i8* [ %46, %45 ], [ %17, %42 ]
%51 = phi i32 [ %47, %45 ], [ %43, %42 ]
%52 = icmp eq i8* %14, null
br i1 %52, label %55, label %53
53: ; preds = %49
%54 = call i32 @free(i8* %14)
br label %55
55: ; preds = %53, %49
%56 = icmp eq i8* %50, null
br i1 %56, label %59, label %57
57: ; preds = %55
%58 = call i32 @free(i8* %50)
br label %59
59: ; preds = %11, %2, %57, %55
%60 = phi i32 [ %51, %57 ], [ %51, %55 ], [ 0, %2 ], [ 0, %11 ]
ret i32 %60
}