#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*/ KIOCSOUND;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
void beep_long() {
  int console_fd = -1;
  if ((console_fd = open("/dev/console", O_WRONLY)) == -1) {
    fprintf(stderr, "Could not open /dev/console for writing.\n");
    perror("open");
    exit(1);
  }
  if (ioctl(console_fd, KIOCSOUND, 1193180 / 1000) < 0) {
    perror("ioctl");
  }
  usleep(300000);
  ioctl(console_fd, KIOCSOUND, 0);
  close(console_fd);
}


x86 assembly (clang, -O0):
<beep_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    11cb <beep_long+0x5b>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe7b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x4(%rbp),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
mov    $0x4a9,%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11f7 <beep_long+0x87>
lea    0xe4a(%rip),%rdi
call   1070 <perror@plt>
mov    $0x493e0,%edi
call   1090 <usleep@plt>
mov    -0x4(%rbp),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<beep_long>:
push   %r14
push   %rbx
push   %rax
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    0xe7c(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11dd <beep_long+0x6d>
mov    %eax,%ebx
mov    0x2e51(%rip),%r14
mov    (%r14),%esi
mov    %eax,%edi
mov    $0x4a9,%edx
call   1030 <ioctl@plt>
test   %rax,%rax
js     11cf <beep_long+0x5f>
mov    $0x493e0,%edi
call   1090 <usleep@plt>
mov    (%r14),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <close@plt>
lea    0xe66(%rip),%rdi
call   1070 <perror@plt>
jmp    11ab <beep_long+0x3b>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe3e(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/console\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [42 x i8] c"Could not open /dev/console for writing.\0A\00"
@.str.2 = [5 x i8] c"open\00"
@KIOCSOUND = global i32 0
@.str.3 = [6 x i8] c"ioctl\00"
define void @beep_long() {
%1 = alloca i32
store i32 -1, i32* %1
%2 = load i32, i32* @O_WRONLY
%3 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %2)
store i32 %3, i32* %1
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* %1
%12 = load i32, i32* @KIOCSOUND
%13 = call i64 @ioctl(i32 %11, i32 %12, i32 1193)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = call i32 @usleep(i32 300000)
%19 = load i32, i32* %1
%20 = load i32, i32* @KIOCSOUND
%21 = call i64 @ioctl(i32 %19, i32 %20, i32 0)
%22 = load i32, i32* %1
%23 = call i32 @close(i32 %22)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/console\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [42 x i8] c"Could not open /dev/console for writing.\0A\00"
@.str.2 = [5 x i8] c"open\00"
@KIOCSOUND = global i32 0
@.str.3 = [6 x i8] c"ioctl\00"
define void @beep_long() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %9
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i32, i32* @KIOCSOUND
%11 = tail call i64 @ioctl(i32 %2, i32 %10, i32 1193)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = tail call i32 @usleep(i32 300000)
%17 = load i32, i32* @KIOCSOUND
%18 = tail call i64 @ioctl(i32 %2, i32 %17, i32 0)
%19 = tail call i32 @close(i32 %2)
ret void
}