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

/* Variables and functions */
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int check_format(FILE *bmp_file) {
  size_t count;
  char bftype[10];
  count = fread(bftype, 1, 10, bmp_file);
  printf("[NOTIFY] file initial bytes: {");
  {
    unsigned i = 0;
    for (; i < count; ++i) {
      printf("%c", bftype[i]);
    }
    putchar('\b');
  }
  printf("}\n");
  if ((bftype[0] != 'B') && (bftype[1] != 'M')) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<check_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0xa,%edx
call   1040 <fread@plt>
mov    %rax,-0x18(%rbp)
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    119d <check_format+0x6d>
mov    -0x28(%rbp),%eax
movsbl -0x22(%rbp,%rax,1),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    116c <check_format+0x3c>
mov    $0x8,%edi
call   1030 <putchar@plt>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl -0x22(%rbp),%eax
cmp    $0x42,%eax
je     11db <check_format+0xab>
movsbl -0x21(%rbp),%eax
cmp    $0x4d,%eax
je     11db <check_format+0xab>
movl   $0x1,-0x4(%rbp)
jmp    11e2 <check_format+0xb2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_format>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rcx
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1050 <fread@plt>
mov    %rax,%r14
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r14,%r14
je     1192 <check_format+0x52>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl 0xe(%rsp,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    %rbx,%r14
ja     1180 <check_format+0x40>
mov    $0x8,%edi
call   1030 <putchar@plt>
lea    0xe7c(%rip),%rdi
call   1040 <puts@plt>
cmpb   $0x42,0xe(%rsp)
setne  %al
cmpb   $0x4d,0xf(%rsp)
setne  %cl
and    %al,%cl
movzbl %cl,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [31 x i8] c"[NOTIFY] file initial bytes: {\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [3 x i8] c"}\0A\00"
define i32 @check_format(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i64
%5 = alloca [10 x i8]
%6 = alloca i32
store i32* %0, i32** %3
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%8 = load i32*, i32** %3
%9 = call i64 @fread(i8* %7, i32 1, i32 10, i32* %8)
store i64 %9, i64* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %11
11: ; preds = %23, %1
%12 = load i32, i32* %6
%13 = zext i32 %12 to i64
%14 = load i64, i64* %4
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = load i32, i32* %6
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %16
%24 = load i32, i32* %6
%25 = add i32 %24, 1
store i32 %25, i32* %6
br label %11
26: ; preds = %11
%27 = call i32 @putchar(i8 signext 8)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 66
br i1 %32, label %33, label %39
33: ; preds = %26
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 1
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 77
br i1 %37, label %38, label %39
38: ; preds = %33
store i32 1, i32* %2
br label %40
39: ; preds = %33, %26
store i32 0, i32* %2
br label %40
40: ; preds = %39, %38
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@.str = [31 x i8] c"[NOTIFY] file initial bytes: {\00"
@str = [2 x i8] c"}\00"
define i32 @check_format(i32* nocapture %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = call i64 @fread(i8* %3, i32 1, i32 10, i32* %0)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %4, 0
br i1 %6, label %16, label %7
7: ; preds = %1, %7
%8 = phi i64 [ %14, %7 ], [ 0, %1 ]
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 %11)
%13 = add nuw nsw i64 %8, 1
%14 = and i64 %13, 4294967295
%15 = icmp ugt i64 %4, %14
br i1 %15, label %7, label %16
16: ; preds = %7, %1
%17 = tail call i32 @putchar(i8 signext 8)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%19 = load i8, i8* %3
%20 = icmp ne i8 %19, 66
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 1
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 77
%24 = select i1 %20, i1 %23, i1 false
%25 = zext i1 %24 to i32
ret i32 %25
}