#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 */
unsigned int htonl(int);
int write_bytes(int, unsigned char *, int);
int write_tempo_change(int fd, int microsecs_per_quarternote) {
  unsigned int buf;
  unsigned char *x;
  unsigned char msg[] = {0xFF, 0x51, 0x03};
  int rc;
  microsecs_per_quarternote &= 0x00ffffff;
  buf = htonl(microsecs_per_quarternote);
  x = (unsigned char *)&buf;
  rc = write_bytes(fd, msg, 3);
  rc += write_bytes(fd, &x[1], 3);
  return (rc != 6);
}


x86 assembly (clang, -O0):
<write_tempo_change>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0xecb(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xec3(%rip),%al
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%eax
and    $0xffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1b(%rbp),%rsi
mov    $0x3,%edx
call   1040 <write_bytes@plt>
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    $0x3,%edx
call   1040 <write_bytes@plt>
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x6,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_tempo_change>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
movb   $0x3,0x2(%rsp)
movw   $0x51ff,(%rsp)
and    $0xffffff,%esi
mov    %esi,%edi
call   1030 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x3,%edx
call   1040 <write_bytes@plt>
mov    %eax,%ebp
lea    0x5(%rsp),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
call   1040 <write_bytes@plt>
add    %ebp,%eax
xor    %ecx,%ecx
cmp    $0x6,%eax
setne  %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.write_tempo_change.msg = [3 x i8] c"\FFQ\03"
define i32 @write_tempo_change(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [3 x i8]
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = bitcast [3 x i8]* %7 to i8*
%10 = load i32, i32* %4
%11 = and i32 %10, 16777215
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = call i32 @htonl(i32 %12)
store i32 %13, i32* %5
%14 = bitcast i32* %5 to i8*
store i8* %14, i8** %6
%15 = load i32, i32* %3
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%17 = call i32 @write_bytes(i32 %15, i8* %16, i32 3)
store i32 %17, i32* %8
%18 = load i32, i32* %3
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i32 @write_bytes(i32 %18, i8* %20, i32 3)
%22 = load i32, i32* %8
%23 = add nsw i32 %22, %21
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 6
%26 = zext i1 %25 to i32
ret i32 %26
}

LLVM IR (-O2):
@__const.write_tempo_change.msg = [3 x i8] c"\FFQ\03"
define i32 @write_tempo_change(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca [3 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%7 = and i32 %1, 16777215
%8 = tail call i32 @htonl(i32 %7)
store i32 %8, i32* %3
%9 = call i32 @write_bytes(i32 %0, i8* %6, i32 3)
%10 = getelementptr inbounds i8, i8* %5, i64 1
%11 = call i32 @write_bytes(i32 %0, i8* %10, i32 3)
%12 = add nsw i32 %11, %9
%13 = icmp ne i32 %12, 6
%14 = zext i1 %13 to i32
ret i32 %14
}