#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 */
unsigned char inb(int);
int /*<<< orphan*/ outb(int, unsigned char);
void play_sound(unsigned int nFrequence) {
  unsigned int Div;
  unsigned char tmp;
  Div = 1193180 / nFrequence;
  outb(0x43, 0xb6);
  outb(0x42, (unsigned char)(Div));
  outb(0x42, (unsigned char)(Div >> 8));
  tmp = inb(0x61);
  if (tmp != (tmp | 3)) {
    outb(0x61, tmp | 3);
  }
}


x86 assembly (clang, -O0):
<play_sound>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x1234dc,%eax
xor    %edx,%edx
divl   -0x4(%rbp)
mov    %eax,-0x8(%rbp)
mov    $0x43,%edi
mov    $0xb6,%esi
call   1030 <outb@plt>
mov    -0x8(%rbp),%eax
mov    $0x42,%edi
movzbl %al,%esi
call   1030 <outb@plt>
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
mov    $0x42,%edi
movzbl %al,%esi
call   1030 <outb@plt>
mov    $0x61,%edi
call   1040 <inb@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
movzbl -0x9(%rbp),%ecx
or     $0x3,%ecx
cmp    %ecx,%eax
je     119e <play_sound+0x7e>
movzbl -0x9(%rbp),%eax
or     $0x3,%eax
mov    $0x61,%edi
movzbl %al,%esi
call   1030 <outb@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<play_sound>:
push   %rbx
mov    $0x1234dc,%eax
xor    %edx,%edx
div    %edi
mov    %eax,%ebx
mov    $0x43,%edi
mov    $0xb6,%esi
call   1030 <outb@plt>
movzbl %bl,%esi
mov    $0x42,%edi
call   1030 <outb@plt>
movzbl %bh,%esi
mov    $0x42,%edi
call   1030 <outb@plt>
mov    $0x61,%edi
call   1040 <inb@plt>
movzbl %al,%eax
mov    %eax,%esi
or     $0x3,%esi
cmp    %eax,%esi
jne    116d <play_sound+0x4d>
pop    %rbx
ret
mov    $0x61,%edi
pop    %rbx
jmp    1030 <outb@plt>

LLVM IR (-O0):
define void @play_sound(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = udiv i32 1193180, %5
store i32 %6, i32* %3
%7 = call i32 @outb(i32 67, i8 zeroext -74)
%8 = load i32, i32* %3
%9 = trunc i32 %8 to i8
%10 = call i32 @outb(i32 66, i8 zeroext %9)
%11 = load i32, i32* %3
%12 = lshr i32 %11, 8
%13 = trunc i32 %12 to i8
%14 = call i32 @outb(i32 66, i8 zeroext %13)
%15 = call zeroext i8 @inb(i32 97)
store i8 %15, i8* %4
%16 = load i8, i8* %4
%17 = zext i8 %16 to i32
%18 = load i8, i8* %4
%19 = zext i8 %18 to i32
%20 = or i32 %19, 3
%21 = icmp ne i32 %17, %20
br i1 %21, label %22, label %28
22: ; preds = %1
%23 = load i8, i8* %4
%24 = zext i8 %23 to i32
%25 = or i32 %24, 3
%26 = trunc i32 %25 to i8
%27 = call i32 @outb(i32 97, i8 zeroext %26)
br label %28
28: ; preds = %22, %1
ret void
}

LLVM IR (-O2):
define void @play_sound(i32 %0) {
%2 = udiv i32 1193180, %0
%3 = tail call i32 @outb(i32 67, i8 zeroext -74)
%4 = trunc i32 %2 to i8
%5 = tail call i32 @outb(i32 66, i8 zeroext %4)
%6 = lshr i32 %2, 8
%7 = trunc i32 %6 to i8
%8 = tail call i32 @outb(i32 66, i8 zeroext %7)
%9 = tail call zeroext i8 @inb(i32 97)
%10 = zext i8 %9 to i32
%11 = or i32 %10, 3
%12 = icmp eq i32 %11, %10
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = trunc i32 %11 to i8
%15 = tail call i32 @outb(i32 97, i8 zeroext %14)
br label %16
16: ; preds = %13, %1
ret void
}