#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*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ write_int16(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ write_int32(int, int /*<<< orphan*/ *);
void write_bmp_header(FILE *fp, int h, int w) {
  int size = 54 + 3 * h * w;
  size += (w % 4) * h;
  fputc(66, fp);
  fputc(77, fp);
  write_int32(size, fp);
  write_int16(0, fp);
  write_int16(0, fp);
  write_int32(54, fp);
  write_int32(40, fp);
  write_int32(w, fp);
  write_int32(h, fp);
  write_int16(1, fp);
  write_int16(24, fp);
  write_int32(0, fp);
  write_int32(size - 54, fp);
  write_int32(2835, fp);
  write_int32(2835, fp);
  write_int32(0, fp);
  write_int32(0, fp);
}


x86 assembly (clang, -O0):
<write_bmp_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
imul   $0x3,-0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
add    $0x36,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
imul   -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0x42,%edi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rsi
mov    $0x4d,%edi
call   1040 <fputc@plt>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <write_int32@plt>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1050 <write_int16@plt>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1050 <write_int16@plt>
mov    -0x8(%rbp),%rsi
mov    $0x36,%edi
call   1030 <write_int32@plt>
mov    -0x8(%rbp),%rsi
mov    $0x28,%edi
call   1030 <write_int32@plt>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <write_int32@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <write_int32@plt>
mov    -0x8(%rbp),%rsi
mov    $0x1,%edi
call   1050 <write_int16@plt>
mov    -0x8(%rbp),%rsi
mov    $0x18,%edi
call   1050 <write_int16@plt>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1030 <write_int32@plt>
mov    -0x14(%rbp),%edi
sub    $0x36,%edi
mov    -0x8(%rbp),%rsi
call   1030 <write_int32@plt>
mov    -0x8(%rbp),%rsi
mov    $0xb13,%edi
call   1030 <write_int32@plt>
mov    -0x8(%rbp),%rsi
mov    $0xb13,%edi
call   1030 <write_int32@plt>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1030 <write_int32@plt>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1030 <write_int32@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_bmp_header>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%rbx
mov    %esi,%eax
imul   %edx,%eax
lea    (%rax,%rax,2),%eax
lea    0x3(%rbp),%ecx
test   %edx,%edx
cmovns %edx,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%edx
imul   %esi,%edx
lea    (%rdx,%rax,1),%r12d
add    $0x36,%r12d
mov    %edx,%r14d
add    %eax,%r14d
mov    $0x42,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    $0x4d,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1030 <write_int32@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <write_int16@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <write_int16@plt>
mov    $0x36,%edi
mov    %rbx,%rsi
call   1030 <write_int32@plt>
mov    $0x28,%edi
mov    %rbx,%rsi
call   1030 <write_int32@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write_int32@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1030 <write_int32@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1050 <write_int16@plt>
mov    $0x18,%edi
mov    %rbx,%rsi
call   1050 <write_int16@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1030 <write_int32@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1030 <write_int32@plt>
mov    $0xb13,%edi
mov    %rbx,%rsi
call   1030 <write_int32@plt>
mov    $0xb13,%edi
mov    %rbx,%rsi
call   1030 <write_int32@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1030 <write_int32@plt>
xor    %edi,%edi
mov    %rbx,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <write_int32@plt>

LLVM IR (-O0):
define void @write_bmp_header(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = mul nsw i32 3, %8
%10 = load i32, i32* %6
%11 = mul nsw i32 %9, %10
%12 = add nsw i32 54, %11
store i32 %12, i32* %7
%13 = load i32, i32* %6
%14 = srem i32 %13, 4
%15 = load i32, i32* %5
%16 = mul nsw i32 %14, %15
%17 = load i32, i32* %7
%18 = add nsw i32 %17, %16
store i32 %18, i32* %7
%19 = load i32*, i32** %4
%20 = call i32 @fputc(i32 66, i32* %19)
%21 = load i32*, i32** %4
%22 = call i32 @fputc(i32 77, i32* %21)
%23 = load i32, i32* %7
%24 = load i32*, i32** %4
%25 = call i32 @write_int32(i32 %23, i32* %24)
%26 = load i32*, i32** %4
%27 = call i32 @write_int16(i32 0, i32* %26)
%28 = load i32*, i32** %4
%29 = call i32 @write_int16(i32 0, i32* %28)
%30 = load i32*, i32** %4
%31 = call i32 @write_int32(i32 54, i32* %30)
%32 = load i32*, i32** %4
%33 = call i32 @write_int32(i32 40, i32* %32)
%34 = load i32, i32* %6
%35 = load i32*, i32** %4
%36 = call i32 @write_int32(i32 %34, i32* %35)
%37 = load i32, i32* %5
%38 = load i32*, i32** %4
%39 = call i32 @write_int32(i32 %37, i32* %38)
%40 = load i32*, i32** %4
%41 = call i32 @write_int16(i32 1, i32* %40)
%42 = load i32*, i32** %4
%43 = call i32 @write_int16(i32 24, i32* %42)
%44 = load i32*, i32** %4
%45 = call i32 @write_int32(i32 0, i32* %44)
%46 = load i32, i32* %7
%47 = sub nsw i32 %46, 54
%48 = load i32*, i32** %4
%49 = call i32 @write_int32(i32 %47, i32* %48)
%50 = load i32*, i32** %4
%51 = call i32 @write_int32(i32 2835, i32* %50)
%52 = load i32*, i32** %4
%53 = call i32 @write_int32(i32 2835, i32* %52)
%54 = load i32*, i32** %4
%55 = call i32 @write_int32(i32 0, i32* %54)
%56 = load i32*, i32** %4
%57 = call i32 @write_int32(i32 0, i32* %56)
ret void
}

LLVM IR (-O2):
define void @write_bmp_header(i32* %0, i32 %1, i32 %2) {
%4 = mul nsw i32 %1, 3
%5 = mul nsw i32 %4, %2
%6 = srem i32 %2, 4
%7 = mul nsw i32 %6, %1
%8 = add i32 %7, %5
%9 = add i32 %8, 54
%10 = tail call i32 @fputc(i32 66, i32* %0)
%11 = tail call i32 @fputc(i32 77, i32* %0)
%12 = tail call i32 @write_int32(i32 %9, i32* %0)
%13 = tail call i32 @write_int16(i32 0, i32* %0)
%14 = tail call i32 @write_int16(i32 0, i32* %0)
%15 = tail call i32 @write_int32(i32 54, i32* %0)
%16 = tail call i32 @write_int32(i32 40, i32* %0)
%17 = tail call i32 @write_int32(i32 %2, i32* %0)
%18 = tail call i32 @write_int32(i32 %1, i32* %0)
%19 = tail call i32 @write_int16(i32 1, i32* %0)
%20 = tail call i32 @write_int16(i32 24, i32* %0)
%21 = tail call i32 @write_int32(i32 0, i32* %0)
%22 = tail call i32 @write_int32(i32 %8, i32* %0)
%23 = tail call i32 @write_int32(i32 2835, i32* %0)
%24 = tail call i32 @write_int32(i32 2835, i32* %0)
%25 = tail call i32 @write_int32(i32 0, i32* %0)
%26 = tail call i32 @write_int32(i32 0, i32* %0)
ret void
}