#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 */
int /*<<< orphan*/ YM2612_writeSafe(int, int);
unsigned short Z80_isBusTaken();
int /*<<< orphan*/ Z80_releaseBus();
int /*<<< orphan*/ Z80_requestBus(int);
void YM2612_reset() {
  unsigned short i;
  unsigned short bus_taken;
  bus_taken = Z80_isBusTaken();
  if (!bus_taken)
    Z80_requestBus(1);
  for (i = 0; i < 3; i++) {
    YM2612_writeSafe(0, 0xB4 | i);
    YM2612_writeSafe(1, 0xC0);
    YM2612_writeSafe(2, 0xB4 | i);
    YM2612_writeSafe(3, 0xC0);
  }
  YM2612_writeSafe(0, 0x22);
  YM2612_writeSafe(1, 0x00);
  YM2612_writeSafe(0, 0x27);
  YM2612_writeSafe(1, 0x00);
  YM2612_writeSafe(0, 0x28);
  for (i = 0; i < 3; i++) {
    YM2612_writeSafe(1, 0x00 | i);
    YM2612_writeSafe(1, 0x04 | i);
  }
  YM2612_writeSafe(0, 0x2B);
  YM2612_writeSafe(1, 0x00);
  if (!bus_taken)
    Z80_releaseBus();
}


x86 assembly (clang, -O0):
<YM2612_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <Z80_isBusTaken@plt>
mov    %ax,-0x4(%rbp)
cmpw   $0x0,-0x4(%rbp)
jne    1168 <YM2612_reset+0x28>
mov    $0x1,%edi
call   1040 <Z80_requestBus@plt>
movw   $0x0,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x3,%eax
jge    11cf <YM2612_reset+0x8f>
movzwl -0x2(%rbp),%esi
or     $0xb4,%esi
xor    %edi,%edi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
mov    $0xc0,%esi
call   1060 <YM2612_writeSafe@plt>
movzwl -0x2(%rbp),%esi
or     $0xb4,%esi
mov    $0x2,%edi
call   1060 <YM2612_writeSafe@plt>
mov    $0x3,%edi
mov    $0xc0,%esi
call   1060 <YM2612_writeSafe@plt>
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    116e <YM2612_reset+0x2e>
xor    %edi,%edi
mov    $0x22,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <YM2612_writeSafe@plt>
xor    %edi,%edi
mov    $0x27,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <YM2612_writeSafe@plt>
xor    %edi,%edi
mov    $0x28,%esi
call   1060 <YM2612_writeSafe@plt>
movw   $0x0,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x3,%eax
jge    1251 <YM2612_reset+0x111>
movzwl -0x2(%rbp),%esi
or     $0x0,%esi
mov    $0x1,%edi
call   1060 <YM2612_writeSafe@plt>
movzwl -0x2(%rbp),%esi
or     $0x4,%esi
mov    $0x1,%edi
call   1060 <YM2612_writeSafe@plt>
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    1211 <YM2612_reset+0xd1>
xor    %edi,%edi
mov    $0x2b,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <YM2612_writeSafe@plt>
cmpw   $0x0,-0x4(%rbp)
jne    127b <YM2612_reset+0x13b>
mov    $0x0,%al
call   1050 <Z80_releaseBus@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<YM2612_reset>:
push   %rbx
xor    %eax,%eax
call   1030 <Z80_isBusTaken@plt>
mov    %eax,%ebx
test   %ax,%ax
jne    1159 <YM2612_reset+0x19>
mov    $0x1,%edi
call   1040 <Z80_requestBus@plt>
xor    %edi,%edi
mov    $0xb4,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
mov    $0xc0,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x2,%edi
mov    $0xb4,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x3,%edi
mov    $0xc0,%esi
call   1060 <YM2612_writeSafe@plt>
xor    %edi,%edi
mov    $0xb5,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
mov    $0xc0,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x2,%edi
mov    $0xb5,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x3,%edi
mov    $0xc0,%esi
call   1060 <YM2612_writeSafe@plt>
xor    %edi,%edi
mov    $0xb6,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
mov    $0xc0,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x2,%edi
mov    $0xb6,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x3,%edi
mov    $0xc0,%esi
call   1060 <YM2612_writeSafe@plt>
xor    %edi,%edi
mov    $0x22,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <YM2612_writeSafe@plt>
xor    %edi,%edi
mov    $0x27,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <YM2612_writeSafe@plt>
xor    %edi,%edi
mov    $0x28,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
mov    $0x4,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
mov    $0x5,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
mov    $0x2,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
mov    $0x6,%esi
call   1060 <YM2612_writeSafe@plt>
xor    %edi,%edi
mov    $0x2b,%esi
call   1060 <YM2612_writeSafe@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <YM2612_writeSafe@plt>
test   %bx,%bx
je     12b6 <YM2612_reset+0x176>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
jmp    1050 <Z80_releaseBus@plt>

LLVM IR (-O0):
define void @YM2612_reset() {
%1 = alloca i16
%2 = alloca i16
%3 = call zeroext i16 (...) @Z80_isBusTaken()
store i16 %3, i16* %2
%4 = load i16, i16* %2
%5 = icmp ne i16 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @Z80_requestBus(i32 1)
br label %8
8: ; preds = %6, %0
store i16 0, i16* %1
br label %9
9: ; preds = %24, %8
%10 = load i16, i16* %1
%11 = zext i16 %10 to i32
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load i16, i16* %1
%15 = zext i16 %14 to i32
%16 = or i32 180, %15
%17 = call i32 @YM2612_writeSafe(i32 0, i32 %16)
%18 = call i32 @YM2612_writeSafe(i32 1, i32 192)
%19 = load i16, i16* %1
%20 = zext i16 %19 to i32
%21 = or i32 180, %20
%22 = call i32 @YM2612_writeSafe(i32 2, i32 %21)
%23 = call i32 @YM2612_writeSafe(i32 3, i32 192)
br label %24
24: ; preds = %13
%25 = load i16, i16* %1
%26 = add i16 %25, 1
store i16 %26, i16* %1
br label %9
27: ; preds = %9
%28 = call i32 @YM2612_writeSafe(i32 0, i32 34)
%29 = call i32 @YM2612_writeSafe(i32 1, i32 0)
%30 = call i32 @YM2612_writeSafe(i32 0, i32 39)
%31 = call i32 @YM2612_writeSafe(i32 1, i32 0)
%32 = call i32 @YM2612_writeSafe(i32 0, i32 40)
store i16 0, i16* %1
br label %33
33: ; preds = %46, %27
%34 = load i16, i16* %1
%35 = zext i16 %34 to i32
%36 = icmp slt i32 %35, 3
br i1 %36, label %37, label %49
37: ; preds = %33
%38 = load i16, i16* %1
%39 = zext i16 %38 to i32
%40 = or i32 0, %39
%41 = call i32 @YM2612_writeSafe(i32 1, i32 %40)
%42 = load i16, i16* %1
%43 = zext i16 %42 to i32
%44 = or i32 4, %43
%45 = call i32 @YM2612_writeSafe(i32 1, i32 %44)
br label %46
46: ; preds = %37
%47 = load i16, i16* %1
%48 = add i16 %47, 1
store i16 %48, i16* %1
br label %33
49: ; preds = %33
%50 = call i32 @YM2612_writeSafe(i32 0, i32 43)
%51 = call i32 @YM2612_writeSafe(i32 1, i32 0)
%52 = load i16, i16* %2
%53 = icmp ne i16 %52, 0
br i1 %53, label %56, label %54
54: ; preds = %49
%55 = call i32 (...) @Z80_releaseBus()
br label %56
56: ; preds = %54, %49
ret void
}

LLVM IR (-O2):
define void @YM2612_reset() {
%1 = tail call zeroext i16 (...) @Z80_isBusTaken()
%2 = icmp eq i16 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @Z80_requestBus(i32 1)
br label %5
5: ; preds = %3, %0
%6 = tail call i32 @YM2612_writeSafe(i32 0, i32 180)
%7 = tail call i32 @YM2612_writeSafe(i32 1, i32 192)
%8 = tail call i32 @YM2612_writeSafe(i32 2, i32 180)
%9 = tail call i32 @YM2612_writeSafe(i32 3, i32 192)
%10 = tail call i32 @YM2612_writeSafe(i32 0, i32 181)
%11 = tail call i32 @YM2612_writeSafe(i32 1, i32 192)
%12 = tail call i32 @YM2612_writeSafe(i32 2, i32 181)
%13 = tail call i32 @YM2612_writeSafe(i32 3, i32 192)
%14 = tail call i32 @YM2612_writeSafe(i32 0, i32 182)
%15 = tail call i32 @YM2612_writeSafe(i32 1, i32 192)
%16 = tail call i32 @YM2612_writeSafe(i32 2, i32 182)
%17 = tail call i32 @YM2612_writeSafe(i32 3, i32 192)
%18 = tail call i32 @YM2612_writeSafe(i32 0, i32 34)
%19 = tail call i32 @YM2612_writeSafe(i32 1, i32 0)
%20 = tail call i32 @YM2612_writeSafe(i32 0, i32 39)
%21 = tail call i32 @YM2612_writeSafe(i32 1, i32 0)
%22 = tail call i32 @YM2612_writeSafe(i32 0, i32 40)
%23 = tail call i32 @YM2612_writeSafe(i32 1, i32 0)
%24 = tail call i32 @YM2612_writeSafe(i32 1, i32 4)
%25 = tail call i32 @YM2612_writeSafe(i32 1, i32 1)
%26 = tail call i32 @YM2612_writeSafe(i32 1, i32 5)
%27 = tail call i32 @YM2612_writeSafe(i32 1, i32 2)
%28 = tail call i32 @YM2612_writeSafe(i32 1, i32 6)
%29 = tail call i32 @YM2612_writeSafe(i32 0, i32 43)
%30 = tail call i32 @YM2612_writeSafe(i32 1, i32 0)
br i1 %2, label %31, label %33
31: ; preds = %5
%32 = tail call i32 (...) @Z80_releaseBus()
br label %33
33: ; preds = %31, %5
ret void
}