#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 inb_p(int);
int /*<<< orphan*/ outb(int, int);
int /*<<< orphan*/ outb_p(unsigned int, int);
int /*<<< orphan*/ sleep(int, int /*<<< orphan*/, int /*<<< orphan*/, int);
void beep(unsigned int frequency) {
  unsigned int count = 1193180 / frequency;
  outb_p(inb_p(0x61) | 3, 0x61);
  outb_p(0xB6, 0x43);
  outb_p(count & 0xff, 0x42);
  outb((count >> 8) & 0xff, 0x42);
  sleep(100, 0, 0, 1);
  outb(inb_p(0x61) & 0xFC, 0x61);
}


x86 assembly (clang, -O0):
<beep>:
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    $0x61,%edi
call   1050 <inb_p@plt>
mov    %eax,%edi
or     $0x3,%edi
mov    $0x61,%esi
call   1040 <outb_p@plt>
mov    $0xb6,%edi
mov    $0x43,%esi
call   1040 <outb_p@plt>
mov    -0x8(%rbp),%edi
and    $0xff,%edi
mov    $0x42,%esi
call   1040 <outb_p@plt>
mov    -0x8(%rbp),%edi
shr    $0x8,%edi
and    $0xff,%edi
mov    $0x42,%esi
call   1030 <outb@plt>
mov    $0x64,%edi
xor    %edx,%edx
mov    $0x1,%ecx
mov    %edx,%esi
call   1060 <sleep@plt>
mov    $0x61,%edi
call   1050 <inb_p@plt>
mov    %eax,%edi
and    $0xfc,%edi
mov    $0x61,%esi
call   1030 <outb@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<beep>:
push   %rbx
mov    $0x1234dc,%eax
xor    %edx,%edx
div    %edi
mov    %eax,%ebx
mov    $0x61,%edi
call   1050 <inb_p@plt>
or     $0x3,%eax
mov    %eax,%edi
mov    $0x61,%esi
call   1040 <outb_p@plt>
mov    $0xb6,%edi
mov    $0x43,%esi
call   1040 <outb_p@plt>
movzbl %bl,%edi
mov    $0x42,%esi
call   1040 <outb_p@plt>
movzbl %bh,%edi
mov    $0x42,%esi
call   1030 <outb@plt>
mov    $0x64,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1060 <sleep@plt>
mov    $0x61,%edi
call   1050 <inb_p@plt>
and    $0xfc,%eax
mov    %eax,%edi
mov    $0x61,%esi
pop    %rbx
jmp    1030 <outb@plt>

LLVM IR (-O0):
define void @beep(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = udiv i32 1193180, %4
store i32 %5, i32* %3
%6 = call i32 @inb_p(i32 97)
%7 = or i32 %6, 3
%8 = call i32 @outb_p(i32 %7, i32 97)
%9 = call i32 @outb_p(i32 182, i32 67)
%10 = load i32, i32* %3
%11 = and i32 %10, 255
%12 = call i32 @outb_p(i32 %11, i32 66)
%13 = load i32, i32* %3
%14 = lshr i32 %13, 8
%15 = and i32 %14, 255
%16 = call i32 @outb(i32 %15, i32 66)
%17 = call i32 @sleep(i32 100, i32 0, i32 0, i32 1)
%18 = call i32 @inb_p(i32 97)
%19 = and i32 %18, 252
%20 = call i32 @outb(i32 %19, i32 97)
ret void
}

LLVM IR (-O2):
define void @beep(i32 %0) {
%2 = udiv i32 1193180, %0
%3 = tail call i32 @inb_p(i32 97)
%4 = or i32 %3, 3
%5 = tail call i32 @outb_p(i32 %4, i32 97)
%6 = tail call i32 @outb_p(i32 182, i32 67)
%7 = and i32 %2, 255
%8 = tail call i32 @outb_p(i32 %7, i32 66)
%9 = lshr i32 %2, 8
%10 = and i32 %9, 255
%11 = tail call i32 @outb(i32 %10, i32 66)
%12 = tail call i32 @sleep(i32 100, i32 0, i32 0, i32 1)
%13 = tail call i32 @inb_p(i32 97)
%14 = and i32 %13, 252
%15 = tail call i32 @outb(i32 %14, i32 97)
ret void
}