#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 AFMT_S16_LE;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SNDCTL_DSP_CHANNELS;
int /*<<< orphan*/ SNDCTL_DSP_SETFMT;
int /*<<< orphan*/ SNDCTL_DSP_SPEED;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/);
int stb_vorbis_decode_filename(char *, int *, int *, short **);
int write(int, short *, int);
int /*<<< orphan*/ write2(char *);
int main(int argc, char **argv) {
  int error, value = AFMT_S16_LE, pcm = open("/dev/dsp", O_WRONLY);
  if (pcm < 0)
    write2("cannot get fd\n");
  if (ioctl(pcm, SNDCTL_DSP_SETFMT, &value) < 0)
    write2("cannot set audio format: %s\n");
  while (--argc) {
    short *decoded;
    int channels, len, sample_rate;
    len = stb_vorbis_decode_filename(argv[argc], &channels, &sample_rate,
                                     &decoded);
    len *= channels;
    if (ioctl(pcm, SNDCTL_DSP_CHANNELS, &channels) < 0)
      write2("cannot set channels");
    if (ioctl(pcm, SNDCTL_DSP_SPEED, &sample_rate) < 0)
      write2("cannot set sample rate");
    while (len > 0) {
      int out = write(pcm, decoded, 4096);
      decoded += out >> 1;
      len -= out;
    }
  }
  close(pcm);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
lea    0xe6e(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11b0 <main+0x50>
lea    0xe5e(%rip),%rdi
call   1070 <write2@plt>
mov    -0x1c(%rbp),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11db <main+0x7b>
lea    0xe42(%rip),%rdi
call   1070 <write2@plt>
jmp    11e0 <main+0x80>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     12c2 <main+0x162>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1050 <stb_vorbis_decode_filename@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
imul   -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1247 <main+0xe7>
lea    0xdf3(%rip),%rdi
call   1070 <write2@plt>
mov    -0x1c(%rbp),%edi
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
lea    -0x34(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1272 <main+0x112>
lea    0xddc(%rip),%rdi
call   1070 <write2@plt>
jmp    1277 <main+0x117>
cmpl   $0x0,-0x30(%rbp)
jle    12bd <main+0x15d>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <write@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%ecx
sar    $0x1,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
shl    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%ecx
mov    -0x30(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x30(%rbp)
jmp    1277 <main+0x117>
jmp    11e0 <main+0x80>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11a7 <main+0x47>
lea    0xe67(%rip),%rdi
call   1070 <write2@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     11cb <main+0x6b>
add    $0xffffffff,%ebx
jne    11e0 <main+0x80>
jmp    12a8 <main+0x148>
lea    0xe46(%rip),%rdi
call   1070 <write2@plt>
add    $0xffffffff,%ebx
je     12a8 <main+0x148>
movslq %ebx,%r12
lea    0xc(%rsp),%r15
lea    0x14(%rsp),%rbx
jmp    11fd <main+0x9d>
nop
add    $0xffffffffffffffff,%r12
test   %r12d,%r12d
je     12a8 <main+0x148>
mov    (%r14,%r12,8),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rsp,%rcx
call   1050 <stb_vorbis_decode_filename@plt>
mov    %eax,%r13d
imul   0xc(%rsp),%r13d
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r15,%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
jns    123c <main+0xdc>
lea    0xdfe(%rip),%rdi
call   1070 <write2@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
js     1260 <main+0x100>
test   %r13d,%r13d
jg     1275 <main+0x115>
jmp    11f0 <main+0x90>
nopl   0x0(%rax,%rax,1)
lea    0xde2(%rip),%rdi
call   1070 <write2@plt>
test   %r13d,%r13d
jle    11f0 <main+0x90>
mov    (%rsp),%rsi
nopl   0x0(%rax)
mov    %ebp,%edi
mov    $0x1000,%edx
call   1030 <write@plt>
mov    %eax,%ecx
sar    %ecx
movslq %ecx,%rsi
add    %rsi,%rsi
add    (%rsp),%rsi
mov    %rsi,(%rsp)
sub    %eax,%r13d
jg     1280 <main+0x120>
jmp    11f0 <main+0x90>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AFMT_S16_LE = global i32 0
@.str = [9 x i8] c"/dev/dsp\00"
@O_WRONLY = global i32 0
@.str.1 = [15 x i8] c"cannot get fd\0A\00"
@SNDCTL_DSP_SETFMT = global i32 0
@.str.2 = [29 x i8] c"cannot set audio format: %s\0A\00"
@SNDCTL_DSP_CHANNELS = global i32 0
@.str.3 = [20 x i8] c"cannot set channels\00"
@SNDCTL_DSP_SPEED = global i32 0
@.str.4 = [23 x i8] c"cannot set sample rate\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i16*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @AFMT_S16_LE
store i32 %14, i32* %7
%15 = load i32, i32* @O_WRONLY
%16 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @write2(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
%22 = load i32, i32* %8
%23 = load i32, i32* @SNDCTL_DSP_SETFMT
%24 = call i64 @ioctl(i32 %22, i32 %23, i32* %7)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @write2(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
br label %29
29: ; preds = %72, %28
%30 = load i32, i32* %4
%31 = add nsw i32 %30, -1
store i32 %31, i32* %4
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %73
33: ; preds = %29
%34 = load i8**, i8*** %5
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @stb_vorbis_decode_filename(i8* %38, i32* %10, i32* %12, i16** %9)
store i32 %39, i32* %11
%40 = load i32, i32* %10
%41 = load i32, i32* %11
%42 = mul nsw i32 %41, %40
store i32 %42, i32* %11
%43 = load i32, i32* %8
%44 = load i32, i32* @SNDCTL_DSP_CHANNELS
%45 = call i64 @ioctl(i32 %43, i32 %44, i32* %10)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %33
%48 = call i32 @write2(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %33
%50 = load i32, i32* %8
%51 = load i32, i32* @SNDCTL_DSP_SPEED
%52 = call i64 @ioctl(i32 %50, i32 %51, i32* %12)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 @write2(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %54, %49
br label %57
57: ; preds = %60, %56
%58 = load i32, i32* %11
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %72
60: ; preds = %57
%61 = load i32, i32* %8
%62 = load i16*, i16** %9
%63 = call i32 @write(i32 %61, i16* %62, i32 4096)
store i32 %63, i32* %13
%64 = load i32, i32* %13
%65 = ashr i32 %64, 1
%66 = load i16*, i16** %9
%67 = sext i32 %65 to i64
%68 = getelementptr inbounds i16, i16* %66, i64 %67
store i16* %68, i16** %9
%69 = load i32, i32* %13
%70 = load i32, i32* %11
%71 = sub nsw i32 %70, %69
store i32 %71, i32* %11
br label %57
72: ; preds = %57
br label %29
73: ; preds = %29
%74 = load i32, i32* %8
%75 = call i32 @close(i32 %74)
ret i32 0
}

LLVM IR (-O2):
@AFMT_S16_LE = global i32 0
@.str = [9 x i8] c"/dev/dsp\00"
@O_WRONLY = global i32 0
@.str.1 = [15 x i8] c"cannot get fd\0A\00"
@SNDCTL_DSP_SETFMT = global i32 0
@.str.2 = [29 x i8] c"cannot set audio format: %s\0A\00"
@SNDCTL_DSP_CHANNELS = global i32 0
@.str.3 = [20 x i8] c"cannot set channels\00"
@SNDCTL_DSP_SPEED = global i32 0
@.str.4 = [23 x i8] c"cannot set sample rate\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i16*
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = load i32, i32* @AFMT_S16_LE
store i32 %8, i32* %3
%9 = load i32, i32* @O_WRONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 @write2(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* @SNDCTL_DSP_SETFMT
%16 = call i64 @ioctl(i32 %10, i32 %15, i32* %3)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @write2(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = add i32 %0, -1
%22 = icmp eq i32 %21, 0
br i1 %22, label %64, label %23
23: ; preds = %20
%24 = bitcast i16** %4 to i8*
%25 = bitcast i32* %5 to i8*
%26 = bitcast i32* %6 to i8*
%27 = sext i32 %21 to i64
br label %28
28: ; preds = %23, %60
%29 = phi i64 [ %27, %23 ], [ %61, %60 ]
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @stb_vorbis_decode_filename(i8* %31, i32* %5, i32* %6, i16** %4)
%33 = load i32, i32* %5
%34 = mul nsw i32 %33, %32
%35 = load i32, i32* @SNDCTL_DSP_CHANNELS
%36 = call i64 @ioctl(i32 %10, i32 %35, i32* %5)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %28
%39 = call i32 @write2(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %28
%41 = load i32, i32* @SNDCTL_DSP_SPEED
%42 = call i64 @ioctl(i32 %10, i32 %41, i32* %6)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @write2(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
%47 = icmp sgt i32 %34, 0
br i1 %47, label %48, label %60
48: ; preds = %46
%49 = load i16*, i16** %4
br label %50
50: ; preds = %48, %50
%51 = phi i16* [ %57, %50 ], [ %49, %48 ]
%52 = phi i32 [ %58, %50 ], [ %34, %48 ]
%53 = call i32 @write(i32 %10, i16* %51, i32 4096)
%54 = ashr i32 %53, 1
%55 = load i16*, i16** %4
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i16, i16* %55, i64 %56
store i16* %57, i16** %4
%58 = sub nsw i32 %52, %53
%59 = icmp sgt i32 %58, 0
br i1 %59, label %50, label %60
60: ; preds = %50, %46
%61 = add nsw i64 %29, -1
%62 = trunc i64 %61 to i32
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %28
64: ; preds = %60, %20
%65 = call i32 @close(i32 %10)
ret i32 0
}