#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*/ initialize_sndlib();
int /*<<< orphan*/ mus_format2bytes(int);
int /*<<< orphan*/ mus_header_data_location();
int mus_open_write(char *);
int /*<<< orphan*/ mus_set_file_descriptors(int, int, int /*<<< orphan*/,
                                            int /*<<< orphan*/, int, int);
int mus_write_header(char *, int, int, int, int /*<<< orphan*/,
                     int /*<<< orphan*/, int, char *, int);
int /*<<< orphan*/ save_header_name(int, char *);
int /*<<< orphan*/ set_audio_error(int);
int strlen(char *);
int open_sound_output(char *arg, int srate, int chans, int data_format,
                      int header_type, char *comment) {
  int fd = 0, err, comlen = 0;
  if (comment)
    comlen = strlen(comment);
  set_audio_error(0);
  initialize_sndlib();
  err = mus_write_header(arg, header_type, srate, chans, 0, 0, data_format,
                         comment, comlen);
  if (err != -1) {
    fd = mus_open_write(arg);
    mus_set_file_descriptors(fd, data_format, mus_format2bytes(data_format),
                             mus_header_data_location(), chans, header_type);
    save_header_name(fd, arg);
  } else
    set_audio_error(17);
  return (fd);
}


x86 assembly (clang, -O0):
<open_sound_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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   $0x0,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d2 <open_sound_output+0x42>
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x2c(%rbp)
xor    %edi,%edi
call   1060 <set_audio_error@plt>
mov    $0x0,%al
call   1090 <initialize_sndlib@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   10b0 <mus_write_header@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
je     1270 <open_sound_output+0xe0>
mov    -0x8(%rbp),%rdi
call   1050 <mus_open_write@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <mus_format2bytes@plt>
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1080 <mus_header_data_location@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    %eax,%ecx
mov    -0x10(%rbp),%r8d
mov    -0x18(%rbp),%r9d
call   10a0 <mus_set_file_descriptors@plt>
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <save_header_name@plt>
jmp    127a <open_sound_output+0xea>
mov    $0x11,%edi
call   1060 <set_audio_error@plt>
mov    -0x24(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_sound_output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%rbp
mov    %r8d,%r12d
mov    %rcx,0x10(%rsp)
mov    %edx,0xc(%rsp)
mov    %esi,%r14d
mov    %rdi,%r13
test   %r9,%r9
je     11c5 <open_sound_output+0x35>
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %eax,%r15d
jmp    11c8 <open_sound_output+0x38>
xor    %r15d,%r15d
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <set_audio_error@plt>
xor    %eax,%eax
call   1090 <initialize_sndlib@plt>
sub    $0x8,%rsp
mov    %r13,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
mov    0x14(%rsp),%r14d
mov    %r14d,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %r15
push   %rbp
mov    0x28(%rsp),%rbp
push   %rbp
call   10b0 <mus_write_header@plt>
add    $0x20,%rsp
cmp    $0xffffffff,%eax
je     1245 <open_sound_output+0xb5>
mov    %r13,%rdi
call   1050 <mus_open_write@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <mus_format2bytes@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1080 <mus_header_data_location@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %eax,%ecx
mov    %r14d,%r8d
mov    %r12d,%r9d
call   10a0 <mus_set_file_descriptors@plt>
mov    %ebx,%edi
mov    %r13,%rsi
call   1040 <save_header_name@plt>
jmp    124f <open_sound_output+0xbf>
mov    $0x11,%edi
call   1060 <set_audio_error@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @open_sound_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 0, 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 @set_audio_error(i32 0)
%23 = call i32 (...) @initialize_sndlib()
%24 = load i8*, i8** %7
%25 = load i32, i32* %11
%26 = load i32, i32* %8
%27 = load i32, i32* %9
%28 = load i32, i32* %10
%29 = load i8*, i8** %12
%30 = load i32, i32* %15
%31 = call i32 @mus_write_header(i8* %24, i32 %25, i32 %26, i32 %27, i32 0, i32 0, i32 %28, i8* %29, i32 %30)
store i32 %31, i32* %14
%32 = load i32, i32* %14
%33 = icmp ne i32 %32, -1
br i1 %33, label %34, label %48
34: ; preds = %21
%35 = load i8*, i8** %7
%36 = call i32 @mus_open_write(i8* %35)
store i32 %36, i32* %13
%37 = load i32, i32* %13
%38 = load i32, i32* %10
%39 = load i32, i32* %10
%40 = call i32 @mus_format2bytes(i32 %39)
%41 = call i32 (...) @mus_header_data_location()
%42 = load i32, i32* %9
%43 = load i32, i32* %11
%44 = call i32 @mus_set_file_descriptors(i32 %37, i32 %38, i32 %40, i32 %41, i32 %42, i32 %43)
%45 = load i32, i32* %13
%46 = load i8*, i8** %7
%47 = call i32 @save_header_name(i32 %45, i8* %46)
br label %50
48: ; preds = %21
%49 = call i32 @set_audio_error(i32 17)
br label %50
50: ; preds = %48, %34
%51 = load i32, i32* %13
ret i32 %51
}

LLVM IR (-O2):
define i32 @open_sound_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 @set_audio_error(i32 0)
%13 = tail call i32 (...) @initialize_sndlib()
%14 = tail call i32 @mus_write_header(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 %22, label %16
16: ; preds = %10
%17 = tail call i32 @mus_open_write(i8* %0)
%18 = tail call i32 @mus_format2bytes(i32 %3)
%19 = tail call i32 (...) @mus_header_data_location()
%20 = tail call i32 @mus_set_file_descriptors(i32 %17, i32 %3, i32 %18, i32 %19, i32 %2, i32 %4)
%21 = tail call i32 @save_header_name(i32 %17, i8* %0)
br label %24
22: ; preds = %10
%23 = tail call i32 @set_audio_error(i32 17)
br label %24
24: ; preds = %22, %16
%25 = phi i32 [ %17, %16 ], [ 0, %22 ]
ret i32 %25
}