#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ XKeyboardState;
struct TYPE_4__ {
  void *bell_duration;
  void *bell_pitch;
  void *bell_percent;
  void *key_click_percent;
};
typedef TYPE_1__ XKeyboardControl;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
unsigned long KBBellDuration;
unsigned long KBBellPercent;
unsigned long KBBellPitch;
int /*<<< orphan*/ XBell(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ XChangeKeyboardControl(int /*<<< orphan*/ *, unsigned long,
                                          TYPE_1__ *);
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XGetKeyboardControl(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
void *atoi(char *);
int /*<<< orphan*/ pkc(TYPE_1__ *, unsigned long);
int /*<<< orphan*/ pks(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  Display *display = XOpenDisplay(NULL);
  XKeyboardControl kc;
  XKeyboardState ks;
  unsigned long vm;
  if (argc != 5) {
    printf("Usage: xbell percent baseVolume pitch duration\n");
    return 1;
  }
  vm = (KBBellPercent | KBBellPitch | KBBellDuration);
  kc.key_click_percent = atoi(argv[1]);
  kc.bell_percent = atoi(argv[2]);
  kc.bell_pitch = atoi(argv[3]);
  kc.bell_duration = atoi(argv[4]);
  printf("Setting:\n");
  pkc(&kc, vm);
  XChangeKeyboardControl(display, vm, &kc);
  printf("Have:\n");
  XGetKeyboardControl(display, &ks);
  pks(&ks);
  XBell(display, 100);
  XCloseDisplay(display);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11d5 <main+0x45>
lea    0xe3c(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a5 <main+0x115>
mov    0x2df4(%rip),%rax
mov    (%rax),%rax
mov    0x2df2(%rip),%rcx
or     (%rcx),%rax
mov    0x2df8(%rip),%rcx
or     (%rcx),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10a0 <atoi@plt>
mov    %rax,-0x38(%rbp)
lea    0xdee(%rip),%rdi
call   1060 <printf@plt>
mov    -0x48(%rbp),%rsi
lea    -0x38(%rbp),%rdi
call   1080 <pkc@plt>
mov    -0x18(%rbp),%rdi
mov    -0x48(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1030 <XChangeKeyboardControl@plt>
lea    0xdce(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1050 <XGetKeyboardControl@plt>
lea    -0x3c(%rbp),%rdi
call   1070 <pks@plt>
mov    -0x18(%rbp),%rdi
mov    $0x64,%esi
call   1040 <XBell@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <XCloseDisplay@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r12
mov    %edi,%ebx
xor    %r14d,%r14d
xor    %edi,%edi
call   1090 <XOpenDisplay@plt>
cmp    $0x5,%ebx
jne    1275 <main+0xe5>
mov    %rax,%r15
mov    0x2e13(%rip),%rax
mov    0x2e14(%rip),%rcx
mov    (%rcx),%rbx
or     (%rax),%rbx
mov    0x2e17(%rip),%rax
or     (%rax),%rbx
mov    0x8(%r12),%rdi
call   10a0 <atoi@plt>
mov    %rax,0x20(%rsp)
mov    0x10(%r12),%rdi
call   10a0 <atoi@plt>
mov    %rax,0x18(%rsp)
mov    0x18(%r12),%rdi
call   10a0 <atoi@plt>
mov    %rax,0x10(%rsp)
mov    0x20(%r12),%rdi
call   10a0 <atoi@plt>
mov    %rax,0x8(%rsp)
lea    0xde9(%rip),%rdi
call   1060 <puts@plt>
lea    0x8(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1080 <pkc@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1030 <XChangeKeyboardControl@plt>
lea    0xdc8(%rip),%rdi
call   1060 <puts@plt>
lea    0x4(%rsp),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <XGetKeyboardControl@plt>
mov    %rbx,%rdi
call   1070 <pks@plt>
mov    %r15,%rdi
mov    $0x64,%esi
call   1040 <XBell@plt>
mov    %r15,%rdi
call   10b0 <XCloseDisplay@plt>
jmp    1287 <main+0xf7>
lea    0xd93(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i8*, i8*, i8*, i8* }
@.str = [48 x i8] c"Usage: xbell percent baseVolume pitch duration\0A\00"
@KBBellPercent = global i64 0
@KBBellPitch = global i64 0
@KBBellDuration = global i64 0
@.str.1 = [10 x i8] c"Setting:\0A\00"
@.str.2 = [7 x i8] c"Have:\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.TYPE_4__
%8 = alloca i32
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @XOpenDisplay(i32* null)
store i32* %10, i32** %6
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 5
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %55
15: ; preds = %2
%16 = load i64, i64* @KBBellPercent
%17 = load i64, i64* @KBBellPitch
%18 = or i64 %16, %17
%19 = load i64, i64* @KBBellDuration
%20 = or i64 %18, %19
store i64 %20, i64* %9
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i8* @atoi(i8* %23)
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 3
store i8* %24, i8** %25
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i8* @atoi(i8* %28)
%30 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 2
store i8* %29, i8** %30
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = call i8* @atoi(i8* %33)
%35 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 1
store i8* %34, i8** %35
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 4
%38 = load i8*, i8** %37
%39 = call i8* @atoi(i8* %38)
%40 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
store i8* %39, i8** %40
%41 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%42 = load i64, i64* %9
%43 = call i32 @pkc(%struct.TYPE_4__* %7, i64 %42)
%44 = load i32*, i32** %6
%45 = load i64, i64* %9
%46 = call i32 @XChangeKeyboardControl(i32* %44, i64 %45, %struct.TYPE_4__* %7)
%47 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%48 = load i32*, i32** %6
%49 = call i32 @XGetKeyboardControl(i32* %48, i32* %8)
%50 = call i32 @pks(i32* %8)
%51 = load i32*, i32** %6
%52 = call i32 @XBell(i32* %51, i32 100)
%53 = load i32*, i32** %6
%54 = call i32 @XCloseDisplay(i32* %53)
store i32 0, i32* %3
br label %55
55: ; preds = %15, %13
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i8*, i8*, i8*, i8* }
@KBBellPercent = global i64 0
@KBBellPitch = global i64 0
@KBBellDuration = global i64 0
@str = [9 x i8] c"Setting:\00"
@str.3 = [6 x i8] c"Have:\00"
@str.4 = [47 x i8] c"Usage: xbell percent baseVolume pitch duration\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.TYPE_4__
%4 = alloca i32
%5 = tail call i32* @XOpenDisplay(i32* null)
%6 = bitcast %struct.TYPE_4__* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = icmp eq i32 %0, 5
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.4, i64 0, i64 0))
br label %41
11: ; preds = %2
%12 = load i64, i64* @KBBellPercent
%13 = load i64, i64* @KBBellPitch
%14 = or i64 %13, %12
%15 = load i64, i64* @KBBellDuration
%16 = or i64 %14, %15
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i8* @atoi(i8* %18)
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 3
store i8* %19, i8** %20
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i8* @atoi(i8* %22)
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 2
store i8* %23, i8** %24
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = tail call i8* @atoi(i8* %26)
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 1
store i8* %27, i8** %28
%29 = getelementptr inbounds i8*, i8** %1, i64 4
%30 = load i8*, i8** %29
%31 = tail call i8* @atoi(i8* %30)
%32 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
store i8* %31, i8** %32
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%34 = call i32 @pkc(%struct.TYPE_4__* %3, i64 %16)
%35 = call i32 @XChangeKeyboardControl(i32* %5, i64 %16, %struct.TYPE_4__* %3)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.3, i64 0, i64 0))
%37 = call i32 @XGetKeyboardControl(i32* %5, i32* %4)
%38 = call i32 @pks(i32* %4)
%39 = call i32 @XBell(i32* %5, i32 100)
%40 = call i32 @XCloseDisplay(i32* %5)
br label %41
41: ; preds = %11, %9
%42 = phi i32 [ 1, %9 ], [ 0, %11 ]
ret i32 %42
}