// File: /workspace/github_cpp_makefile_star2_O2/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, %r13
leaq 0x60(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x250(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x34f0
leaq 0xc8(%rsp), %rdi
callq 0x3210
leaq 0xd8(%rsp), %rdi
leaq 0x260(%rsp), %rsi
callq 0x30a0
leaq 0x250(%rsp), %rdi
callq 0x3090
leaq 0xe0(%rsp), %rsi
leaq 0x18(%rsp), %rdi
callq 0x34e0
movq 0x18(%rsp), %rdi
callq 0x8e09
movq %rax, %rbp
leaq 0x18(%rsp), %rdi
callq 0x3618
testq %rbp, %rbp
je 0x6803
leaq 0x5ee2(%rip), %rsi      # 0xc508
movq %rbp, %rdi
callq 0x8f76
testq %rax, %rax
je 0x6820
movq %rbp, 0x8(%rsp)
movq 0x20(%rax), %rsi
leaq 0x18(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x6efa
leaq 0xbd07(%rip), %rax      # 0x12360
xorl %r12d, %r12d
leaq 0xa8(%rsp), %r15
leaq 0x38(%rsp), %rbp
movq %r13, 0x10(%rsp)
movq $0x0, (%rsp)
cmpq $0x100, %r12            # imm = 0x100
je 0x67b3
movq %r15, %rbx
movq %rax, %r14
movq -0x20(%rax), %rsi
movq 0x8(%rsp), %rdi
callq 0x8f76
testq %rax, %rax
movq %rbx, %r15
je 0x66e2
movq 0x20(%rax), %rsi
movq %r15, %rdi
movq %rbp, %rdx
callq 0x6efa
leaq 0x58(%rsp), %rdi
movq %r15, %rsi
callq 0x6f36
testq %rax, %rax
je 0x66f5
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x6f50
movzwl (%rax), %eax
movzwl (%r14), %ecx
movw %ax, 0x1000(%r13,%rcx,2)
jmp 0x6793
movzwl (%r14), %eax
andw $0x0, 0x1000(%r13,%rax,2)
jmp 0x679e
leaq 0x88(%rsp), %r15
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
leaq 0x5e44(%rip), %rdx      # 0xc550
callq 0x6ec1
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x6ea2
movq %r13, %r15
movq %r13, %rdi
movq %rbp, %rsi
movq 0x10(%rsp), %rdx
callq 0x69f2
movl %eax, %r13d
movq %rbp, %rdi
callq 0x3618
leaq 0x88(%rsp), %rdi
callq 0x3618
testb %r13b, %r13b
je 0x677d
movzwl (%r14), %eax
movq %r15, %r13
movw %r12w, 0x1000(%r15,%rax,2)
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x6f50
leaq 0x38(%rsp), %rbp
movw %r12w, (%rax)
movb $0x1, %al
movq %rax, (%rsp)
jmp 0x6793
movzwl (%r14), %eax
movq %r15, %r13
andw $0x0, 0x1000(%r15,%rax,2)
leaq 0x38(%rsp), %rbp
movq %rbx, %r15
movq %rbx, %rdi
callq 0x3618
incq %r12
addq $0x10, 0x10(%rsp)
addq $0x28, %r14
movq %r14, %rax
jmp 0x6676
leaq 0x18(%rsp), %rdi
callq 0x3618
movq 0x8(%rsp), %rdi
callq 0x881f
testb $0x1, (%rsp)
je 0x6845
leaq 0xc8(%rsp), %rdi
callq 0x3240
leaq 0x250(%rsp), %rdi
callq 0x30e0
leaq 0x58(%rsp), %rdi
callq 0x6fe2
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb7ae(%rip), %rdi      # 0x11fb8
leaq 0x5d60(%rip), %rsi      # 0xc571
callq 0x3310
movq %rax, %rdi
callq 0x3180
jmp 0x6860
movq 0xb791(%rip), %rdi      # 0x11fb8
leaq 0x5d55(%rip), %rsi      # 0xc583
callq 0x3310
movq %rax, %rdi
callq 0x3180
movq %rbp, %rdi
callq 0x881f
jmp 0x6860
movq 0xb76c(%rip), %rdi      # 0x11fb8
leaq 0x5d50(%rip), %rsi      # 0xc5a3
callq 0x3310
movq %rax, %rdi
callq 0x3180
pushq $0x1
popq %rdi
callq 0x33b0
jmp 0x687c
jmp 0x687c
jmp 0x68a6
jmp 0x687c
movq %rax, %rbx
jmp 0x68d2
movq %rax, %rbx
jmp 0x68df
jmp 0x687c
movq %rax, %rbx
jmp 0x68c5
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x3618
jmp 0x6893
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x3618
jmp 0x68ae
jmp 0x68ab
jmp 0x68a6
movq %rax, %rbx
jmp 0x68bb
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3618
leaq 0x18(%rsp), %rdi
callq 0x3618
leaq 0xc8(%rsp), %rdi
callq 0x3240
leaq 0x250(%rsp), %rdi
callq 0x30e0
leaq 0x58(%rsp), %rdi
callq 0x6fe2
movq %rbx, %rdi
callq 0x3570
nop