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

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, unsigned char *, int);
int create_header(char *filename, uint32_t w, uint32_t h, uint8_t *data) {
  uint32_t filesize = 14 + 40 + w * h * 3;
  unsigned char bmpfileheader[14] = {'B', 'M', 0, 0,  0, 0, 0,
                                     0,   0,   0, 54, 0, 0, 0};
  unsigned char bmpinfoheader[40] = {40, 0, 0, 0, 0, 0, 0,  0,
                                     0,  0, 0, 0, 1, 0, 24, 0};
  unsigned char bmppad[3] = {0, 0, 0};
  int index = 0;
  bmpfileheader[2] = (unsigned char)(filesize);
  bmpfileheader[3] = (unsigned char)(filesize >> 8);
  bmpfileheader[4] = (unsigned char)(filesize >> 16);
  bmpfileheader[5] = (unsigned char)(filesize >> 24);
  memcpy(data + index, bmpfileheader, sizeof(bmpfileheader));
  index += sizeof(bmpfileheader);
  bmpinfoheader[4] = (unsigned char)(w);
  bmpinfoheader[5] = (unsigned char)(w >> 8);
  bmpinfoheader[6] = (unsigned char)(w >> 16);
  bmpinfoheader[7] = (unsigned char)(w >> 24);
  bmpinfoheader[8] = (unsigned char)(h);
  bmpinfoheader[9] = (unsigned char)(h >> 8);
  bmpinfoheader[10] = (unsigned char)(h >> 16);
  bmpinfoheader[11] = (unsigned char)(h >> 24);
  memcpy(data + index, bmpinfoheader, sizeof(bmpinfoheader));
  index += sizeof(bmpinfoheader);
  return index;
}


x86 assembly (clang, -O0):
<create_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
imul   $0x3,%eax,%eax
add    $0x36,%eax
mov    %eax,-0x1c(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x2a(%rbp)
mov    0xeb1(%rip),%eax
mov    %eax,-0x22(%rbp)
mov    0xeab(%rip),%ax
mov    %ax,-0x1e(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
movb   $0x28,-0x60(%rbp)
movb   $0x1,-0x54(%rbp)
movb   $0x18,-0x52(%rbp)
lea    -0x63(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <memset@plt>
movl   $0x0,-0x68(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x27(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x10,%eax
mov    %al,-0x26(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x18,%eax
mov    %al,-0x25(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x68(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0x2a(%rbp),%rsi
mov    $0xe,%edx
call   1040 <memcpy@plt>
movslq -0x68(%rbp),%rax
add    $0xe,%rax
mov    %eax,-0x68(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0x5c(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x5b(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x10,%eax
mov    %al,-0x5a(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x18,%eax
mov    %al,-0x59(%rbp)
mov    -0x10(%rbp),%eax
mov    %al,-0x58(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x57(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x10,%eax
mov    %al,-0x56(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x18,%eax
mov    %al,-0x55(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x68(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0x60(%rbp),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
movslq -0x68(%rbp),%rax
add    $0x28,%rax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_header>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rcx,%r14
mov    %edx,%ebp
mov    %esi,%ebx
mov    %esi,%eax
imul   %edx,%eax
lea    (%rax,%rax,2),%eax
add    $0x36,%eax
movabs $0x3600000000,%rcx
mov    %rcx,0x6(%rsp)
movq   $0x4d42,(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x30(%rsp)
movb   $0x28,0x10(%rsp)
movb   $0x1,0x1c(%rsp)
movb   $0x18,0x1e(%rsp)
mov    %al,0x2(%rsp)
mov    %ah,0x3(%rsp)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x4(%rsp)
shr    $0x18,%eax
mov    %al,0x5(%rsp)
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0xe,%edx
call   1030 <memcpy@plt>
mov    %bl,0x14(%rsp)
mov    %bh,0x15(%rsp)
mov    %ebx,%eax
shr    $0x10,%eax
mov    %al,0x16(%rsp)
shr    $0x18,%ebx
mov    %bl,0x17(%rsp)
mov    %ebp,%ecx
mov    %cl,0x18(%rsp)
mov    %ch,0x19(%rsp)
mov    %ebp,%eax
shr    $0x10,%eax
mov    %al,0x1a(%rsp)
shr    $0x18,%ecx
mov    %cl,0x1b(%rsp)
add    $0x38,%r14
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    $0x28,%edx
call   1030 <memcpy@plt>
mov    $0x36,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.create_header.bmpfileheader = [14 x i8] c"BM\00\00\00\00\00\00\00\006\00\00\00"
define i32 @create_header(i8* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca [14 x i8]
%11 = alloca [40 x i8]
%12 = alloca [3 x i8]
%13 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = mul nsw i32 %14, %15
%17 = mul nsw i32 %16, 3
%18 = add nsw i32 54, %17
store i32 %18, i32* %9
%19 = bitcast [14 x i8]* %10 to i8*
%20 = bitcast [40 x i8]* %11 to i8*
%21 = bitcast i8* %20 to <{ [15 x i8], [25 x i8] }>*
%22 = getelementptr inbounds <{ [15 x i8], [25 x i8] }>, <{ [15 x i8], [25 x i8] }>* %21, i32 0, i32 0
%23 = getelementptr inbounds [15 x i8], [15 x i8]* %22, i32 0, i32 0
store i8 40, i8* %23
%24 = getelementptr inbounds [15 x i8], [15 x i8]* %22, i32 0, i32 12
store i8 1, i8* %24
%25 = getelementptr inbounds [15 x i8], [15 x i8]* %22, i32 0, i32 14
store i8 24, i8* %25
%26 = bitcast [3 x i8]* %12 to i8*
store i32 0, i32* %13
%27 = load i32, i32* %9
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds [14 x i8], [14 x i8]* %10, i64 0, i64 2
store i8 %28, i8* %29
%30 = load i32, i32* %9
%31 = ashr i32 %30, 8
%32 = trunc i32 %31 to i8
%33 = getelementptr inbounds [14 x i8], [14 x i8]* %10, i64 0, i64 3
store i8 %32, i8* %33
%34 = load i32, i32* %9
%35 = ashr i32 %34, 16
%36 = trunc i32 %35 to i8
%37 = getelementptr inbounds [14 x i8], [14 x i8]* %10, i64 0, i64 4
store i8 %36, i8* %37
%38 = load i32, i32* %9
%39 = ashr i32 %38, 24
%40 = trunc i32 %39 to i8
%41 = getelementptr inbounds [14 x i8], [14 x i8]* %10, i64 0, i64 5
store i8 %40, i8* %41
%42 = load i32*, i32** %8
%43 = load i32, i32* %13
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = getelementptr inbounds [14 x i8], [14 x i8]* %10, i64 0, i64 0
%47 = call i32 @memcpy(i32* %45, i8* %46, i32 14)
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = add i64 %49, 14
%51 = trunc i64 %50 to i32
store i32 %51, i32* %13
%52 = load i32, i32* %6
%53 = trunc i32 %52 to i8
%54 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 4
store i8 %53, i8* %54
%55 = load i32, i32* %6
%56 = ashr i32 %55, 8
%57 = trunc i32 %56 to i8
%58 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 5
store i8 %57, i8* %58
%59 = load i32, i32* %6
%60 = ashr i32 %59, 16
%61 = trunc i32 %60 to i8
%62 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 6
store i8 %61, i8* %62
%63 = load i32, i32* %6
%64 = ashr i32 %63, 24
%65 = trunc i32 %64 to i8
%66 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 7
store i8 %65, i8* %66
%67 = load i32, i32* %7
%68 = trunc i32 %67 to i8
%69 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 8
store i8 %68, i8* %69
%70 = load i32, i32* %7
%71 = ashr i32 %70, 8
%72 = trunc i32 %71 to i8
%73 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 9
store i8 %72, i8* %73
%74 = load i32, i32* %7
%75 = ashr i32 %74, 16
%76 = trunc i32 %75 to i8
%77 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 10
store i8 %76, i8* %77
%78 = load i32, i32* %7
%79 = ashr i32 %78, 24
%80 = trunc i32 %79 to i8
%81 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 11
store i8 %80, i8* %81
%82 = load i32*, i32** %8
%83 = load i32, i32* %13
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %82, i64 %84
%86 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 0
%87 = call i32 @memcpy(i32* %85, i8* %86, i32 40)
%88 = load i32, i32* %13
%89 = sext i32 %88 to i64
%90 = add i64 %89, 40
%91 = trunc i64 %90 to i32
store i32 %91, i32* %13
%92 = load i32, i32* %13
ret i32 %92
}

LLVM IR (-O2):
@__const.create_header.bmpfileheader = [14 x i8] c"BM\00\00\00\00\00\00\00\006\00\00\00"
define i32 @create_header(i8* nocapture readnone %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca [14 x i8]
%6 = alloca [40 x i8]
%7 = mul i32 %1, 3
%8 = mul i32 %7, %2
%9 = add nsw i32 %8, 54
%10 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
store i8 40, i8* %11
%12 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 12
store i8 1, i8* %12
%13 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 14
store i8 24, i8* %13
%14 = trunc i32 %9 to i8
%15 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 2
store i8 %14, i8* %15
%16 = lshr i32 %9, 8
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 3
store i8 %17, i8* %18
%19 = lshr i32 %9, 16
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 4
store i8 %20, i8* %21
%22 = lshr i32 %9, 24
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 5
store i8 %23, i8* %24
%25 = call i32 @memcpy(i32* %3, i8* %10, i32 14)
%26 = trunc i32 %1 to i8
%27 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 4
store i8 %26, i8* %27
%28 = lshr i32 %1, 8
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 5
store i8 %29, i8* %30
%31 = lshr i32 %1, 16
%32 = trunc i32 %31 to i8
%33 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 6
store i8 %32, i8* %33
%34 = lshr i32 %1, 24
%35 = trunc i32 %34 to i8
%36 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 7
store i8 %35, i8* %36
%37 = trunc i32 %2 to i8
%38 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 8
store i8 %37, i8* %38
%39 = lshr i32 %2, 8
%40 = trunc i32 %39 to i8
%41 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 9
store i8 %40, i8* %41
%42 = lshr i32 %2, 16
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 10
store i8 %43, i8* %44
%45 = lshr i32 %2, 24
%46 = trunc i32 %45 to i8
%47 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 11
store i8 %46, i8* %47
%48 = getelementptr inbounds i32, i32* %3, i64 14
%49 = call i32 @memcpy(i32* %48, i8* %11, i32 40)
ret i32 54
}