#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*/ uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ write_uint16(int);
void write_imf_element(uint8_t opl, uint8_t data, uint16_t delay,
                       uint16_t *counter) {
  fwrite(&opl, sizeof(uint8_t), 1, stdout);
  fwrite(&data, sizeof(uint8_t), 1, stdout);
  write_uint16(delay);
  if (counter != NULL) {
    *counter += 4;
  }
}


x86 assembly (clang, -O0):
<write_imf_element>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%ecx
lea    -0x4(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%ecx
lea    -0x8(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
mov    -0xc(%rbp),%edi
call   1030 <write_uint16@plt>
cmpq   $0x0,-0x18(%rbp)
je     118b <write_imf_element+0x6b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x4,%ecx
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_imf_element>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %edi,0xc(%rsp)
mov    %esi,0x8(%rsp)
mov    0x2ea3(%rip),%rbp
mov    0x0(%rbp),%ecx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
mov    0x0(%rbp),%ecx
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
mov    %r14d,%edi
call   1030 <write_uint16@plt>
test   %rbx,%rbx
je     117b <write_imf_element+0x5b>
addl   $0x4,(%rbx)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define void @write_imf_element(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%9 = load i32, i32* @stdout
%10 = call i32 @fwrite(i32* %5, i32 4, i32 1, i32 %9)
%11 = load i32, i32* @stdout
%12 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32 %11)
%13 = load i32, i32* %7
%14 = call i32 @write_uint16(i32 %13)
%15 = load i32*, i32** %8
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = load i32*, i32** %8
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 4
store i32 %20, i32* %18
br label %21
21: ; preds = %17, %4
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
define void @write_imf_element(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
%7 = load i32, i32* @stdout
%8 = call i32 @fwrite(i32* %5, i32 4, i32 1, i32 %7)
%9 = load i32, i32* @stdout
%10 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32 %9)
%11 = call i32 @write_uint16(i32 %2)
%12 = icmp eq i32* %3, null
br i1 %12, label %16, label %13
13: ; preds = %4
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 4
store i32 %15, i32* %3
br label %16
16: ; preds = %13, %4
ret void
}