#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*/ PSG_setTone(unsigned char, unsigned short);
void PSG_setFrequency(unsigned char channel, unsigned short value) {
  unsigned short data;
  if (value) {
    if (((*(volatile unsigned short *)(0xC00004)) & ((1 << 0))))
      data = 3546893 / (value * 32);
    else
      data = 3579545 / (value * 32);
  } else
    data = 0;
  PSG_setTone(channel, data);
}


x86 assembly (clang, -O0):
<PSG_setFrequency>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %si,%ax
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %ax,-0x4(%rbp)
cmpw   $0x0,-0x4(%rbp)
je     1177 <PSG_setFrequency+0x67>
mov    $0xc00004,%eax
mov    (%rax),%ax
movzwl %ax,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     115f <PSG_setFrequency+0x4f>
movzwl -0x4(%rbp),%ecx
shl    $0x5,%ecx
mov    $0x361f0d,%eax
cltd
idiv   %ecx
mov    %ax,-0x6(%rbp)
jmp    1172 <PSG_setFrequency+0x62>
movzwl -0x4(%rbp),%ecx
shl    $0x5,%ecx
mov    $0x369e99,%eax
cltd
idiv   %ecx
mov    %ax,-0x6(%rbp)
jmp    117d <PSG_setFrequency+0x6d>
movw   $0x0,-0x6(%rbp)
mov    -0x1(%rbp),%al
movzbl %al,%edi
movzwl -0x6(%rbp),%esi
call   1030 <PSG_setTone@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PSG_setFrequency>:
test   %esi,%esi
je     1137 <PSG_setFrequency+0x27>
movzwl 0xc00004,%eax
movzwl %si,%ecx
shl    $0x5,%ecx
test   $0x1,%al
mov    $0x369e99,%edx
mov    $0x361f0d,%eax
cmove  %edx,%eax
xor    %edx,%edx
div    %ecx
jmp    1139 <PSG_setFrequency+0x29>
xor    %eax,%eax
movzbl %dil,%edi
movzwl %ax,%esi
jmp    1030 <PSG_setTone@plt>

LLVM IR (-O0):
define void @PSG_setFrequency(i8 zeroext %0, i16 zeroext %1) {
%3 = alloca i8
%4 = alloca i16
%5 = alloca i16
store i8 %0, i8* %3
store i16 %1, i16* %4
%6 = load i16, i16* %4
%7 = icmp ne i16 %6, 0
br i1 %7, label %8, label %26
8: ; preds = %2
%9 = load volatile i16, i16* inttoptr (i64 12582916 to i16*)
%10 = zext i16 %9 to i32
%11 = and i32 %10, 1
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i16, i16* %4
%15 = zext i16 %14 to i32
%16 = mul nsw i32 %15, 32
%17 = sdiv i32 3546893, %16
%18 = trunc i32 %17 to i16
store i16 %18, i16* %5
br label %25
19: ; preds = %8
%20 = load i16, i16* %4
%21 = zext i16 %20 to i32
%22 = mul nsw i32 %21, 32
%23 = sdiv i32 3579545, %22
%24 = trunc i32 %23 to i16
store i16 %24, i16* %5
br label %25
25: ; preds = %19, %13
br label %27
26: ; preds = %2
store i16 0, i16* %5
br label %27
27: ; preds = %26, %25
%28 = load i8, i8* %3
%29 = load i16, i16* %5
%30 = call i32 @PSG_setTone(i8 zeroext %28, i16 zeroext %29)
ret void
}

LLVM IR (-O2):
define void @PSG_setFrequency(i8 zeroext %0, i16 zeroext %1) {
%3 = icmp eq i16 %1, 0
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = load volatile i16, i16* inttoptr (i64 12582916 to i16*)
%6 = and i16 %5, 1
%7 = icmp eq i16 %6, 0
%8 = zext i16 %1 to i32
%9 = shl nuw nsw i32 %8, 5
%10 = select i1 %7, i32 3579545, i32 3546893
%11 = udiv i32 %10, %9
%12 = trunc i32 %11 to i16
br label %13
13: ; preds = %4, %2
%14 = phi i16 [ 0, %2 ], [ %12, %4 ]
%15 = tail call i32 @PSG_setTone(i8 zeroext %0, i16 zeroext %14)
ret void
}