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

/* Variables and functions */
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
void write_coff_header(FILE *file, uint16_t machine) {
  char buffer[128];
  memset(buffer, 0, sizeof(buffer));
  buffer[0] = machine & 0xff;
  buffer[1] = machine >> 0x8;
  fwrite(buffer, 2, 1, file);
  memset(buffer, 0, sizeof(buffer));
  fwrite(buffer, 2, 1, file);
  fwrite(buffer, 4, 1, file);
  fwrite(buffer, 4, 1, file);
  fwrite(buffer, 4, 1, file);
  fwrite(buffer, 2, 1, file);
  buffer[0] = 0x00;
  buffer[1] = 0x20;
  fwrite(buffer, 2, 1, file);
  memset(buffer, 0, sizeof(buffer));
}


x86 assembly (clang, -O0):
<write_coff_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x90(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x8f(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
movb   $0x0,-0x90(%rbp)
movb   $0x20,-0x8f(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_coff_header>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
mov    %bp,(%rsp)
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
movw   $0x2000,(%rsp)
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @write_coff_header(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [128 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 128)
%8 = load i32, i32* %4
%9 = and i32 %8, 255
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
store i8 %10, i8* %11
%12 = load i32, i32* %4
%13 = ashr i32 %12, 8
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 1
store i8 %14, i8* %15
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i32 @fwrite(i8* %16, i32 2, i32 1, i32* %17)
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 128)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%22 = load i32*, i32** %3
%23 = call i32 @fwrite(i8* %21, i32 2, i32 1, i32* %22)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%25 = load i32*, i32** %3
%26 = call i32 @fwrite(i8* %24, i32 4, i32 1, i32* %25)
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%28 = load i32*, i32** %3
%29 = call i32 @fwrite(i8* %27, i32 4, i32 1, i32* %28)
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%31 = load i32*, i32** %3
%32 = call i32 @fwrite(i8* %30, i32 4, i32 1, i32* %31)
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%34 = load i32*, i32** %3
%35 = call i32 @fwrite(i8* %33, i32 2, i32 1, i32* %34)
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
store i8 0, i8* %36
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 1
store i8 32, i8* %37
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%39 = load i32*, i32** %3
%40 = call i32 @fwrite(i8* %38, i32 2, i32 1, i32* %39)
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 0, i32 128)
ret void
}

LLVM IR (-O2):
define void @write_coff_header(i32* nocapture %0, i32 %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 128)
%6 = trunc i32 %1 to i8
store i8 %6, i8* %4
%7 = lshr i32 %1, 8
%8 = trunc i32 %7 to i8
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 1
store i8 %8, i8* %9
%10 = call i32 @fwrite(i8* %4, i32 2, i32 1, i32* %0)
%11 = call i32 @memset(i8* %4, i32 0, i32 128)
%12 = call i32 @fwrite(i8* %4, i32 2, i32 1, i32* %0)
%13 = call i32 @fwrite(i8* %4, i32 4, i32 1, i32* %0)
%14 = call i32 @fwrite(i8* %4, i32 4, i32 1, i32* %0)
%15 = call i32 @fwrite(i8* %4, i32 4, i32 1, i32* %0)
%16 = call i32 @fwrite(i8* %4, i32 2, i32 1, i32* %0)
store i8 0, i8* %4
store i8 32, i8* %9
%17 = call i32 @fwrite(i8* %4, i32 2, i32 1, i32* %0)
%18 = call i32 @memset(i8* %4, i32 0, i32 128)
ret void
}