#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ close_sound_input(int);
int /*<<< orphan*/ free(int **);
int mus_read_any(int, int /*<<< orphan*/, int, int, int **, int *);
int open_sound_input(char *);
int /*<<< orphan*/ seek_sound_frame(int, int);
int sound_chans(char *);
int mus_file2array(char *filename, int chan, int start, int samples,
                   int *array) {
  int ifd, chans, total_read;
  int **bufs;
  ifd = open_sound_input(filename);
  if (ifd == -1)
    return (-1);
  chans = sound_chans(filename);
  bufs = (int **)calloc(chans, sizeof(int *));
  bufs[chan] = array;
  seek_sound_frame(ifd, start);
  total_read = mus_read_any(ifd, 0, chans, samples, bufs, (int *)bufs);
  close_sound_input(ifd);
  free(bufs);
  return (total_read);
}


x86 assembly (clang, -O0):
<mus_file2array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <open_sound_input@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11ab <mus_file2array+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <mus_file2array+0xa5>
mov    -0x10(%rbp),%rdi
call   1050 <sound_chans@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1070 <seek_sound_frame@plt>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x40(%rbp),%r8
mov    -0x40(%rbp),%r9
xor    %esi,%esi
call   1060 <mus_read_any@plt>
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <close_sound_input@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mus_file2array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%r13d
mov    %rdi,%rbx
call   1090 <open_sound_input@plt>
cmp    $0xffffffff,%eax
je     11ec <mus_file2array+0x7c>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <sound_chans@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %r15d,%esi
mov    %r14d,%r15d
mov    %rax,%r14
movslq %r13d,%rax
mov    %r12,(%r14,%rax,8)
mov    %ebp,%edi
call   1070 <seek_sound_frame@plt>
mov    %ebp,%edi
xor    %esi,%esi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %r14,%r8
mov    %r14,%r9
call   1060 <mus_read_any@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close_sound_input@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
jmp    11f1 <mus_file2array+0x81>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mus_file2array(i8* %0, i32 %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32**
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32* %4, i32** %11
%16 = load i8*, i8** %7
%17 = call i32 @open_sound_input(i8* %16)
store i32 %17, i32* %12
%18 = load i32, i32* %12
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %5
store i32 -1, i32* %6
br label %47
21: ; preds = %5
%22 = load i8*, i8** %7
%23 = call i32 @sound_chans(i8* %22)
store i32 %23, i32* %13
%24 = load i32, i32* %13
%25 = call i64 @calloc(i32 %24, i32 8)
%26 = inttoptr i64 %25 to i32**
store i32** %26, i32*** %15
%27 = load i32*, i32** %11
%28 = load i32**, i32*** %15
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32*, i32** %28, i64 %30
store i32* %27, i32** %31
%32 = load i32, i32* %12
%33 = load i32, i32* %9
%34 = call i32 @seek_sound_frame(i32 %32, i32 %33)
%35 = load i32, i32* %12
%36 = load i32, i32* %13
%37 = load i32, i32* %10
%38 = load i32**, i32*** %15
%39 = load i32**, i32*** %15
%40 = bitcast i32** %39 to i32*
%41 = call i32 @mus_read_any(i32 %35, i32 0, i32 %36, i32 %37, i32** %38, i32* %40)
store i32 %41, i32* %14
%42 = load i32, i32* %12
%43 = call i32 @close_sound_input(i32 %42)
%44 = load i32**, i32*** %15
%45 = call i32 @free(i32** %44)
%46 = load i32, i32* %14
store i32 %46, i32* %6
br label %47
47: ; preds = %21, %20
%48 = load i32, i32* %6
ret i32 %48
}

LLVM IR (-O2):
define i32 @mus_file2array(i8* %0, i32 %1, i32 %2, i32 %3, i32* %4) {
%6 = tail call i32 @open_sound_input(i8* %0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %19, label %8
8: ; preds = %5
%9 = tail call i32 @sound_chans(i8* %0)
%10 = tail call i64 @calloc(i32 %9, i32 8)
%11 = inttoptr i64 %10 to i32**
%12 = sext i32 %1 to i64
%13 = getelementptr inbounds i32*, i32** %11, i64 %12
store i32* %4, i32** %13
%14 = tail call i32 @seek_sound_frame(i32 %6, i32 %2)
%15 = inttoptr i64 %10 to i32*
%16 = tail call i32 @mus_read_any(i32 %6, i32 0, i32 %9, i32 %3, i32** %11, i32* %15)
%17 = tail call i32 @close_sound_input(i32 %6)
%18 = tail call i32 @free(i32** %11)
br label %19
19: ; preds = %5, %8
%20 = phi i32 [ %16, %8 ], [ -1, %5 ]
ret i32 %20
}