#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 */

/* Variables and functions */
scalar_t__ wblong(int, int);
scalar_t__ wbshort(int, unsigned short);
int write(int, char *, int);
int smf_header_fmt(int fd, unsigned short format, unsigned short tracks,
                   unsigned short divisions) {
  int num;
  num = write(fd, "MThd", 4);
  num += wblong(fd, 6);
  num += wbshort(fd, format);
  num += wbshort(fd, tracks);
  num += wbshort(fd, divisions);
  return num;
}


x86 assembly (clang, -O0):
<smf_header_fmt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %cx,%ax
mov    %dx,%cx
mov    %si,%dx
mov    %edi,-0x4(%rbp)
mov    %dx,-0x6(%rbp)
mov    %cx,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    -0x4(%rbp),%edi
lea    0xea6(%rip),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x6,%esi
call   1030 <wblong@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
movzwl -0x6(%rbp),%esi
call   1050 <wbshort@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
movzwl -0x8(%rbp),%esi
call   1050 <wbshort@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
movzwl -0xa(%rbp),%esi
call   1050 <wbshort@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smf_header_fmt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,0x4(%rsp)
mov    %edx,%r15d
mov    %esi,%r12d
mov    %edi,%r14d
lea    0xeb1(%rip),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    %eax,%r13d
mov    %r14d,%edi
mov    $0x6,%esi
call   1030 <wblong@plt>
mov    %rax,%rbx
add    %r13d,%ebx
mov    %r14d,%edi
mov    %r12d,%esi
call   1050 <wbshort@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    %r14d,%edi
mov    %r15d,%esi
call   1050 <wbshort@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    %r14d,%edi
mov    0x4(%rsp),%esi
call   1050 <wbshort@plt>
add    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"MThd\00"
define i32 @smf_header_fmt(i32 %0, i16 zeroext %1, i16 zeroext %2, i16 zeroext %3) {
%5 = alloca i32
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16
%9 = alloca i32
store i32 %0, i32* %5
store i16 %1, i16* %6
store i16 %2, i16* %7
store i16 %3, i16* %8
%10 = load i32, i32* %5
%11 = call i32 @write(i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
store i32 %11, i32* %9
%12 = load i32, i32* %5
%13 = call i64 @wblong(i32 %12, i32 6)
%14 = load i32, i32* %9
%15 = sext i32 %14 to i64
%16 = add nsw i64 %15, %13
%17 = trunc i64 %16 to i32
store i32 %17, i32* %9
%18 = load i32, i32* %5
%19 = load i16, i16* %6
%20 = call i64 @wbshort(i32 %18, i16 zeroext %19)
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = add nsw i64 %22, %20
%24 = trunc i64 %23 to i32
store i32 %24, i32* %9
%25 = load i32, i32* %5
%26 = load i16, i16* %7
%27 = call i64 @wbshort(i32 %25, i16 zeroext %26)
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = add nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %9
%32 = load i32, i32* %5
%33 = load i16, i16* %8
%34 = call i64 @wbshort(i32 %32, i16 zeroext %33)
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = add nsw i64 %36, %34
%38 = trunc i64 %37 to i32
store i32 %38, i32* %9
%39 = load i32, i32* %9
ret i32 %39
}

LLVM IR (-O2):
@.str = [5 x i8] c"MThd\00"
define i32 @smf_header_fmt(i32 %0, i16 zeroext %1, i16 zeroext %2, i16 zeroext %3) {
%5 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%6 = tail call i64 @wblong(i32 %0, i32 6)
%7 = trunc i64 %6 to i32
%8 = add i32 %5, %7
%9 = tail call i64 @wbshort(i32 %0, i16 zeroext %1)
%10 = trunc i64 %9 to i32
%11 = add i32 %8, %10
%12 = tail call i64 @wbshort(i32 %0, i16 zeroext %2)
%13 = trunc i64 %12 to i32
%14 = add i32 %11, %13
%15 = tail call i64 @wbshort(i32 %0, i16 zeroext %3)
%16 = trunc i64 %15 to i32
%17 = add i32 %14, %16
ret i32 %17
}