#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 */
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int mus_file_close(int);
char *mus_file_fd_name(int);
int mus_file_header_type(int);
int /*<<< orphan*/ mus_header_change_data_size(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mus_sound_forget(char *);
char *strdup(char *);
int mus_sound_close_output(int fd, off_t bytes_of_data) {
  char *name;
  name = mus_file_fd_name(fd);
  if (name) {
    int err = -1, old_type;
    char *fname;
    fname = strdup(name);
    old_type = mus_file_header_type(fd);
    err = mus_file_close(fd);
    mus_sound_forget(fname);
    mus_header_change_data_size(fname, old_type, bytes_of_data);
    free(fname);
    return (err);
  }
  return (-1);
}


x86 assembly (clang, -O0):
<mus_sound_close_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <mus_file_fd_name@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11eb <mus_sound_close_output+0x7b>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <mus_file_header_type@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1090 <mus_file_close@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <mus_sound_forget@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1070 <mus_header_change_data_size@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f2 <mus_sound_close_output+0x82>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mus_sound_close_output>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebp
call   1060 <mus_file_fd_name@plt>
test   %rax,%rax
je     11c6 <mus_sound_close_output+0x56>
mov    %rax,%rdi
call   1080 <strdup@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1050 <mus_file_header_type@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1090 <mus_file_close@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <mus_sound_forget@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1070 <mus_header_change_data_size@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    11cb <mus_sound_close_output+0x5b>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mus_sound_close_output(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
%10 = load i32, i32* %4
%11 = call i8* @mus_file_fd_name(i32 %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %30
14: ; preds = %2
store i32 -1, i32* %7
%15 = load i8*, i8** %6
%16 = call i8* @strdup(i8* %15)
store i8* %16, i8** %9
%17 = load i32, i32* %4
%18 = call i32 @mus_file_header_type(i32 %17)
store i32 %18, i32* %8
%19 = load i32, i32* %4
%20 = call i32 @mus_file_close(i32 %19)
store i32 %20, i32* %7
%21 = load i8*, i8** %9
%22 = call i32 @mus_sound_forget(i8* %21)
%23 = load i8*, i8** %9
%24 = load i32, i32* %8
%25 = load i32, i32* %5
%26 = call i32 @mus_header_change_data_size(i8* %23, i32 %24, i32 %25)
%27 = load i8*, i8** %9
%28 = call i32 @free(i8* %27)
%29 = load i32, i32* %7
store i32 %29, i32* %3
br label %31
30: ; preds = %2
store i32 -1, i32* %3
br label %31
31: ; preds = %30, %14
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
define i32 @mus_sound_close_output(i32 %0, i32 %1) {
%3 = tail call i8* @mus_file_fd_name(i32 %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = tail call i8* @strdup(i8* %3)
%7 = tail call i32 @mus_file_header_type(i32 %0)
%8 = tail call i32 @mus_file_close(i32 %0)
%9 = tail call i32 @mus_sound_forget(i8* %6)
%10 = tail call i32 @mus_header_change_data_size(i8* %6, i32 %7, i32 %1)
%11 = tail call i32 @free(i8* %6)
br label %12
12: ; preds = %2, %5
%13 = phi i32 [ %8, %5 ], [ -1, %2 ]
ret i32 %13
}