// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/../scg.h
// Function: scg__audio_new
static scg_audio_t *scg__audio_new() {
    SDL_AudioSpec desired, obtained;

    int samples_per_sec = 48000;
    int desired_num_channels = 2;
    size_t bytes_per_sample = sizeof(int16_t) * desired_num_channels;

    memset(&desired, 0, sizeof(desired));
    desired.freq = samples_per_sec;
    desired.format = AUDIO_S16LSB;
    desired.channels = desired_num_channels;
    desired.samples = 2048;
    desired.callback = NULL;

    SDL_AudioDeviceID device_id = SDL_OpenAudioDevice(
        NULL, 0, &desired, &obtained, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
    if (device_id == 0) {
        scg_log_errorf("Failed to open SDL audio device. %s", SDL_GetError());

        return NULL;
    }

    if (obtained.format != desired.format) {
        scg_log_error("Audio device does not support format S16LSB");

        SDL_CloseAudioDevice(device_id);
        return NULL;
    }

    int obtained_frequency = obtained.freq;
    int latency_sample_count = obtained_frequency / 15;
    uint32_t buffer_size = latency_sample_count * bytes_per_sample;
    uint8_t *buffer = malloc(buffer_size);
    if (buffer == NULL) {
        scg_log_errorf("Failed to allocate memory for sound buffer. bytes=%u",
                       buffer_size);

        SDL_CloseAudioDevice(device_id);
        return NULL;
    }

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

        free(buffer);
        SDL_CloseAudioDevice(device_id);
        return NULL;
    }

    audio->device_id = device_id;
    audio->frequency = obtained_frequency;
    audio->num_channels = obtained.channels;
    audio->num_samples = obtained.samples;
    audio->bytes_per_sample = bytes_per_sample;
    audio->latency_sample_count = latency_sample_count;
    audio->buffer_size = buffer_size;
    audio->buffer = buffer;
    audio->num_sounds = 0;

    SDL_PauseAudioDevice(device_id, 0);

    return audio;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl $0xbb80, -0x4c(%rbp)    # imm = 0xBB80
movl $0x2, -0x50(%rbp)
movslq -0x50(%rbp), %rax
shlq %rax
movq %rax, -0x58(%rbp)
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2100
movl -0x4c(%rbp), %eax
movl %eax, -0x28(%rbp)
movw $0x8010, -0x24(%rbp)    # imm = 0x8010
movl -0x50(%rbp), %eax
movb %al, -0x22(%rbp)
movw $0x800, -0x20(%rbp)     # imm = 0x800
movq $0x0, -0x18(%rbp)
xorl %eax, %eax
movl %eax, %edi
xorl %esi, %esi
leaq -0x28(%rbp), %rdx
leaq -0x48(%rbp), %rcx
movl $0x2, %r8d
callq 0x22b0
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jne 0x6aaf
callq 0x2190
movq %rax, %r9
xorl %edi, %edi
leaq 0xd4b(%rip), %rsi       # 0x77d2
leaq 0xd7d(%rip), %rdx       # 0x780b
leaq 0x621(%rip), %rcx       # 0x70b6
movl $0x82a, %r8d            # imm = 0x82A
movb $0x0, %al
callq 0x22e0
movq $0x0, -0x8(%rbp)
jmp 0x6c3e
movzwl -0x44(%rbp), %eax
movzwl -0x24(%rbp), %ecx
cmpl %ecx, %eax
je 0x6afb
xorl %edi, %edi
leaq 0x5cc(%rip), %rsi       # 0x7090
leaq 0xd40(%rip), %rdx       # 0x780b
leaq 0x5e4(%rip), %rcx       # 0x70b6
movl $0x830, %r8d            # imm = 0x830
leaq 0xd3b(%rip), %r9        # 0x781a
movb $0x0, %al
callq 0x22e0
movl -0x5c(%rbp), %edi
callq 0x20d0
movq $0x0, -0x8(%rbp)
jmp 0x6c3e
movl -0x48(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl $0xf, %ecx
cltd
idivl %ecx
movl %eax, -0x64(%rbp)
movslq -0x64(%rbp), %rax
imulq -0x58(%rbp), %rax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl %eax, %edi
callq 0x22f0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x6b6d
movl -0x68(%rbp), %r9d
xorl %edi, %edi
leaq 0xd09(%rip), %rsi       # 0x7846
leaq 0xcc7(%rip), %rdx       # 0x780b
leaq 0x56b(%rip), %rcx       # 0x70b6
movl $0x83c, %r8d            # imm = 0x83C
movb $0x0, %al
callq 0x22e0
movl -0x5c(%rbp), %edi
callq 0x20d0
movq $0x0, -0x8(%rbp)
jmp 0x6c3e
movl $0xa8, %edi
callq 0x22f0
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x6bc8
xorl %edi, %edi
leaq 0x505(%rip), %rsi       # 0x7090
leaq 0xc79(%rip), %rdx       # 0x780b
leaq 0x51d(%rip), %rcx       # 0x70b6
movl $0x844, %r8d            # imm = 0x844
leaq 0xcea(%rip), %r9        # 0x7890
movb $0x0, %al
callq 0x22e0
movq -0x70(%rbp), %rdi
callq 0x2290
movl -0x5c(%rbp), %edi
callq 0x20d0
movq $0x0, -0x8(%rbp)
jmp 0x6c3e
movl -0x5c(%rbp), %ecx
movq -0x78(%rbp), %rax
movl %ecx, (%rax)
movl -0x60(%rbp), %ecx
movq -0x78(%rbp), %rax
movl %ecx, 0x4(%rax)
movb -0x42(%rbp), %cl
movq -0x78(%rbp), %rax
movb %cl, 0x8(%rax)
movw -0x40(%rbp), %cx
movq -0x78(%rbp), %rax
movw %cx, 0xa(%rax)
movq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x78(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x64(%rbp), %ecx
movq -0x78(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x68(%rbp), %ecx
movq -0x78(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x70(%rbp), %rcx
movq -0x78(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x78(%rbp), %rax
movl $0x0, 0xa0(%rax)
movl -0x5c(%rbp), %edi
xorl %esi, %esi
callq 0x22d0
movq -0x78(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)