#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*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int lsb_to_int(unsigned char *);
scalar_t__ malloc(int);
unsigned char *read_dib_header(FILE *fp) {
  unsigned char dib_header_size[4];
  fread(dib_header_size, 1, 4, fp);
  int dib_header_size_as_int = lsb_to_int(dib_header_size) - 4;
  unsigned char *dib_header;
  dib_header =
      (unsigned char *)malloc(dib_header_size_as_int * sizeof(unsigned char));
  fread(dib_header, 1, dib_header_size_as_int, fp);
  return dib_header;
}


x86 assembly (clang, -O0):
<read_dib_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
lea    -0xc(%rbp),%rdi
call   1040 <lsb_to_int@plt>
sub    $0x4,%eax
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_dib_header>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
call   1040 <lsb_to_int@plt>
lea    -0x4(%rax),%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @read_dib_header(i32* %0) {
%2 = alloca i32*
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = alloca i8*
store i32* %0, i32** %2
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%7 = load i32*, i32** %2
%8 = call i32 @fread(i8* %6, i32 1, i32 4, i32* %7)
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%10 = call i32 @lsb_to_int(i8* %9)
%11 = sub nsw i32 %10, 4
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = load i32, i32* %4
%20 = load i32*, i32** %2
%21 = call i32 @fread(i8* %18, i32 1, i32 %19, i32* %20)
%22 = load i8*, i8** %5
ret i8* %22
}

LLVM IR (-O2):
define i8* @read_dib_header(i32* nocapture %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = call i32 @fread(i8* %3, i32 1, i32 4, i32* %0)
%5 = call i32 @lsb_to_int(i8* %3)
%6 = add nsw i32 %5, -4
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = call i32 @fread(i8* %8, i32 1, i32 %6, i32* %0)
ret i8* %8
}