#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, unsigned char *, int);
int write(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  int fd;
  int i, ch, ret;
  unsigned char buf[3 * 8000 * 1];
  fd = open("audio.raw", O_RDONLY);
  read(fd, buf, sizeof(buf));
  close(fd);
  fd = open("/dev/audio", O_RDWR);
  if (fd < 0) {
    printf("could not open /dev/audio\n");
    exit(1);
  }
  ret = write(fd, buf, sizeof(buf));
  printf("buf = %d, %d\n", ret, sizeof(buf));
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5de0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x5de0(%rbp),%rsi
mov    $0x5dc0,%edx
call   1060 <read@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xe54(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11e0 <main+0x80>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x5de0(%rbp),%rsi
mov    $0x5dc0,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe2f(%rip),%rdi
mov    $0x5dc0,%edx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x5de0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x5dc0,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x5dc0,%edx
call   1070 <read@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    0xe72(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11f6 <main+0x86>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x5dc0,%edx
call   1040 <write@plt>
lea    0xe34(%rip),%rdi
mov    $0x5dc0,%edx
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x5dc0,%rsp
pop    %rbx
ret
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"audio.raw\00"
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"/dev/audio\00"
@O_RDWR = global i32 0
@.str.2 = [27 x i8] c"could not open /dev/audio\0A\00"
@.str.3 = [14 x i8] c"buf = %d, %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [24000 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = getelementptr inbounds [24000 x i8], [24000 x i8]* %9, i64 0, i64 0
%14 = call i32 @read(i32 %12, i8* %13, i32 24000)
%15 = load i32, i32* %5
%16 = call i32 @close(i32 %15)
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i32, i32* %5
%26 = getelementptr inbounds [24000 x i8], [24000 x i8]* %9, i64 0, i64 0
%27 = call i32 @write(i32 %25, i8* %26, i32 24000)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %28, i64 24000)
%30 = load i32, i32* %5
%31 = call i32 @close(i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"audio.raw\00"
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"/dev/audio\00"
@O_RDWR = global i32 0
@.str.3 = [14 x i8] c"buf = %d, %d\0A\00"
@str = [26 x i8] c"could not open /dev/audio\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [24000 x i8]
%4 = getelementptr inbounds [24000 x i8], [24000 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @read(i32 %6, i8* %4, i32 24000)
%8 = tail call i32 @close(i32 %6)
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = call i32 @write(i32 %10, i8* %4, i32 24000)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %16, i64 24000)
%18 = tail call i32 @close(i32 %10)
ret i32 0
}