#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 open_soundfile_via_fd(int, int, int *, int *, int *, long *, long);
int open_via_path(char const *, char const *, char *, char *, char **, int,
                  int);
int /*<<< orphan*/ sys_close(int);
int open_soundfile(const char *dirname, const char *filename, int headersize,
                   int *p_bytespersamp, int *p_bigendian, int *p_nchannels,
                   long *p_bytelimit, long skipframes) {
  char buf[1000], *bufptr;
  int fd, sf_fd;
  fd = open_via_path(dirname, filename, "", buf, &bufptr, 1000, 1);
  if (fd < 0)
    return (-1);
  sf_fd = open_soundfile_via_fd(fd, headersize, p_bytespersamp, p_bigendian,
                                p_nchannels, p_bytelimit, skipframes);
  if (sf_fd < 0)
    sys_close(fd);
  return (sf_fd);
}


x86 assembly (clang, -O0):
<open_soundfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x420(%rbp),%rcx
lea    0xe90(%rip),%rdx
lea    -0x428(%rbp),%r8
mov    $0x3e8,%r9d
movl   $0x1,(%rsp)
call   1030 <open_via_path@plt>
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jge    11a8 <open_soundfile+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f5 <open_soundfile+0xc5>
mov    -0x42c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    0x10(%rbp),%r9
mov    0x18(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <open_soundfile_via_fd@plt>
mov    %eax,-0x430(%rbp)
cmpl   $0x0,-0x430(%rbp)
jge    11ec <open_soundfile+0xbc>
mov    -0x42c(%rbp),%edi
call   1050 <sys_close@plt>
mov    -0x430(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_soundfile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %edx,%ebp
movl   $0x1,(%rsp)
lea    0xea8(%rip),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    $0x3e8,%r9d
call   1030 <open_via_path@plt>
test   %eax,%eax
js     11a8 <open_soundfile+0x78>
mov    %eax,%ebx
mov    0x438(%rsp),%rax
mov    0x430(%rsp),%r9
mov    %rax,(%rsp)
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <open_soundfile_via_fd@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11ad <open_soundfile+0x7d>
mov    %ebx,%edi
call   1050 <sys_close@plt>
jmp    11ad <open_soundfile+0x7d>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i32 @open_soundfile(i8* %0, i8* %1, i32 %2, i32* %3, i32* %4, i32* %5, i64* %6, i64 %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i64*
%17 = alloca i64
%18 = alloca [1000 x i8]
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
store i8* %0, i8** %10
store i8* %1, i8** %11
store i32 %2, i32* %12
store i32* %3, i32** %13
store i32* %4, i32** %14
store i32* %5, i32** %15
store i64* %6, i64** %16
store i64 %7, i64* %17
%22 = load i8*, i8** %10
%23 = load i8*, i8** %11
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %18, i64 0, i64 0
%25 = call i32 @open_via_path(i8* %22, i8* %23, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %24, i8** %19, i32 1000, i32 1)
store i32 %25, i32* %20
%26 = load i32, i32* %20
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %8
store i32 -1, i32* %9
br label %45
29: ; preds = %8
%30 = load i32, i32* %20
%31 = load i32, i32* %12
%32 = load i32*, i32** %13
%33 = load i32*, i32** %14
%34 = load i32*, i32** %15
%35 = load i64*, i64** %16
%36 = load i64, i64* %17
%37 = call i32 @open_soundfile_via_fd(i32 %30, i32 %31, i32* %32, i32* %33, i32* %34, i64* %35, i64 %36)
store i32 %37, i32* %21
%38 = load i32, i32* %21
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %29
%41 = load i32, i32* %20
%42 = call i32 @sys_close(i32 %41)
br label %43
43: ; preds = %40, %29
%44 = load i32, i32* %21
store i32 %44, i32* %9
br label %45
45: ; preds = %43, %28
%46 = load i32, i32* %9
ret i32 %46
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i32 @open_soundfile(i8* %0, i8* %1, i32 %2, i32* %3, i32* %4, i32* %5, i64* %6, i64 %7) {
%9 = alloca [1000 x i8]
%10 = alloca i8*
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%12 = bitcast i8** %10 to i8*
%13 = call i32 @open_via_path(i8* %0, i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %11, i8** %10, i32 1000, i32 1)
%14 = icmp slt i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %8
%16 = call i32 @open_soundfile_via_fd(i32 %13, i32 %2, i32* %3, i32* %4, i32* %5, i64* %6, i64 %7)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @sys_close(i32 %13)
br label %20
20: ; preds = %15, %18, %8
%21 = phi i32 [ -1, %8 ], [ %16, %18 ], [ %16, %15 ]
ret i32 %21
}