// File: 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
movq %rsp, %rbp
subq $0x540, %rsp            # imm = 0x540
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x4b0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x93c0
movb $0x0, -0x41(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x250(%rbp), %rdi
movl $0x8, %edx
callq 0x45e0
jmp 0x7d12
leaq -0x3e8(%rbp), %rdi
callq 0x4260
jmp 0x7d20
leaq -0x3d8(%rbp), %rax
movq %rax, -0x4c0(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x45a0
movq %rax, -0x4b8(%rbp)
jmp 0x7d43
movq -0x4b8(%rbp), %rsi
movq -0x4c0(%rbp), %rdi
callq 0x40c0
jmp 0x7d58
leaq -0x250(%rbp), %rdi
callq 0x40b0
jmp 0x7d66
leaq -0x410(%rbp), %rdi
leaq -0x3e8(%rbp), %rsi
callq 0x4390
jmp 0x7d7b
leaq -0x410(%rbp), %rdi
callq 0x4170
movq %rax, %rdi
callq 0xea90
movq %rax, -0x4c8(%rbp)
jmp 0x7d98
leaq -0x410(%rbp), %rdi
callq 0x4728
movq -0x4c8(%rbp), %rax
movq %rax, -0x3f0(%rbp)
cmpq $0x0, -0x3f0(%rbp)
jne 0x7e63
movq 0x171f1(%rip), %rdi     # 0x1efb8
leaq 0xe7a3(%rip), %rsi      # 0x16571
callq 0x43a0
movq %rax, -0x4d0(%rbp)
jmp 0x7ddc
movq -0x4d0(%rbp), %rdi
movq 0x1719e(%rip), %rsi     # 0x1ef88
callq 0x4400
jmp 0x7df1
movl $0x1, %edi
callq 0x4480
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
jmp 0x836c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
jmp 0x8360
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
jmp 0x8354
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
leaq -0x410(%rbp), %rdi
callq 0x4728
jmp 0x8354
movq -0x3f0(%rbp), %rdi
leaq 0xe697(%rip), %rsi      # 0x16508
callq 0xee30
movq %rax, -0x4d8(%rbp)
jmp 0x7e7f
movq -0x4d8(%rbp), %rax
movq %rax, -0x418(%rbp)
cmpq $0x0, -0x418(%rbp)
je 0x8292
movq -0x418(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x4e8(%rbp)
leaq -0x439(%rbp), %rdi
movq %rdi, -0x4e0(%rbp)
callq 0x4680
movq -0x4e8(%rbp), %rsi
movq -0x4e0(%rbp), %rdx
leaq -0x438(%rbp), %rdi
callq 0x93e0
jmp 0x7edc
leaq -0x439(%rbp), %rdi
callq 0x4420
movl $0x0, -0x440(%rbp)
cmpl $0x100, -0x440(%rbp)    # imm = 0x100
jge 0x8273
movq -0x3f0(%rbp), %rax
movq %rax, -0x4f8(%rbp)
movslq -0x440(%rbp), %rax
leaq (%rax,%rax,4), %rcx
leaq 0x174ae(%rip), %rax     # 0x1f3d0
leaq (%rax,%rcx,8), %rdi
callq 0x4170
movq -0x4f8(%rbp), %rdi
movq %rax, %rsi
callq 0xee30
movq %rax, -0x4f0(%rbp)
jmp 0x7f43
movq -0x4f0(%rbp), %rax
movq %rax, -0x418(%rbp)
cmpq $0x0, -0x418(%rbp)
jne 0x7fc4
movq -0x4b0(%rbp), %rax
movslq -0x440(%rbp), %rdx
leaq 0x17460(%rip), %rcx     # 0x1f3d0
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movzwl 0x20(%rcx), %ecx
movw $0x0, 0x1000(%rax,%rcx,2)
jmp 0x8251
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
leaq -0x439(%rbp), %rdi
callq 0x4420
jmp 0x8354
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
jmp 0x8281
movq -0x418(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x508(%rbp)
leaq -0x461(%rbp), %rdi
movq %rdi, -0x500(%rbp)
callq 0x4680
movq -0x508(%rbp), %rsi
movq -0x500(%rbp), %rdx
leaq -0x460(%rbp), %rdi
callq 0x93e0
jmp 0x8005
leaq -0x461(%rbp), %rdi
callq 0x4420
leaq -0x40(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x9490
movq %rax, -0x510(%rbp)
jmp 0x802a
movq -0x510(%rbp), %rax
cmpq $0x0, %rax
jbe 0x80cf
leaq -0x40(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x94f0
movq %rax, -0x518(%rbp)
jmp 0x8054
movq -0x4b0(%rbp), %rax
movq -0x518(%rbp), %rcx
movw (%rcx), %dx
movslq -0x440(%rbp), %rsi
leaq 0x1735d(%rip), %rcx     # 0x1f3d0
imulq $0x28, %rsi, %rsi
addq %rsi, %rcx
movzwl 0x20(%rcx), %ecx
movw %dx, 0x1000(%rax,%rcx,2)
movl $0x4, -0x468(%rbp)
jmp 0x8235
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
leaq -0x461(%rbp), %rdi
callq 0x4420
jmp 0x8281
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
jmp 0x8265
leaq 0xe47a(%rip), %rdx      # 0x16550
leaq -0x4a8(%rbp), %rdi
leaq -0x438(%rbp), %rsi
callq 0x9340
jmp 0x80eb
leaq -0x488(%rbp), %rdi
leaq -0x4a8(%rbp), %rsi
leaq -0x460(%rbp), %rdx
callq 0x92f0
jmp 0x8107
movq -0x4b0(%rbp), %rdi
movslq -0x440(%rbp), %rax
shlq $0x4, %rax
movq %rdi, %rdx
addq %rax, %rdx
leaq -0x488(%rbp), %rsi
callq 0x8560
movb %al, -0x519(%rbp)
jmp 0x8133
leaq -0x488(%rbp), %rdi
callq 0x4728
leaq -0x4a8(%rbp), %rdi
callq 0x4728
movb -0x519(%rbp), %al
testb $0x1, %al
jne 0x815a
jmp 0x8201
movq -0x4b0(%rbp), %rax
movslq -0x440(%rbp), %rcx
movw %cx, %dx
leaq (%rcx,%rcx,4), %rsi
leaq 0x1725a(%rip), %rcx     # 0x1f3d0
movzwl 0x20(%rcx,%rsi,8), %ecx
movw %dx, 0x1000(%rax,%rcx,2)
movw -0x440(%rbp), %ax
movw %ax, -0x52a(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x94f0
movq %rax, -0x528(%rbp)
jmp 0x81aa
movq -0x528(%rbp), %rax
movw -0x52a(%rbp), %cx
movw %cx, (%rax)
movb $0x1, -0x41(%rbp)
jmp 0x822b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
jmp 0x81f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
leaq -0x488(%rbp), %rdi
callq 0x4728
leaq -0x4a8(%rbp), %rdi
callq 0x4728
jmp 0x8265
movq -0x4b0(%rbp), %rax
movslq -0x440(%rbp), %rdx
leaq 0x171ba(%rip), %rcx     # 0x1f3d0
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movzwl 0x20(%rcx), %ecx
movw $0x0, 0x1000(%rax,%rcx,2)
movl $0x0, -0x468(%rbp)
leaq -0x460(%rbp), %rdi
callq 0x4728
movl -0x468(%rbp), %eax
testl %eax, %eax
je 0x824f
jmp 0x824d
jmp 0x8251
jmp 0x8251
movl -0x440(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x440(%rbp)
jmp 0x7ef2
leaq -0x460(%rbp), %rdi
callq 0x4728
jmp 0x8281
leaq -0x438(%rbp), %rdi
callq 0x4728
jmp 0x82db
leaq -0x438(%rbp), %rdi
callq 0x4728
jmp 0x8354
movq 0x16d1f(%rip), %rdi     # 0x1efb8
leaq 0xe2e3(%rip), %rsi      # 0x16583
callq 0x43a0
movq %rax, -0x538(%rbp)
jmp 0x82ae
movq -0x538(%rbp), %rdi
movq 0x16ccc(%rip), %rsi     # 0x1ef88
callq 0x4400
jmp 0x82c3
movq -0x3f0(%rbp), %rdi
callq 0xe6c0
jmp 0x82d1
movl $0x1, %edi
callq 0x4480
movq -0x3f0(%rbp), %rdi
callq 0xe6c0
jmp 0x82e9
testb $0x1, -0x41(%rbp)
jne 0x832a
movq 0x16cc2(%rip), %rdi     # 0x1efb8
leaq 0xe2a6(%rip), %rsi      # 0x165a3
callq 0x43a0
movq %rax, -0x540(%rbp)
jmp 0x830b
movq -0x540(%rbp), %rdi
movq 0x16c6f(%rip), %rsi     # 0x1ef88
callq 0x4400
jmp 0x8320
movl $0x1, %edi
callq 0x4480
leaq -0x3e8(%rbp), %rdi
callq 0x4290
leaq -0x250(%rbp), %rdi
callq 0x40f0
leaq -0x40(%rbp), %rdi
callq 0x95d0
addq $0x540, %rsp            # imm = 0x540
popq %rbp
retq
leaq -0x3e8(%rbp), %rdi
callq 0x4290
leaq -0x250(%rbp), %rdi
callq 0x40f0
leaq -0x40(%rbp), %rdi
callq 0x95d0
movq -0x258(%rbp), %rdi
callq 0x4670
nopw %cs:(%rax,%rax)