int mf_write_midi_event(delta_time, type, chan, data, size)
unsigned long delta_time;
unsigned int chan, type;
unsigned long size;
unsigned char *data;
{
  int i;
  void WriteVarLen();
  unsigned char c;
  WriteVarLen(delta_time);
  c = type | chan;
  if (chan > 15)
    perror("error: MIDI channel greater than 16\n");
  eputc(c);
  for (i = 0; i < size; i++)
    eputc(data[i]);
  return (size);
}


x86 assembly (clang, -O0):
<mf_write_midi_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <WriteVarLen@plt>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %al,-0x25(%rbp)
cmpl   $0xf,-0x10(%rbp)
jbe    1176 <mf_write_midi_event+0x46>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <perror@plt>
movzbl -0x25(%rbp),%edi
mov    $0x0,%al
call   1050 <eputc@plt>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11b7 <mf_write_midi_event+0x87>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
mov    $0x0,%al
call   1050 <eputc@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1188 <mf_write_midi_event+0x58>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mf_write_midi_event>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %rcx,%r14
mov    %edx,%ebp
mov    %esi,%r15d
xor    %eax,%eax
call   1030 <WriteVarLen@plt>
or     %ebp,%r15d
cmp    $0x10,%ebp
jb     115f <mf_write_midi_event+0x2f>
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1040 <perror@plt>
movzbl %r15b,%edi
xor    %eax,%eax
call   1050 <eputc@plt>
test   %rbx,%rbx
je     1195 <mf_write_midi_event+0x65>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbp,1),%edi
xor    %eax,%eax
call   1050 <eputc@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1180 <mf_write_midi_event+0x50>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"error: MIDI channel greater than 16\0A\00"
define i32 @mf_write_midi_event(i64 %0, i32 %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i8
store i64 %0, i64* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%13 = load i64, i64* %6
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = or i32 %14, %15
%17 = trunc i32 %16 to i8
store i8 %17, i8* %12
%18 = load i32, i32* %8
%19 = icmp ugt i32 %18, 15
br i1 %19, label %20, label %22
20: ; preds = %5
%21 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %5
%23 = load i8, i8* %12
%24 = zext i8 %23 to i32
%25 = call i32 (i32, ...) bitcast (i32 (...)* @eputc to i32 (i32, ...)*)(i32 %24)
store i32 0, i32* %11
br label %26
26: ; preds = %39, %22
%27 = load i32, i32* %11
%28 = sext i32 %27 to i64
%29 = load i64, i64* %10
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %42
31: ; preds = %26
%32 = load i8*, i8** %9
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = call i32 (i32, ...) bitcast (i32 (...)* @eputc to i32 (i32, ...)*)(i32 %37)
br label %39
39: ; preds = %31
%40 = load i32, i32* %11
%41 = add nsw i32 %40, 1
store i32 %41, i32* %11
br label %26
42: ; preds = %26
%43 = load i64, i64* %10
%44 = trunc i64 %43 to i32
ret i32 %44
}

LLVM IR (-O2):
@.str = [37 x i8] c"error: MIDI channel greater than 16\0A\00"
define i32 @mf_write_midi_event(i64 %0, i32 %1, i32 %2, i8* nocapture %3, i64 %4) {
tail call void (i64, ...) bitcast (void (...)* @WriteVarLen to void (i64, ...)*)(i64 %0)
%6 = or i32 %2, %1
%7 = icmp ugt i32 %2, 15
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = and i32 %6, 255
%12 = tail call i32 (i32, ...) bitcast (i32 (...)* @eputc to i32 (i32, ...)*)(i32 %11)
%13 = icmp eq i64 %4, 0
br i1 %13, label %22, label %14
14: ; preds = %10, %14
%15 = phi i64 [ %20, %14 ], [ 0, %10 ]
%16 = getelementptr inbounds i8, i8* %3, i64 %15
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = tail call i32 (i32, ...) bitcast (i32 (...)* @eputc to i32 (i32, ...)*)(i32 %18)
%20 = add nuw i64 %15, 1
%21 = icmp eq i64 %20, %4
br i1 %21, label %22, label %14
22: ; preds = %14, %10
%23 = trunc i64 %4 to i32
ret i32 %23
}