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

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void readBMPdumpBMP(char *filename) {
  uint8_t col_cnt = 0;
  FILE *fp = fopen(filename, "r");
  if (fp == NULL) {
    printf("\n*** File open failed !!! ***\n");
    return;
  }
  while (1) {
    uint8_t byte_read = 0;
    if (!fread((void *)&byte_read, 1, 1, fp))
      break;
    printf("0x%02X, ", byte_read);
    col_cnt++;
    if ((col_cnt % 32) == 0)
      printf("\n");
  }
}


x86 assembly (clang, -O0):
<readBMPdumpBMP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1175 <readBMPdumpBMP+0x45>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e4 <readBMPdumpBMP+0xb4>
jmp    117a <readBMPdumpBMP+0x4a>
movl   $0x0,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%eax
jne    11a3 <readBMPdumpBMP+0x73>
jmp    11e4 <readBMPdumpBMP+0xb4>
mov    -0x1c(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11df <readBMPdumpBMP+0xaf>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    117a <readBMPdumpBMP+0x4a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readBMPdumpBMP>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ff <readBMPdumpBMP+0xaf>
mov    %rax,%rbx
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
test   %eax,%eax
je     11f4 <readBMPdumpBMP+0xa4>
lea    0xe64(%rip),%r14
lea    0x4(%rsp),%r15
jmp    11d4 <readBMPdumpBMP+0x84>
cs nopw 0x0(%rax,%rax,1)
nop
movl   $0x0,0x4(%rsp)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
add    $0x1,%ebp
test   %eax,%eax
je     11f4 <readBMPdumpBMP+0xa4>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   $0x1f,%bpl
jne    11b0 <readBMPdumpBMP+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11b0 <readBMPdumpBMP+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe05(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"\0A*** File open failed !!! ***\0A\00"
@.str.2 = [9 x i8] c"0x%02X, \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @readBMPdumpBMP(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %30
12: ; preds = %1
br label %13
13: ; preds = %12, %29
store i32 0, i32* %5
%14 = bitcast i32* %5 to i8*
%15 = load i32*, i32** %4
%16 = call i32 @fread(i8* %14, i32 1, i32 1, i32* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %13
br label %30
19: ; preds = %13
%20 = load i32, i32* %5
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = srem i32 %24, 32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %19
br label %13
30: ; preds = %10, %18
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"0x%02X, \00"
@str = [30 x i8] c"\0A*** File open failed !!! ***\00"
define void @readBMPdumpBMP(i8* nocapture %0) {
%2 = alloca i32
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%7 = call i32 @fread(i8* %6, i32 1, i32 1, i32* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %12
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %24
11: ; preds = %21, %5
br label %24
12: ; preds = %5, %21
%13 = phi i32 [ %16, %21 ], [ 0, %5 ]
%14 = load i32, i32* %2
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = add nuw nsw i32 %13, 1
%17 = and i32 %16, 31
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = tail call i32 @putchar(i32 10)
br label %21
21: ; preds = %12, %19
store i32 0, i32* %2
%22 = call i32 @fread(i8* %6, i32 1, i32 1, i32* %3)
%23 = icmp eq i32 %22, 0
br i1 %23, label %11, label %12
24: ; preds = %11, %9
ret void
}