// File: /workspace/github_cpp_makefile_star2_O3/fgheng[P]keysound/src/Audio.cc
// Function: Audio::from_json(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void Audio::from_json(const std::string &str) {
    // json
    std::map<std::string, uint16_t> a_map;
    bool has_file = false;

    std::ifstream f(str);
    std::stringstream json_buf;
    json_buf << f.rdbuf();
    f.close();

    cJSON *root = cJSON_Parse(json_buf.str().c_str());

    if (!root) {
        std::cout << "parse json failed" << std::endl;
        exit(EXIT_FAILURE);
    }

    cJSON *item;
    item = cJSON_GetObjectItem(root, "dir");
    if (item) {
        std::string wav_dir = std::string(item->valuestring);

        for (int i = 0; i < 256; i++) {
            item = cJSON_GetObjectItem(root, KEYS[i].first.c_str());

            if (!item) {
                datas[KEYS[i].second] = 0;
                continue;
            }

            std::string wav_name = std::string(item->valuestring);

            // 已经读取过该音频了	The audio has already been read
            if (a_map.count(wav_name) > 0) {
                datas[KEYS[i].second] = a_map[wav_name];
                continue;
            }

            // if (wav_datas[i].data) continue;

            if (read_wav(wav_dir + "/" + wav_name, wav_datas[i])) {
                datas[KEYS[i].second] = i;
                a_map[wav_name] = i;
                has_file = true;
            } else {
                datas[KEYS[i].second] = 0;
            }
        }
    } else {
        std::cout << "you must add a dir item in json" << std::endl;
        cJSON_Delete(root);
        exit(EXIT_FAILURE);
    }
    cJSON_Delete(root);

    if (!has_file) {
        std::cout << "no wav file read success" << std::endl;
        exit(EXIT_FAILURE);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %rdi, 0x8(%rsp)
leaq 0xa0(%rsp), %r12
movl $0x0, (%r12)
xorl %eax, %eax
movq %rax, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
movq %rax, 0x20(%r12)
leaq 0x250(%rsp), %rdi
movl $0x8, %edx
callq 0x3550
leaq 0xc8(%rsp), %rdi
callq 0x3250
leaq 0xd8(%rsp), %rdi
leaq 0x260(%rsp), %rsi
callq 0x30b0
leaq 0x250(%rsp), %rdi
callq 0x30a0
leaq 0xe0(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x3540
movq 0x10(%rsp), %rdi
callq 0x9fc3
movq %rax, %rbp
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x74ab
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3390
testq %rbp, %rbp
je 0x7760
leaq 0x6f3a(%rip), %rsi      # 0xe3f5
movq %rbp, %rdi
callq 0xa155
testq %rax, %rax
je 0x7786
movq 0x20(%rax), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x7c6e
leaq 0xbe9a(%rip), %r13      # 0x13380
xorl %r14d, %r14d
leaq 0x78(%rsp), %r15
movq 0x8(%rsp), %rbx
movq $0x0, 0x50(%rsp)
movq -0x20(%r13), %rsi
movq %rbp, %rdi
callq 0xa155
testq %rax, %rax
je 0x755d
movq 0x20(%rax), %rsi
movq %r15, %rdi
leaq 0x30(%rsp), %rdx
callq 0x7c6e
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x7ed8
cmpq %r12, %rax
je 0x7576
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x7cac
movzwl (%rax), %eax
movzwl (%r13), %ecx
movq 0x8(%rsp), %rdx
movw %ax, 0x1000(%rdx,%rcx,2)
jmp 0x76aa
movzwl (%r13), %eax
movq 0x8(%rsp), %rcx
movw $0x0, 0x1000(%rcx,%rax,2)
jmp 0x76cc
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %r12
movq %r12, %rdi
callq 0x7e42
movq %r12, %rdi
leaq 0x6e99(%rip), %rsi      # 0xe43d
callq 0x3630
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq %r12, %rdi
callq 0x3110
leaq 0x40(%rsp), %rsi
movq %rsi, 0x30(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x75e6
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x75ec
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0x79fe
movl %eax, %r12d
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x7635
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x7651
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3390
testb %r12b, %r12b
je 0x768e
movzwl (%r13), %eax
movq 0x8(%rsp), %rcx
movw %r14w, 0x1000(%rcx,%rax,2)
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x7cac
leaq 0xa0(%rsp), %r12
movw %r14w, (%rax)
movb $0x1, %al
movq %rax, 0x50(%rsp)
jmp 0x76aa
movzwl (%r13), %eax
movq 0x8(%rsp), %rcx
movw $0x0, 0x1000(%rcx,%rax,2)
leaq 0xa0(%rsp), %r12
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x76cc
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3390
incq %r14
addq $0x10, %rbx
addq $0x28, %r13
cmpq $0x100, %r14            # imm = 0x100
jne 0x74fc
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x7700
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3390
movq %rbp, %rdi
callq 0x9c1f
testb $0x1, 0x50(%rsp)
je 0x77b4
movq 0xb876(%rip), %rsi      # 0x12f90
leaq 0xc8(%rsp), %rdi
callq 0x3280
leaq 0x148(%rsp), %rdi
callq 0x3130
leaq 0x250(%rsp), %rdi
callq 0x30e0
leaq 0x98(%rsp), %rdi
callq 0x7d34
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb859(%rip), %rdi      # 0x12fc0
leaq 0x6cf0(%rip), %rsi      # 0xe45e
movl $0x11, %edx
callq 0x33d0
movq 0xb841(%rip), %rdi      # 0x12fc0
callq 0x31a0
jmp 0x77d8
movq 0xb833(%rip), %rdi      # 0x12fc0
leaq 0x6cdc(%rip), %rsi      # 0xe470
movl $0x1f, %edx
callq 0x33d0
movq 0xb81b(%rip), %rdi      # 0x12fc0
callq 0x31a0
movq %rbp, %rdi
callq 0x9c1f
jmp 0x77d8
movq 0xb805(%rip), %rdi      # 0x12fc0
leaq 0x6cce(%rip), %rsi      # 0xe490
movl $0x18, %edx
callq 0x33d0
movq 0xb7ed(%rip), %rdi      # 0x12fc0
callq 0x31a0
movl $0x1, %edi
callq 0x3410
jmp 0x780b
jmp 0x780b
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
jmp 0x788f
jmp 0x780b
movq %rax, %rbx
jmp 0x78c2
movq %rax, %rbx
jmp 0x78cf
jmp 0x780b
movq %rax, %rbx
jmp 0x78a1
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x7839
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0x7839
jmp 0x7836
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x7863
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3390
jmp 0x7863
jmp 0x7860
jmp 0x785b
movq %rax, %rbx
jmp 0x7885
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x7885
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x78a1
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3390
movq 0xb6e8(%rip), %rsi      # 0x12f90
leaq 0xc8(%rsp), %rdi
callq 0x3280
leaq 0x148(%rsp), %rdi
callq 0x3130
leaq 0x250(%rsp), %rdi
callq 0x30e0
leaq 0x98(%rsp), %rdi
callq 0x7d34
movq %rbx, %rdi
callq 0x35e0