// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/../scg.h
// Function: scg_sound_new_from_wav
scg_sound_t *scg_sound_new_from_wav(scg_audio_t *audio, const char *filepath,
                                    bool loop) {
    if (audio->num_sounds == SCG__MAX_SOUNDS) {
        scg_log_error("Maximum sounds reached");

        return NULL;
    }

    SDL_AudioSpec spec;
    uint32_t length;
    uint8_t *buffer;

    if (SDL_LoadWAV(filepath, &spec, &buffer, &length) == NULL) {
        scg_log_errorf("Failed to load WAV file at %s. %s", filepath,
                       SDL_GetError());

        return NULL;
    }

    scg_sound_t *sound = malloc(sizeof(*sound));
    if (sound == NULL) {
        scg_log_error("Failed to allocate memory for sound");

        SDL_FreeWAV(buffer);
        return NULL;
    }

    sound->sdl_spec = spec;
    sound->length = length;
    sound->buffer = buffer;
    sound->play_offset = 0;
    sound->end_position = buffer + length;
    sound->is_playing = false;
    sound->loop = loop;

    audio->sounds[audio->num_sounds++] = sound;

    return sound;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x10, 0xa0(%rax)
jne 0x480c
xorl %edi, %edi
leaq 0x28b3(%rip), %rsi      # 0x7090
leaq 0x2af9(%rip), %rdx      # 0x72dd
leaq 0x28cb(%rip), %rcx      # 0x70b6
movl $0x51a, %r8d            # imm = 0x51A
leaq 0x2afc(%rip), %r9       # 0x72f4
movb $0x0, %al
callq 0x22e0
movq $0x0, -0x8(%rbp)
jmp 0x4970
movq -0x18(%rbp), %rdi
leaq 0x28fa(%rip), %rsi      # 0x7111
callq 0x20e0
movq %rax, %rdi
movl $0x1, %esi
leaq -0x40(%rbp), %rdx
leaq -0x50(%rbp), %rcx
leaq -0x44(%rbp), %r8
callq 0x2090
cmpq $0x0, %rax
jne 0x4881
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
callq 0x2190
movq -0x60(%rbp), %r9
xorl %edi, %edi
leaq 0x2ab6(%rip), %rsi      # 0x730b
leaq 0x2a81(%rip), %rdx      # 0x72dd
leaq 0x2853(%rip), %rcx      # 0x70b6
movl $0x525, %r8d            # imm = 0x525
movq %rax, (%rsp)
movb $0x0, %al
callq 0x22e0
movq $0x0, -0x8(%rbp)
jmp 0x4970
movl $0x50, %edi
callq 0x22f0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x48d7
xorl %edi, %edi
leaq 0x27f1(%rip), %rsi      # 0x7090
leaq 0x2a37(%rip), %rdx      # 0x72dd
leaq 0x2809(%rip), %rcx      # 0x70b6
movl $0x52c, %r8d            # imm = 0x52C
leaq 0x2a88(%rip), %r9       # 0x7342
movb $0x0, %al
callq 0x22e0
movq -0x50(%rbp), %rdi
callq 0x2310
movq $0x0, -0x8(%rbp)
jmp 0x4970
movq -0x58(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x20(%rax)
movl -0x44(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x50(%rbp), %rcx
movl -0x44(%rbp), %eax
addq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x58(%rbp), %rax
movb $0x0, 0x48(%rax)
movb -0x19(%rbp), %cl
movq -0x58(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x49(%rax)
movq -0x58(%rbp), %rdx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movl 0xa0(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0xa0(%rsi)
movslq %ecx, %rcx
movq %rdx, 0x20(%rax,%rcx,8)
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)