#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 /*<<< orphan*/ mus_bytes_per_sample(int);
int /*<<< orphan*/ mus_file_open_descriptors(int, char const *, int,
                                             int /*<<< orphan*/,
                                             int /*<<< orphan*/, int, int);
int mus_file_open_write(char const *);
int /*<<< orphan*/ mus_header_data_location();
int mus_header_write(char const *, int, int, int, int /*<<< orphan*/,
                     int /*<<< orphan*/, int, char const *, int);
int /*<<< orphan*/ mus_sound_forget(char const *);
int /*<<< orphan*/ mus_sound_initialize();
int strlen(char const *);
int mus_sound_open_output(const char *arg, int srate, int chans,
                          int data_format, int header_type,
                          const char *comment) {
  int fd = -1, err, comlen = 0;
  if (comment)
    comlen = strlen(comment);
  mus_sound_initialize();
  mus_sound_forget(arg);
  err = mus_header_write(arg, header_type, srate, chans, 0, 0, data_format,
                         comment, comlen);
  if (err != -1) {
    fd = mus_file_open_write(arg);
    if (fd != -1)
      mus_file_open_descriptors(fd, arg, data_format,
                                mus_bytes_per_sample(data_format),
                                mus_header_data_location(), chans, header_type);
  }
  return (fd);
}


x86 assembly (clang, -O0):
<mus_sound_open_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c2 <mus_sound_open_output+0x42>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1080 <mus_sound_initialize@plt>
mov    -0x8(%rbp),%rdi
call   1030 <mus_sound_forget@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r11d
mov    -0x20(%rbp),%r10
mov    -0x2c(%rbp),%eax
xor    %r9d,%r9d
mov    %r9d,%r8d
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   10a0 <mus_header_write@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
je     126f <mus_sound_open_output+0xef>
mov    -0x8(%rbp),%rdi
call   1070 <mus_file_open_write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     126a <mus_sound_open_output+0xea>
mov    -0x24(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <mus_bytes_per_sample@plt>
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1060 <mus_header_data_location@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    %eax,%r8d
mov    -0x10(%rbp),%r9d
mov    -0x18(%rbp),%eax
mov    %eax,(%rsp)
call   1090 <mus_file_open_descriptors@plt>
jmp    126f <mus_sound_open_output+0xef>
mov    -0x24(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mus_sound_open_output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%rbx
mov    %r8,(%rsp)
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %esi,%r13d
mov    %rdi,%rbp
test   %r9,%r9
je     11b0 <mus_sound_open_output+0x30>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
jmp    11b3 <mus_sound_open_output+0x33>
xor    %r14d,%r14d
xor    %eax,%eax
call   1080 <mus_sound_initialize@plt>
mov    %rbp,%rdi
call   1030 <mus_sound_forget@plt>
sub    $0x8,%rsp
mov    %rbp,%rdi
mov    0x8(%rsp),%rsi
mov    %r13d,%edx
mov    %r15d,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %r14
push   %rbx
push   %r12
call   10a0 <mus_header_write@plt>
add    $0x20,%rsp
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     1238 <mus_sound_open_output+0xb8>
mov    %rbp,%rdi
call   1070 <mus_file_open_write@plt>
cmp    $0xffffffff,%eax
je     1238 <mus_sound_open_output+0xb8>
mov    %eax,%r14d
mov    %r12d,%edi
call   1040 <mus_bytes_per_sample@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <mus_header_data_location@plt>
sub    $0x8,%rsp
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %r12d,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
mov    %r15d,%r9d
push   0x8(%rsp)
call   1090 <mus_file_open_descriptors@plt>
add    $0x10,%rsp
mov    %r14d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mus_sound_open_output(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%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
store i8* %5, i8** %12
store i32 -1, i32* %13
store i32 0, i32* %15
%16 = load i8*, i8** %12
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %6
%19 = load i8*, i8** %12
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %15
br label %21
21: ; preds = %18, %6
%22 = call i32 (...) @mus_sound_initialize()
%23 = load i8*, i8** %7
%24 = call i32 @mus_sound_forget(i8* %23)
%25 = load i8*, i8** %7
%26 = load i32, i32* %11
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = load i32, i32* %10
%30 = load i8*, i8** %12
%31 = load i32, i32* %15
%32 = call i32 @mus_header_write(i8* %25, i32 %26, i32 %27, i32 %28, i32 0, i32 0, i32 %29, i8* %30, i32 %31)
store i32 %32, i32* %14
%33 = load i32, i32* %14
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %51
35: ; preds = %21
%36 = load i8*, i8** %7
%37 = call i32 @mus_file_open_write(i8* %36)
store i32 %37, i32* %13
%38 = load i32, i32* %13
%39 = icmp ne i32 %38, -1
br i1 %39, label %40, label %50
40: ; preds = %35
%41 = load i32, i32* %13
%42 = load i8*, i8** %7
%43 = load i32, i32* %10
%44 = load i32, i32* %10
%45 = call i32 @mus_bytes_per_sample(i32 %44)
%46 = call i32 (...) @mus_header_data_location()
%47 = load i32, i32* %9
%48 = load i32, i32* %11
%49 = call i32 @mus_file_open_descriptors(i32 %41, i8* %42, i32 %43, i32 %45, i32 %46, i32 %47, i32 %48)
br label %50
50: ; preds = %40, %35
br label %51
51: ; preds = %50, %21
%52 = load i32, i32* %13
ret i32 %52
}

LLVM IR (-O2):
define i32 @mus_sound_open_output(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i8* %5) {
%7 = icmp eq i8* %5, null
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i32 @strlen(i8* %5)
br label %10
10: ; preds = %8, %6
%11 = phi i32 [ %9, %8 ], [ 0, %6 ]
%12 = tail call i32 (...) @mus_sound_initialize()
%13 = tail call i32 @mus_sound_forget(i8* %0)
%14 = tail call i32 @mus_header_write(i8* %0, i32 %4, i32 %1, i32 %2, i32 0, i32 0, i32 %3, i8* %5, i32 %11)
%15 = icmp eq i32 %14, -1
br i1 %15, label %23, label %16
16: ; preds = %10
%17 = tail call i32 @mus_file_open_write(i8* %0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = tail call i32 @mus_bytes_per_sample(i32 %3)
%21 = tail call i32 (...) @mus_header_data_location()
%22 = tail call i32 @mus_file_open_descriptors(i32 %17, i8* %0, i32 %3, i32 %20, i32 %21, i32 %2, i32 %4)
br label %23
23: ; preds = %16, %19, %10
%24 = phi i32 [ %17, %19 ], [ -1, %16 ], [ -1, %10 ]
ret i32 %24
}