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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
scalar_t__ strncmp(char *, char *, int);
const char *get_camera_model(const char *filename) {
  static char model[100];
  char exif_cmd[10000];
  snprintf(exif_cmd, sizeof(exif_cmd), "exiftool -Model -b \"%s\"", filename);
  FILE *exif_file = popen(exif_cmd, "r");
  if (exif_file) {
    if (fgets(model, sizeof(model), exif_file) == NULL)
      goto err;
    pclose(exif_file);
  } else {
  err:
    printf("**WARNING** Could not identify the camera from EXIF. Assuming 5D "
           "Mark III.\n");
    return "EOS 5D Mark III";
  }
  if (strncmp(model, "Canon ", 6) == 0) {
    return model + 6;
  }
  return model;
}


x86 assembly (clang, -O0):
<get_camera_model>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2730,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x2720(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x2710,%esi
lea    0xe7a(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x2720(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x2728(%rbp)
cmpq   $0x0,-0x2728(%rbp)
je     11eb <get_camera_model+0x8b>
mov    -0x2728(%rbp),%rdx
lea    0x2e9f(%rip),%rdi
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    11da <get_camera_model+0x7a>
jmp    11f0 <get_camera_model+0x90>
mov    -0x2728(%rbp),%rdi
call   1050 <pclose@plt>
jmp    120c <get_camera_model+0xac>
jmp    11f0 <get_camera_model+0x90>
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
lea    0xe63(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    124d <get_camera_model+0xed>
lea    0x2e4d(%rip),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1242 <get_camera_model+0xe2>
lea    0x2e2b(%rip),%rax
add    $0x6,%rax
mov    %rax,-0x8(%rbp)
jmp    124d <get_camera_model+0xed>
lea    0x2e17(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_camera_model>:
push   %r14
push   %rbx
sub    $0x2718,%rsp
mov    %rdi,%rcx
lea    0xe8c(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2710,%esi
call   1060 <snprintf@plt>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1080 <popen@plt>
test   %rax,%rax
je     11e3 <get_camera_model+0x83>
mov    %rax,%rbx
lea    0x2ebe(%rip),%r14
mov    %r14,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11e3 <get_camera_model+0x83>
mov    %rbx,%rdi
call   1050 <pclose@plt>
lea    0xe64(%rip),%rsi
mov    %r14,%rdi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
lea    0x2e89(%rip),%rax
cmovne %r14,%rax
jmp    11f6 <get_camera_model+0x96>
lea    0xe47(%rip),%rdi
call   1040 <puts@plt>
lea    0xe24(%rip),%rax
add    $0x2718,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@get_camera_model.model = internal global [100 x i8] zeroinitializer
@.str = [24 x i8] c"exiftool -Model -b \22%s\22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [76 x i8] c"**WARNING** Could not identify the camera from EXIF. Assuming 5D Mark III.\0A\00"
@.str.3 = [16 x i8] c"EOS 5D Mark III\00"
@.str.4 = [7 x i8] c"Canon \00"
define i8* @get_camera_model(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [10000 x i8]
%5 = alloca i32*
store i8* %0, i8** %3
%6 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = call i32 @snprintf(i8* %6, i32 10000, i8* getelementptr inbounds ([24 x i8], [24 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* @fgets(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_camera_model.model, i64 0, i64 0), i32 100, i32* %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
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 ([76 x i8], [76 x i8]* @.str.2, i64 0, i64 0))
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %29
24: ; preds = %18
%25 = call i64 @strncmp(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_camera_model.model, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %24
store i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_camera_model.model, i64 0, i64 6), i8** %2
br label %29
28: ; preds = %24
store i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_camera_model.model, i64 0, i64 0), i8** %2
br label %29
29: ; preds = %28, %27, %22
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@get_camera_model.model = internal global [100 x i8] zeroinitializer
@.str = [24 x i8] c"exiftool -Model -b \22%s\22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [16 x i8] c"EOS 5D Mark III\00"
@.str.4 = [7 x i8] c"Canon \00"
@str = [75 x i8] c"**WARNING** Could not identify the camera from EXIF. Assuming 5D Mark III.\00"
define i8* @get_camera_model(i8* %0) {
%2 = alloca [10000 x i8]
%3 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 10000, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = call i32* @fgets(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_camera_model.model, i64 0, i64 0), i32 100, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = call i32 @pclose(i32* %5)
%12 = call i64 @strncmp(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_camera_model.model, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_camera_model.model, i64 0, i64 6), i8* getelementptr inbounds ([100 x i8], [100 x i8]* @get_camera_model.model, i64 0, i64 0)
br label %17
15: ; preds = %1, %7
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %10, %15
%18 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), %15 ], [ %14, %10 ]
ret i8* %18
}