#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*/ fwrite(char const *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ write_be_long(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ write_be_short(int, int /*<<< orphan*/ *);
void write_midi_header(int format, int tracks, int ticks, FILE *fp) {
  const char *hdr = "MThd";
  fwrite(hdr, 1, 4, fp);
  write_be_long(6, fp);
  write_be_short(format, fp);
  write_be_short(tracks, fp);
  write_be_short(ticks, fp);
}


x86 assembly (clang, -O0):
<write_midi_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
lea    0xeb4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1050 <fwrite@plt>
mov    -0x18(%rbp),%rsi
mov    $0x6,%edi
call   1040 <write_be_long@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <write_be_short@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <write_be_short@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <write_be_short@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_midi_header>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebp
lea    0xeb7(%rip),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1050 <fwrite@plt>
mov    $0x6,%edi
mov    %rbx,%rsi
call   1040 <write_be_long@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write_be_short@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1030 <write_be_short@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <write_be_short@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"MThd\00"
define void @write_midi_header(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i8*, i8** %9
%11 = load i32*, i32** %8
%12 = call i32 @fwrite(i8* %10, i32 1, i32 4, i32* %11)
%13 = load i32*, i32** %8
%14 = call i32 @write_be_long(i32 6, i32* %13)
%15 = load i32, i32* %5
%16 = load i32*, i32** %8
%17 = call i32 @write_be_short(i32 %15, i32* %16)
%18 = load i32, i32* %6
%19 = load i32*, i32** %8
%20 = call i32 @write_be_short(i32 %18, i32* %19)
%21 = load i32, i32* %7
%22 = load i32*, i32** %8
%23 = call i32 @write_be_short(i32 %21, i32* %22)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"MThd\00"
define void @write_midi_header(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = tail call i32 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1, i32 4, i32* %3)
%6 = tail call i32 @write_be_long(i32 6, i32* %3)
%7 = tail call i32 @write_be_short(i32 %0, i32* %3)
%8 = tail call i32 @write_be_short(i32 %1, i32* %3)
%9 = tail call i32 @write_be_short(i32 %2, i32* %3)
ret void
}