// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/../scg.h
// Function: scg__audio_update
static void scg__audio_update(scg_audio_t *audio) {
    memset(audio->buffer, 0, audio->buffer_size);

    uint32_t target_queue_bytes = audio->buffer_size;
    uint32_t bytes_to_write =
        target_queue_bytes - SDL_GetQueuedAudioSize(audio->device_id);

    for (int i = 0; i < audio->num_sounds; i++) {
        scg_sound_t *sound = audio->sounds[i];

        if (!sound->is_playing) {
            continue;
        }

        const uint8_t *current_play_position =
            sound->buffer + sound->play_offset;
        const uint32_t remaining_bytes_to_play =
            sound->length - sound->play_offset;

        if (current_play_position >= sound->end_position) {
            if (!sound->loop) {
                sound->is_playing = false;
            }

            sound->play_offset = 0;
        } else {
            uint32_t bytes_to_mix = (bytes_to_write > remaining_bytes_to_play)
                                        ? remaining_bytes_to_play
                                        : bytes_to_write;

            SDL_MixAudioFormat(audio->buffer, current_play_position,
                               AUDIO_S16LSB, bytes_to_mix, SCG__MAX_VOLUME / 2);

            sound->play_offset += bytes_to_mix;
        }
    }

    SDL_QueueAudio(audio->device_id, audio->buffer, bytes_to_write);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2100
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %edi
callq 0x21b0
movl %eax, %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xa0(%rcx), %eax
jge 0x59ff
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq 0x20(%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
testb $0x1, 0x48(%rax)
jne 0x5953
jmp 0x59f1
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x20(%rbp), %rcx
movl 0x38(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x20(%rbp), %rcx
subl 0x38(%rcx), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jb 0x59a7
movq -0x20(%rbp), %rax
testb $0x1, 0x49(%rax)
jne 0x599a
movq -0x20(%rbp), %rax
movb $0x0, 0x48(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x38(%rax)
jmp 0x59ef
movl -0x10(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jbe 0x59b7
movl -0x2c(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x59bd
movl -0x10(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movl -0x30(%rbp), %ecx
movl $0x8010, %edx           # imm = 0x8010
movl $0x40, %r8d
callq 0x2260
movl -0x30(%rbp), %ecx
movq -0x20(%rbp), %rax
addl 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
jmp 0x59f1
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x5920
movq -0x8(%rbp), %rax
movl (%rax), %edi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movl -0x10(%rbp), %edx
callq 0x23c0
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)