#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
int main(void) {
  int fd = open("/dev/beep", O_RDWR);
  if (fd == -1) {
    perror("open:");
    exit(0);
  }
  while (1) {
    ioctl(fd, 0, 1);
    sleep(1);
    ioctl(fd, 1, 1);
    sleep(1);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1194 <main+0x44>
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>
jmp    1199 <main+0x49>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <ioctl@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <ioctl@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    1199 <main+0x49>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     11a5 <main+0x55>
mov    %eax,%ebx
nopl   (%rax)
mov    %ebx,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <ioctl@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <ioctl@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    1170 <main+0x20>
lea    0xe5e(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/beep\00"
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"open:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @O_RDWR
%4 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @exit(i32 0)
unreachable
10: ; preds = %0
br label %11
11: ; preds = %10, %11
%12 = load i32, i32* %2
%13 = call i32 @ioctl(i32 %12, i32 0, i32 1)
%14 = call i32 @sleep(i32 1)
%15 = load i32, i32* %2
%16 = call i32 @ioctl(i32 %15, i32 1, i32 1)
%17 = call i32 @sleep(i32 1)
br label %11
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/beep\00"
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"open:\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %0, %7
%8 = tail call i32 @ioctl(i32 %2, i32 0, i32 1)
%9 = tail call i32 @sleep(i32 1)
%10 = tail call i32 @ioctl(i32 %2, i32 1, i32 1)
%11 = tail call i32 @sleep(i32 1)
br label %7
}