#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__ write(int, unsigned char *, int);
int write_var_len(int, long);
int smf_note_on(int fd, long dtime, char note, char vel, char channel) {
  unsigned char data[3];
  int num;
  num = write_var_len(fd, dtime);
  data[0] = 0x90 + channel;
  data[1] = note;
  data[2] = vel;
  num += write(fd, data, 3);
  return num;
}


x86 assembly (clang, -O0):
<smf_note_on>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %r8b,%al
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %dl,-0x11(%rbp)
mov    %cl,-0x12(%rbp)
mov    %al,-0x13(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <write_var_len@plt>
mov    %eax,-0x1c(%rbp)
movsbl -0x13(%rbp),%eax
add    $0x90,%eax
mov    %al,-0x16(%rbp)
mov    -0x11(%rbp),%al
mov    %al,-0x15(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0x3,%edx
call   1040 <write@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smf_note_on>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8d,%ebx
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %edi,%ebp
call   1030 <write_var_len@plt>
mov    %eax,%r12d
add    $0x90,%bl
mov    %bl,0xd(%rsp)
mov    %r15b,0xe(%rsp)
mov    %r14b,0xf(%rsp)
lea    0xd(%rsp),%rsi
mov    %ebp,%edi
mov    $0x3,%edx
call   1040 <write@plt>
add    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @smf_note_on(i32 %0, i64 %1, i8 signext %2, i8 signext %3, i8 signext %4) {
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca [3 x i8]
%12 = alloca i32
store i32 %0, i32* %6
store i64 %1, i64* %7
store i8 %2, i8* %8
store i8 %3, i8* %9
store i8 %4, i8* %10
%13 = load i32, i32* %6
%14 = load i64, i64* %7
%15 = call i32 @write_var_len(i32 %13, i64 %14)
store i32 %15, i32* %12
%16 = load i8, i8* %10
%17 = sext i8 %16 to i32
%18 = add nsw i32 144, %17
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
store i8 %19, i8* %20
%21 = load i8, i8* %8
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 1
store i8 %21, i8* %22
%23 = load i8, i8* %9
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 2
store i8 %23, i8* %24
%25 = load i32, i32* %6
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%27 = call i64 @write(i32 %25, i8* %26, i32 3)
%28 = load i32, i32* %12
%29 = sext i32 %28 to i64
%30 = add nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %12
%32 = load i32, i32* %12
ret i32 %32
}

LLVM IR (-O2):
define i32 @smf_note_on(i32 %0, i64 %1, i8 signext %2, i8 signext %3, i8 signext %4) {
%6 = alloca [3 x i8]
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%8 = tail call i32 @write_var_len(i32 %0, i64 %1)
%9 = add i8 %4, -112
store i8 %9, i8* %7
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 1
store i8 %2, i8* %10
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 2
store i8 %3, i8* %11
%12 = call i64 @write(i32 %0, i8* %7, i32 3)
%13 = trunc i64 %12 to i32
%14 = add i32 %8, %13
ret i32 %14
}