#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 */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(long *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
main() {
  FILE *f;
  long width;
  long heigth;
  if ((f = fopen("image.bmp", "rb")) == NULL) {
    printf("open read file error.\n");
    exit(1);
  }
  fseek(f, 18, SEEK_CUR);
  fread(&width, sizeof(long), 1, f);
  fread(&heigth, sizeof(long), 1, f);
  printf("Heigth: %d , width: %d \n", heigth, width);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a8 <main+0x48>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    $0x12,%esi
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x10(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe84(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f9 <main+0x89>
mov    %rax,%rbx
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x12,%esi
call   1070 <fseek@plt>
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rsp,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    (%rsp),%rsi
mov    0x8(%rsp),%rdx
lea    0xe2b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe26(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"image.bmp\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [23 x i8] c"open read file error.\0A\00"
@SEEK_CUR = global i32 0
@.str.3 = [25 x i8] c"Heigth: %d , width: %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = load i32, i32* @SEEK_CUR
%13 = call i32 @fseek(i32* %11, i32 18, i32 %12)
%14 = load i32*, i32** %2
%15 = call i32 @fread(i64* %3, i32 8, i32 1, i32* %14)
%16 = load i32*, i32** %2
%17 = call i32 @fread(i64* %4, i32 8, i32 1, i32* %16)
%18 = load i64, i64* %4
%19 = load i64, i64* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i64 %18, i64 %19)
%21 = load i32*, i32** %2
%22 = call i32 @fclose(i32* %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"image.bmp\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_CUR = global i32 0
@.str.3 = [25 x i8] c"Heigth: %d , width: %d \0A\00"
@str = [22 x i8] c"open read file error.\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
%4 = bitcast i64* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @SEEK_CUR
%12 = tail call i32 @fseek(i32* %5, i32 18, i32 %11)
%13 = call i32 @fread(i64* %1, i32 8, i32 1, i32* %5)
%14 = call i32 @fread(i64* %2, i32 8, i32 1, i32* %5)
%15 = load i64, i64* %2
%16 = load i64, i64* %1
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i64 %15, i64 %16)
%18 = tail call i32 @fclose(i32* %5)
ret i32 0
}