#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ exit(int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int snprintf(char *, int, char *);
int beep_fd_open() {
  int fd, len;
  char buf[64];
  len = snprintf(buf, sizeof(buf), "/dev/beep");
  fd = open(buf, O_RDONLY | O_NONBLOCK);
  if (fd < 0) {
    perror("beep_fd_open");
    exit(1);
  }
  return fd;
}


x86 assembly (clang, -O0):
<beep_fd_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
lea    0xea8(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    0x2e74(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    119e <beep_fd_open+0x5e>
lea    0xe7b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<beep_fd_open>:
push   %rbx
sub    $0x40,%rsp
lea    0xeb4(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1030 <snprintf@plt>
mov    0x2e7d(%rip),%rax
mov    0x2e7e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
test   %eax,%eax
js     1180 <beep_fd_open+0x40>
add    $0x40,%rsp
pop    %rbx
ret
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/beep\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [13 x i8] c"beep_fd_open\00"
define i32 @beep_fd_open() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = call i32 @snprintf(i8* %2, i32 64, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @O_RDONLY
%5 = load i32, i32* @O_NONBLOCK
%6 = or i32 %5, %4
%7 = call i32 @open(i8* %2, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
ret i32 %7
}