#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*/ fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
unsigned int get_model_id(const char *filename) {
  unsigned tag = 0x285;
  char exif_cmd[10000];
  snprintf(exif_cmd, sizeof(exif_cmd), "exiftool -CanonModelID -b \"%s\"",
           filename);
  FILE *exif_file = popen(exif_cmd, "r");
  if (exif_file) {
    if (!fscanf(exif_file, "%u", &tag))
      goto err;
    pclose(exif_file);
  } else {
  err:
    printf("**WARNING** could not identify the camera (exiftool problem). "
           "Assuming it's a 5D Mark III\n");
  }
  return tag & 0xFFF;
}


x86 assembly (clang, -O0):
<get_model_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2730,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x285,-0xc(%rbp)
lea    -0x2720(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x2710,%esi
lea    0xe83(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x2720(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x2728(%rbp)
cmpq   $0x0,-0x2728(%rbp)
je     11e0 <get_model_id+0x90>
mov    -0x2728(%rbp),%rdi
lea    0xe69(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <fscanf@plt>
cmp    $0x0,%eax
jne    11cf <get_model_id+0x7f>
jmp    11e5 <get_model_id+0x95>
mov    -0x2728(%rbp),%rdi
call   1040 <pclose@plt>
jmp    11f1 <get_model_id+0xa1>
jmp    11e5 <get_model_id+0x95>
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
and    $0xfff,%eax
add    $0x2730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_model_id>:
push   %rbx
sub    $0x2720,%rsp
mov    %rdi,%rcx
movl   $0x285,0xc(%rsp)
lea    0xe96(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2710,%esi
call   1050 <snprintf@plt>
lea    0xe9c(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
test   %rax,%rax
je     11b5 <get_model_id+0x65>
mov    %rax,%rbx
lea    0xe87(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
test   %eax,%eax
je     11b5 <get_model_id+0x65>
mov    %rbx,%rdi
call   1040 <pclose@plt>
jmp    11c1 <get_model_id+0x71>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfff,%eax
and    0xc(%rsp),%eax
add    $0x2720,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"exiftool -CanonModelID -b \22%s\22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [91 x i8] c"**WARNING** could not identify the camera (exiftool problem). Assuming it's a 5D Mark III\0A\00"
define i32 @get_model_id(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [10000 x i8]
%5 = alloca i32*
store i8* %0, i8** %2
store i32 645, i32* %3
%6 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @snprintf(i8* %6, i32 10000, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%10 = call i32* @popen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %21
13: ; preds = %1
%14 = load i32*, i32** %5
%15 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %13
br label %22
18: ; preds = %13
%19 = load i32*, i32** %5
%20 = call i32 @pclose(i32* %19)
br label %24
21: ; preds = %1
br label %22
22: ; preds = %21, %17
%23 = call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = load i32, i32* %3
%26 = and i32 %25, 4095
ret i32 %26
}

LLVM IR (-O2):
@.str = [31 x i8] c"exiftool -CanonModelID -b \22%s\22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%u\00"
@str = [90 x i8] c"**WARNING** could not identify the camera (exiftool problem). Assuming it's a 5D Mark III\00"
define i32 @get_model_id(i8* %0) {
%2 = alloca i32
%3 = alloca [10000 x i8]
%4 = bitcast i32* %2 to i8*
store i32 645, i32* %2
%5 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%6 = call i32 @snprintf(i8* %5, i32 10000, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @pclose(i32* %7)
br label %16
14: ; preds = %1, %9
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
%17 = load i32, i32* %2
%18 = and i32 %17, 4095
ret i32 %18
}