LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/kmp/kmp.c
// Function: kmp_char
void kmp_char(char c, char *pattern, int *pattern_pos, int *next, int *ans) {
    while (*pattern_pos != -1 && compare_char_macro(c, pattern[*pattern_pos])) {
        *pattern_pos = next[*pattern_pos];
    }
    if (!compare_char_macro(pattern[++(*pattern_pos)], '\0')) {
        ++(*ans);
        *pattern_pos =
            next[*pattern_pos - 1] + (next[*pattern_pos - 1] == 0 ? 0 : 1);
    }
}

// Assembly:
pushq %rbx
movl (%rdx), %r11d
leaq 0x4bfa(%rip), %rax      # 0x7170
movq (%rax), %r9
movslq %r11d, %r10
cmpl $-0x1, %r11d
je 0x259e
leaq 0x1(%r9), %rbx
movq %rbx, (%rax)
cmpb %dil, (%rsi,%r10)
je 0x259b
movl (%rcx,%r10,4), %r11d
movl %r11d, (%rdx)
movq %rbx, %r9
jmp 0x2579
incq %r9
incq %r9
movq %r9, (%rax)
leaq 0x1(%r10), %rax
movl %eax, (%rdx)
cmpb $0x0, 0x1(%rsi,%r10)
jne 0x25c4
incl (%r8)
movslq (%rdx), %rax
movl -0x4(%rcx,%rax,4), %eax
cmpl $0x1, %eax
sbbl $-0x1, %eax
movl %eax, (%rdx)
popq %rbx
retq
nop
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/link_list/link_list.c
// Function: lk_init
link_list *lk_init() {
    link_list *lk = mp_new(sizeof(link_list));
    lk->head = lk->tail = NULL;
    lk->length = 0;
    return lk;
}

// Assembly:
pushq %rax
pushq $0x20
popq %rdi
callq 0x232d
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andl $0x0, 0x10(%rax)
popq %rcx
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/link_list/link_list.c
// Function: lk_node
linked_node *lk_node(void *ptr) {
    linked_node *node = NULL;
    if (_link_node_unused == NULL) {
        node = mp_new(sizeof(linked_node));
    } else {
        node = _link_node_unused;
        _link_node_unused = _link_node_unused->next;
    }
    node->next = NULL;
    node->value = ptr;
    return node;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x4bb8(%rip), %rax      # 0x71a0
testq %rax, %rax
je 0x25fa
movq 0x8(%rax), %rcx
movq %rcx, 0x4ba8(%rip)      # 0x71a0
jmp 0x2602
pushq $0x10
popq %rdi
callq 0x232d
andq $0x0, 0x8(%rax)
movq %rbx, (%rax)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/link_list/link_list.c
// Function: lk_add
void lk_add(link_list *lk, void *ptr) {
    linked_node *node = lk_node(ptr);
    if (lk_empty(lk)) {
        lk->head = lk->tail = node;
    } else {
        lk->tail->next = node;
        lk->tail = node;
    }
    ++lk->length;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x25dd
movq 0x8(%rbx), %rcx
xorl %edx, %edx
movq (%rbx), %rsi
orq %rcx, %rsi
setne %dl
cmoveq %rbx, %rcx
movq %rax, 0x8(%rcx)
movq %rax, (%rbx,%rdx,8)
incl 0x10(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/link_list/link_list.c
// Function: lk_remove
void lk_remove(link_list *lk, linked_node *ptr) {
    linked_node *p = lk->head;

    if (p == ptr) {
        p = lk->head = ptr->next;
    } else {
        while (p != NULL && p->next != ptr) {
            p = p->next;
        }
        if (p != NULL && p->next == ptr) {
            p->next = ptr->next;
            --lk->length;
            ptr->next = _link_node_unused;
            _link_node_unused = ptr->next;
        }
    }
    if (lk->tail == ptr) {
        lk->tail = p;
    }
}

// Assembly:
movq (%rdi), %rcx
cmpq %rsi, %rcx
je 0x267d
testq %rcx, %rcx
je 0x2686
movq %rcx, %rax
movq 0x8(%rcx), %rcx
cmpq %rsi, %rcx
jne 0x2654
movq 0x8(%rsi), %rcx
movq %rcx, 0x8(%rax)
decl 0x10(%rdi)
movq 0x4b29(%rip), %rcx      # 0x71a0
movq %rcx, 0x8(%rsi)
jmp 0x2688
movq 0x8(%rsi), %rax
movq %rax, (%rdi)
jmp 0x2688
xorl %eax, %eax
cmpq %rsi, 0x8(%rdi)
je 0x268f
retq
movq %rax, 0x8(%rdi)
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/link_list/link_list.c
// Function: lk_search
linked_node *lk_search(link_list *lk, void *target,
                       boolean (*compare)(void *value, void *target)) {
    if (lk_empty(lk)) {
        return NULL;
    }
    linked_node *ptr = lk->head;

    while (ptr != NULL) {
        if (compare(ptr->value, target)) {
            break;
        }
        ptr = ptr->next;
    }
    return ptr;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdx, %r14
movq %rsi, %r15
movq (%rdi), %rbx
testq %rbx, %rbx
jne 0x26ae
cmpq $0x0, 0x8(%rdi)
je 0x26c6
testq %rbx, %rbx
je 0x26c6
movq (%rbx), %rdi
movq %r15, %rsi
callq *%r14
testl %eax, %eax
jne 0x26c8
movq 0x8(%rbx), %rbx
jmp 0x26ae
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r14
popq %r15
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/print/print.c
// Function: print
int print(int c, char *fmt, ...) {
    va_list args; //定义一个va_list类型的变量，用来储存单个参数
    va_start(args, fmt); //使args指向可变参数的第一个参数
    begin(c);
    int ret = vprintf(fmt, args); //必须用vprintf等带V的
    end();
    va_end(args); //结束可变参数的获取
    return ret;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %rbx
leaq 0x20(%rsp), %rsi
movq %rdx, 0x10(%rsi)
movq %rcx, 0x18(%rsi)
movq %r8, 0x20(%rsi)
movq %r9, 0x28(%rsi)
testb %al, %al
je 0x275c
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movaps %xmm3, 0x80(%rsp)
movaps %xmm4, 0x90(%rsp)
movaps %xmm5, 0xa0(%rsp)
movaps %xmm6, 0xb0(%rsp)
movaps %xmm7, 0xc0(%rsp)
movq %rsp, %r14
movq %rsi, 0x10(%r14)
leaq 0xf0(%rsp), %rax
movq %rax, 0x8(%r14)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%r14)
callq 0x26d4
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1160
movl %eax, %ebx
callq 0x26f1
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/print/print.c
// Function: print_err
int print_err(char *fmt, ...) {
    va_list args;
    va_start(args, fmt);
    begin(RED);
    int ret = vfprintf(stderr, fmt, args);
    end();
    va_end(args);
    return ret;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
leaq 0x20(%rsp), %rdi
movq %rsi, 0x8(%rdi)
movq %rdx, 0x10(%rdi)
movq %rcx, 0x18(%rdi)
movq %r8, 0x20(%rdi)
movq %r9, 0x28(%rdi)
testb %al, %al
je 0x2801
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movaps %xmm3, 0x80(%rsp)
movaps %xmm4, 0x90(%rsp)
movaps %xmm5, 0xa0(%rsp)
movaps %xmm6, 0xb0(%rsp)
movaps %xmm7, 0xc0(%rsp)
movq %rsp, %r14
movq %rdi, 0x10(%r14)
leaq 0xf0(%rsp), %rax
movq %rax, 0x8(%r14)
movabsq $0x3000000008, %rax     # imm = 0x3000000008
movq %rax, (%r14)
leaq 0x19e8(%rip), %rdi      # 0x4210
xorl %eax, %eax
callq 0x10b0
movq 0x47c2(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x11a0
movl %eax, %ebx
callq 0x26f1
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/print/print.c
// Function: print_ok
int print_ok(char *fmt, ...) {
    va_list args;
    va_start(args, fmt);
    begin(GREEN);
    int ret = vfprintf(stdout, fmt, args);
    end();
    va_end(args);
    return ret;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
leaq 0x20(%rsp), %rdi
movq %rsi, 0x8(%rdi)
movq %rdx, 0x10(%rdi)
movq %rcx, 0x18(%rdi)
movq %r8, 0x20(%rdi)
movq %r9, 0x28(%rdi)
testb %al, %al
je 0x28b9
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movaps %xmm3, 0x80(%rsp)
movaps %xmm4, 0x90(%rsp)
movaps %xmm5, 0xa0(%rsp)
movaps %xmm6, 0xb0(%rsp)
movaps %xmm7, 0xc0(%rsp)
movq %rsp, %r14
movq %rdi, 0x10(%r14)
leaq 0xf0(%rsp), %rax
movq %rax, 0x8(%r14)
movabsq $0x3000000008, %rax     # imm = 0x3000000008
movq %rax, (%r14)
leaq 0x1938(%rip), %rdi      # 0x4218
xorl %eax, %eax
callq 0x10b0
movq 0x46ea(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x11a0
movl %eax, %ebx
callq 0x26f1
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/radix_tree/radix_tree.c
// Function: rt_init
radix_tree *rt_init(int k) {
    radix_tree *rt = mp_new(sizeof(radix_tree));
    rt->k = k;
    rt->temp = bits_init();
    return rt;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %edi, %ebx
pushq $0x18
popq %rdi
callq 0x232d
movq %rax, %r14
movl %ebx, 0x8(%rax)
xorl %eax, %eax
callq 0x158c
movq %rax, 0x10(%r14)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/radix_tree/radix_tree.c
// Function: rt_add
void rt_add(radix_tree *rt, void *value, int size) {
    rt->temp->start = 0;
    rt->temp->end = size * 8;
    rt->temp->value = value;

    // printf("Add %s ", (char *)value);
    // bits_print(rt->temp);
    // printf("\n");

    rt->root = rtn_add(rt->root, rt->temp, rt->k, T);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x10(%rdi), %rax
andl $0x0, 0x8(%rax)
shll $0x3, %edx
movl %edx, 0xc(%rax)
movq %rsi, (%rax)
movq (%rdi), %rdi
movl 0x8(%rbx), %edx
leaq 0x1740(%rip), %rcx      # 0x409c
movl (%rcx), %ecx
movq %rax, %rsi
callq 0x2aa4
movq %rax, (%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/radix_tree/radix_tree.c
// Function: rt_exist
boolean rt_exist(radix_tree *rt, void *value, int size) {
    rt->temp->start = 0;
    rt->temp->end = size * 8;
    rt->temp->value = value;

    // printf("Search %s ", (char *)value);
    // bits_print(rt->temp);
    // printf("\n");

    return rtn_exist(rt->root, rt->temp, rt->k);
}

// Assembly:
movq 0x10(%rdi), %rax
andl $0x0, 0x8(%rax)
shll $0x3, %edx
movl %edx, 0xc(%rax)
movq %rsi, (%rax)
movq (%rdi), %rcx
movl 0x8(%rdi), %edx
movq %rcx, %rdi
movq %rax, %rsi
jmp 0x2be6
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/radix_tree/radix_tree_node.c
// Function: rtn_get_child_key
int rtn_get_child_key(bits *value, int prefix, int k) {
    int l = bits_len(value);
    if (prefix > l) {
        print_err("Uncepted error: prefix %d and value is ", prefix);
        bits_print(value);
        print_err("\n");
        exit(1);
    }
    int key = 0;
    for (int i = 0; i < k && i + prefix < l; ++i) {
        key = (key << 1) | bits_get(value, i + prefix);
    }
    return key;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %r14d
movl %esi, %ebp
movq %rdi, %rbx
callq 0x1757
cmpl %ebp, %eax
jl 0x2a2e
movl %eax, %r15d
xorl %r12d, %r12d
testl %r14d, %r14d
cmovlel %r12d, %r14d
subl $0x1, %r14d
jb 0x2a22
cmpl %ebp, %r15d
je 0x2a22
addl %r12d, %r12d
movq %rbx, %rdi
movl %ebp, %esi
callq 0x171c
orl %eax, %r12d
incl %ebp
jmp 0x2a03
movl %r12d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x183b(%rip), %rdi      # 0x4270
movl %ebp, %esi
xorl %eax, %eax
callq 0x27a0
movq %rbx, %rdi
callq 0x17e7
leaq 0x164a(%rip), %rdi      # 0x4097
xorl %eax, %eax
callq 0x27a0
pushq $0x1
popq %rdi
callq 0x11c0
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/radix_tree/radix_tree_node.c
// Function: rtn_init
radix_tree_node *rtn_init(int k) {
    int m = pow2(k);
    ++_radix_node_number;
    _radix_nodemem += sizeof(radix_tree_node) + sizeof(radix_tree_node *) * m;
    radix_tree_node *rtn = mp_new(sizeof(radix_tree_node));
    rtn->children = mp_new(sizeof(radix_tree_node *) * m);
    return rtn;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
callq 0x29ac
incl 0x473d(%rip)            # 0x71a8
movl 0x473f(%rip), %ecx      # 0x71b0
leal (,%rax,8), %ebx
leal (%rcx,%rax,8), %eax
addl $0x18, %eax
movl %eax, 0x472c(%rip)      # 0x71b0
pushq $0x18
popq %rdi
callq 0x232d
movq %rax, %r14
movl %ebx, %edi
callq 0x232d
movq %rax, (%r14)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/radix_tree/radix_tree_node.c
// Function: rtn_exist
boolean rtn_exist(radix_tree_node *rtn, bits *value, int k) {
    if (rtn == NULL) {
        return F;
    }
    ++compare_number;

    int prefix = bits_prefix(rtn->value, value, k);
    if (prefix != bits_len(rtn->value)) {
        return F;
    }

    if (prefix == bits_len(value) && rtn->end_of_value == T) {
        return T;
    }

    int key = rtn_get_child_key(value, prefix, k);
    value->start += prefix;

    return rtn_exist(rtn->children[key], value, k);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x149c(%rip), %rax      # 0x409c
movl (%rax), %ebx
leaq 0x4567(%rip), %r13      # 0x7170
testq %r15, %r15
je 0x2c60
incq (%r13)
movq 0x10(%r15), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x175e
movl %eax, %r12d
movq 0x10(%r15), %rdi
callq 0x1757
cmpl %eax, %r12d
jne 0x2c60
movq %r14, %rdi
callq 0x1757
cmpl %eax, %r12d
jne 0x2c44
cmpl %ebx, 0x8(%r15)
je 0x2c69
movq %r14, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x29dd
addl %r12d, 0x8(%r14)
movq (%r15), %rcx
cltq
movq (%rcx,%rax,8), %r15
jmp 0x2c09
leaq 0x1439(%rip), %rax      # 0x40a0
movl (%rax), %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/radix_tree/radix_tree_node.c
// Function: rtn_print
void rtn_print(radix_tree_node *rtn, int m) {
    if (rtn == NULL) {
        return;
    }
    printf("%p %d ", rtn, rtn->end_of_value);
    bits_print(rtn->value);
    printf("\n\t");
    for (int i = 0; i < m; ++i) {
        printf("%p ", rtn->children[i]);
    }
    printf("\n");

    for (int i = 0; i < m; ++i) {
        rtn_print(rtn->children[i], m);
    }
}

// Assembly:
testq %rdi, %rdi
je 0x2d19
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
movl 0x8(%rdi), %edx
leaq 0x15fd(%rip), %rdi      # 0x4298
movq %r14, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x10(%r14), %rdi
callq 0x17e7
leaq 0x15ea(%rip), %rdi      # 0x429f
xorl %eax, %eax
callq 0x10b0
testl %ebx, %ebx
movl $0x0, %r12d
cmovgl %ebx, %r12d
leaq 0x15d3(%rip), %r15      # 0x42a2
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x2ced
movq (%r14), %rax
movq (%rax,%r13,8), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x10b0
incq %r13
jmp 0x2cd2
pushq $0xa
popq %rdi
callq 0x1030
xorl %r15d, %r15d
cmpq %r15, %r12
je 0x2d10
movq (%r14), %rax
movq (%rax,%r15,8), %rdi
movl %ebx, %esi
callq 0x2c7a
incq %r15
jmp 0x2cf8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/sort/sort.c
// Function: sort
void sort(int l, int r, void *args, sort_compare_function compare,
          sort_swap_function swap) {
    if (l < r) {
        int left = l;
        int right = r;
        int mid = l;

        int a = compare(args, l, r), b = compare(args, l, (l + r) / 2),
            c = compare(args, (l + r) / 2, r);
        if (a == b && b == c) {
            mid = (l + r) / 2;
        } else if (a == c) {
            mid = l;
        } else {
            mid = r;
        }

        while (left < right) {
            while (left < right && mid < right &&
                   compare(args, mid, right) < 0) {
                right--;
            }
            if (left < right && mid < right) {
                swap(args, left++, right);
                mid = right;
            }
            while (left < right && left < mid && compare(args, left, mid) < 0) {
                left++;
            }
            if (left < right && left < mid) {
                swap(args, left, right--);
                mid = left;
            }
        }
        // swap(left, mid);

        // 递归调用
        sort(l, mid - 1, args, compare, swap); // 排序mid左边
        sort(mid + 1, r, args, compare, swap); // 排序mid右边
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x10(%rsp)
movq %rcx, %r14
movq %rdx, %r15
movl %esi, %ebx
movl %edi, %r12d
movq %rbx, 0x20(%rsp)
cmpl %ebx, %r12d
jge 0x2e41
movq %r15, %rdi
movl %r12d, %esi
movl %ebx, %edx
callq *%r14
movl %eax, 0x8(%rsp)
leal (%r12,%rbx), %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %eax, %r13d
movq %r15, %rdi
movl %r12d, %esi
movl %eax, %edx
movl %eax, 0x1c(%rsp)
callq *%r14
movl %eax, %ebp
movq %r15, %rdi
movl %r13d, %esi
movl %ebx, %edx
callq *%r14
movl 0x8(%rsp), %edx
movl %edx, %ecx
xorl %ebp, %ecx
xorl %eax, %ebp
cmpl %eax, %edx
movl %ebx, %r13d
cmovel %r12d, %r13d
orl %ecx, %ebp
cmovel 0x1c(%rsp), %r13d
movl %ebx, %ebp
movq %r12, 0x8(%rsp)
cmpl %ebp, %r12d
jge 0x2e18
cmpl %r13d, %r12d
movl %r13d, %ebx
cmovgl %r12d, %ebx
cmpl %ebx, %ebp
jle 0x2ddf
movq %r15, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq *%r14
testl %eax, %eax
jns 0x2dc8
decl %ebp
jmp 0x2db1
leal 0x1(%r12), %ebx
movq %r15, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq *0x10(%rsp)
movl %ebp, %r13d
movl %ebx, %r12d
cmpl %r13d, %ebp
movl %r13d, %ebx
cmovll %ebp, %ebx
cmpl %ebx, %r12d
jge 0x2da2
movq %r15, %rdi
movl %r12d, %esi
movl %r13d, %edx
callq *%r14
testl %eax, %eax
jns 0x2e02
incl %r12d
jmp 0x2de8
leal -0x1(%rbp), %ebx
movq %r15, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq *0x10(%rsp)
movl %r12d, %r13d
movl %ebx, %ebp
jmp 0x2da2
leal -0x1(%r13), %esi
movq 0x8(%rsp), %rdi
movq %r15, %rdx
movq %r14, %rcx
movq 0x10(%rsp), %r8
callq 0x2d1c
incl %r13d
movl %r13d, %r12d
movq 0x20(%rsp), %rbx
jmp 0x2d3f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/thread/thread.c
// Function: tp_new
thread_pool *tp_new(int thread_number, int mutex_number, thread_function tf) {
    thread_pool *tp = mp_new(sizeof(thread_pool));
    tp->thread_number = thread_number;
    tp->mutex_number = mutex_number;

    tp->thread_list = mp_new(sizeof(pthread_t) * thread_number);

    tp->mutex = mp_new(sizeof(pthread_mutex_t *) * mutex_number);
    for (int i = 0; i < tp->mutex_number; ++i) {
        tp->mutex[i] = mp_new(sizeof(pthread_mutex_t));
        pthread_mutex_init(tp->mutex[i], NULL);
    }

    for (int i = 0; i < tp->thread_number; ++i) {
        int ret = pthread_create(&tp->thread_list[i], NULL, tf, tp);
        if (ret != 0) {
            perror("pthread_create error:" + ret);
            exit(EXIT_FAILURE);
        }
    }

    return tp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %rbx
movl %esi, %ebp
movl %edi, %r15d
pushq $0x18
popq %rdi
callq 0x232d
movq %rax, %r14
movl %r15d, (%rax)
movl %ebp, 0x4(%rax)
shll $0x3, %r15d
movl %r15d, %edi
callq 0x232d
movq %rax, 0x8(%r14)
shll $0x3, %ebp
movl %ebp, %edi
callq 0x232d
movq %rax, 0x10(%r14)
xorl %r15d, %r15d
pushq $0x28
popq %rbp
movslq 0x4(%r14), %rax
cmpq %rax, %r15
jge 0x2ec1
movl %ebp, %edi
callq 0x232d
movq 0x10(%r14), %rcx
movq %rax, (%rcx,%r15,8)
movq 0x10(%r14), %rax
movq (%rax,%r15,8), %rdi
xorl %esi, %esi
callq 0x11f0
incq %r15
jmp 0x2e95
pushq $-0x1
popq %r15
xorl %edi, %edi
movslq (%r14), %rax
incq %r15
cmpq %rax, %r15
jge 0x2f07
leaq 0x8(%rdi), %r12
addq 0x8(%r14), %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x1170
movq %r12, %rdi
testl %eax, %eax
je 0x2ec7
cltq
leaq 0x13c1(%rip), %rdi      # 0x42b8
addq %rax, %rdi
callq 0x1190
pushq $0x1
popq %rdi
callq 0x11c0
movq %r14, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/thread/thread.c
// Function: tp_wait
void tp_wait(thread_pool *tp) {
    for (int i = 0; i < tp->thread_number; ++i) {
        int ret = pthread_join(tp->thread_list[i], NULL);
        if (ret != 0) {
            perror("pthread_join error: " + ret);
            exit(EXIT_FAILURE);
        }
    }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorl %r14d, %r14d
movslq (%rbx), %rax
cmpq %rax, %r14
jge 0x2f54
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rdi
xorl %esi, %esi
callq 0x11e0
incq %r14
testl %eax, %eax
je 0x2f1d
cltq
leaq 0x138a(%rip), %rdi      # 0x42ce
addq %rax, %rdi
callq 0x1190
pushq $0x1
popq %rdi
callq 0x11c0
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/thread/thread.c
// Function: tp_lock
void tp_lock(thread_pool *tp, int idx) {
    int ret = pthread_mutex_lock(tp->mutex[idx]);
    if (ret != 0) {
        perror("pthread_mutex_lock error: " + ret);
        exit(EXIT_FAILURE);
    }
}

// Assembly:
pushq %rax
movq 0x10(%rdi), %rax
movslq %esi, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1200
testl %eax, %eax
jne 0x2f73
popq %rax
retq
cltq
leaq 0x1367(%rip), %rdi      # 0x42e3
addq %rax, %rdi
callq 0x1190
pushq $0x1
popq %rdi
callq 0x11c0
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/thread/thread.c
// Function: tp_unlock
void tp_unlock(thread_pool *tp, int idx) {
    int ret = pthread_mutex_unlock(tp->mutex[idx]);
    if (ret != 0) {
        perror("pthread_mutex_unlock error: " + ret);
        exit(EXIT_FAILURE);
    }
}

// Assembly:
pushq %rax
movq 0x10(%rdi), %rax
movslq %esi, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1140
testl %eax, %eax
jne 0x2fa3
popq %rax
retq
cltq
leaq 0x1352(%rip), %rdi      # 0x42fe
addq %rax, %rdi
callq 0x1190
pushq $0x1
popq %rdi
callq 0x11c0
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/pattern_match/strstr/strstr.c
// Function: rollback
void rollback(int index) {
    // pos[index] = 0;
    // return;
    int     temp = 2;
    boolean end = F;
    while (!end) {
        for (int i = pos[index] - temp, p = 0;; --i, ++p) {
            if (i <= 0) {
                // match
                pos[index] = compare_char(string[i], patterns[index][p]) == 0
                                 ? p + 1
                                 : 0;
                end = T;
                break;
            }
            if (compare_char(string[i], patterns[index][p]) != 0) {
                ++temp;
                break;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x10d2(%rip), %rax      # 0x40a0
movl (%rax), %eax
movslq %edi, %rbx
leaq 0x10c2(%rip), %rcx      # 0x409c
movl (%rcx), %ecx
movl %ecx, 0x4(%rsp)
pushq $0x2
popq %r14
pushq $-0x2
popq %r15
testl %eax, %eax
jne 0x308d
movq 0x41c1(%rip), %rax      # 0x71b8
movl (%rax,%rbx,4), %eax
movl %eax, %r12d
subl %r14d, %r12d
addl %r15d, %eax
movslq %eax, %rbp
xorl %r13d, %r13d
testl %r12d, %r12d
jle 0x303e
movq 0x41ab(%rip), %rax      # 0x71c0
movsbl (%rax,%r12), %edi
movq 0x41a7(%rip), %rax      # 0x71c8
movq (%rax,%rbx,8), %rax
movsbl (%rax,%r13), %esi
callq 0x2061
testl %eax, %eax
jne 0x3080
decq %r12
incq %r13
decq %rbp
jmp 0x3009
movq 0x417b(%rip), %rax      # 0x71c0
movsbl (%rax,%rbp), %edi
movq 0x4178(%rip), %rax      # 0x71c8
movq (%rax,%rbx,8), %rax
movsbl (%rax,%r13), %esi
callq 0x2061
incl %r13d
testl %eax, %eax
movl $0x0, %eax
cmovnel %eax, %r13d
movq 0x4145(%rip), %rax      # 0x71b8
movl %r13d, (%rax,%rbx,4)
movl 0x4(%rsp), %eax
jmp 0x2fe8
incl %r14d
decl %r15d
xorl %eax, %eax
jmp 0x2fe8
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/pattern_match/strstr/strstr.c
// Function: match
void match(char c, int index) {
    if (compare_char(c, patterns[index][pos[index]++]) == 0) {
        if (compare_char('\0', patterns[index][pos[index]]) == 0) {
            ++count[index];
            rollback(index);
        }
    } else {
        rollback(index);
    }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq 0x411f(%rip), %rax      # 0x71c8
movslq %esi, %r14
movq (%rax,%r14,8), %rax
movq 0x4101(%rip), %rcx      # 0x71b8
movslq (%rcx,%r14,4), %rdx
leal 0x1(%rdx), %esi
movl %esi, (%rcx,%r14,4)
movsbl (%rax,%rdx), %esi
callq 0x2061
testl %eax, %eax
je 0x30dd
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2fbc
movq 0x40e4(%rip), %rax      # 0x71c8
movq (%rax,%r14,8), %rax
movq 0x40c9(%rip), %rcx      # 0x71b8
movslq (%rcx,%r14,4), %rcx
movsbl (%rax,%rcx), %esi
xorl %edi, %edi
callq 0x2061
testl %eax, %eax
je 0x310a
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq 0x40bf(%rip), %rax      # 0x71d0
incl (%rax,%r14,4)
jmp 0x30cf
// File: /workspace/github_c_makefile_star2_O2/OhYee[P]computer_application_programming_experiment/pattern_match/strstr/strstr.c
// Function: compare
int compare(void *args, int i, int j) {
    char **args_patterns = (char **)(((void **)args)[0]);
    int *  args_count = (int *)(((void **)args)[1]);

    int res = args_count[j] - args_count[i];
    if (res == 0) {
        res = compare_string(args_patterns[i], args_patterns[j]);
    }
    return res;
}

// Assembly:
movq 0x8(%rdi), %r8
movslq %edx, %rcx
movl (%r8,%rcx,4), %eax
movslq %esi, %rdx
subl (%r8,%rdx,4), %eax
je 0x312c
retq
movq (%rdi), %rax
movq (%rax,%rdx,8), %rdi
movq (%rax,%rcx,8), %rsi
jmp 0x206d
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/sysoff.c
// Function: main
int main(int argc, char *argv[])
{
	int memfd;
	void *mapped_base;

	memfd = open("/dev/mem", O_RDWR | O_SYNC);
	if (memfd == -1) {
		printf("Can't open /dev/mem.\n");
		exit(0);
	}

	// Map memory
	mapped_base = mmap( (void *) MEM0_BASE_ADDRESS, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, memfd, SPI_BASE_ADDRESS);
	if (mapped_base == (void *) -1) {
		printf("Can't map the memory to user space.\n");
		exit(0);
	}

	/* ----------- INSERT CODE BELOW THIS LINE ------------ */

	sys_off_tx(mapped_base);

	/* ----------- INSERT CODE ABOVE THIS LINE ------------ */

	if (munmap(mapped_base, MAP_SIZE) == -1) {
		printf("Can't unmap memory from user space.\n");
		exit(0);
	}
	close(memfd);
	return 0;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
leaq 0xdbd(%rip), %rdi       # 0x2004
movl $0x101002, %esi         # imm = 0x101002
xorl %eax, %eax
callq 0x10f0
cmpl $-0x1, %eax
je 0x12ac
movl %eax, %ebx
pushq $0x3
popq %rdx
pushq $0x11
popq %rcx
movl $0x40000000, %edi       # imm = 0x40000000
movl $0x400000, %esi         # imm = 0x400000
movl $0x64000000, %r9d       # imm = 0x64000000
movl %eax, %r8d
callq 0x1080
cmpq $-0x1, %rax
je 0x12b5
movq %rax, %r14
movq %rax, %rdi
callq 0x1549
movl $0x400000, %esi         # imm = 0x400000
movq %r14, %rdi
callq 0x10e0
cmpl $-0x1, %eax
je 0x12be
movl %ebx, %edi
callq 0x10c0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0xda2(%rip), %rdi       # 0x2055
jmp 0x12c5
leaq 0xd75(%rip), %rdi       # 0x2031
jmp 0x12c5
leaq 0xd48(%rip), %rdi       # 0x200d
callq 0x1060
xorl %edi, %edi
callq 0x1120
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/miraclelib.c
// Function: set_sample_rate_tx
void set_sample_rate_tx(double rate, void *mapped_base)
{

	uint64_t val;
	unsigned int val_msb;
	unsigned int val_lsb;

	val = (uint64_t) round(ldexp(rate/160e6,40)); // do rate calc
	val_msb = (val >> 32) & 0xFF; // upper 8 bits
	val_lsb = val & 0xFFFFFFFF; // lower 32 bits
	/*
	   printf("rate: %f\n",rate);
	   printf("val=0x%" PRIX64 "\n", val);
	   printf("MSB: 0x%X\n",val_msb);
	   printf("LSB: 0x%X\n",val_lsb);
	   */

	*((unsigned int *) (mapped_base + (MAP_SIZE - (2<<2)))) = val_lsb; // write rate val LSB to maxaddr - 2
	*((unsigned int *) (mapped_base + (MAP_SIZE - (3<<2)))) = val_msb; // write rate val MSB to maxaddr - 3
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
divsd 0xd51(%rip), %xmm0      # 0x2070
pushq $0x28
popq %rdi
callq 0x1030
callq 0x1040
cvttsd2si %xmm0, %rax
movq %rax, %rcx
subsd 0xd3c(%rip), %xmm0      # 0x2078
cvttsd2si %xmm0, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
movl %edx, 0x3ffff8(%rbx)
shrq $0x20, %rdx
movzbl %dl, %eax
movl %eax, 0x3ffff4(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/miraclelib.c
// Function: set_sig_tx
void set_sig_tx(char *filename, void *mapped_base)
{
	int wave[WAVE_SIZE];
	int N, counter;

	
	read_bin_file(filename, wave, &N);	

	// write array to FIFO memory
	for (counter = 0; counter <= N; counter = counter +1)
	{
		*((unsigned int *) (mapped_base+(counter << 2))) = wave[counter];
	}

	*((unsigned int *) (mapped_base+ (MAP_SIZE - (1<<2)))) = N; // write to maxaddr


}

// Assembly:
pushq %r14
pushq %rbx
subq $0x258018, %rsp         # imm = 0x258018
movq %rsi, %rbx
leaq 0x10(%rsp), %rsi
leaq 0xc(%rsp), %r14
movq %r14, %rdx
callq 0x13d9
movl (%r14), %eax
movslq %eax, %rcx
xorl %edx, %edx
xorl %esi, %esi
cmpq %rcx, %rsi
jg 0x13c8
movl 0x10(%rsp,%rdx), %edi
movslq %edx, %r8
movl %edi, (%rbx,%r8)
incq %rsi
addq $0x4, %rdx
jmp 0x13af
movl %eax, 0x3ffffc(%rbx)
addq $0x258018, %rsp         # imm = 0x258018
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/miraclelib.c
// Function: read_bin_file
void read_bin_file(char *filename, int *array, int *N)
{
	FILE *fp;
	int c, c1, c2, counter;
	unsigned int c3, c4;
	int Continue;

	system("mount /dev/mmcblk0p1 /mnt");        

	counter = 0;
	fp = fopen(filename, "r");
	if (fp == NULL)
	{
		printf("FILE NOT FOUND\n");
		exit(0);
	}

	Continue = 1;
	while(Continue)
	{

		c1 = fgetc(fp);
		c2 = fgetc(fp);
		c2 = c2 << 8;
		c = c1 + c2;
		c3 = c & (0x0fff);  // bitwise AND 
		c3 = c3 << 16;    // I channel
		c1 = fgetc(fp);
		c2 = fgetc(fp);
		c2 = c2 << 8;
		c  = c1 + c2;
		c4 = c & (0x0fff);  // Q channel
		c4 = c3 + c4;
		array[counter] = c4;
		counter++;

		if (feof(fp))
		{
			//printf("\n\rfeof found\n\r");
			*N = counter-2;
			Continue = 0;
		}
	}
	fclose(fp);
	system("umount /mnt");
	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0xccb(%rip), %rdi       # 0x20bf
callq 0x1090
leaq 0xdc3(%rip), %rsi       # 0x21c3
movq %r15, %rdi
callq 0x1100
testq %rax, %rax
je 0x149e
movq %rax, %r15
pushq $-0x1
popq %r13
xorl %eax, %eax
testb $0x1, %al
jne 0x147c
movq %r15, %rdi
callq 0x10b0
movl %eax, %ebp
movq %r15, %rdi
callq 0x10b0
shll $0x18, %eax
shll $0x10, %ebp
addl %eax, %ebp
andl $0xfff0000, %ebp        # imm = 0xFFF0000
movq %r15, %rdi
callq 0x10b0
movl %eax, %r12d
movq %r15, %rdi
callq 0x10b0
shll $0x8, %eax
addl %r12d, %eax
andl $0xfff, %eax            # imm = 0xFFF
orl %ebp, %eax
movl %eax, (%r14)
movq %r15, %rdi
callq 0x10d0
testl %eax, %eax
setne %al
je 0x1473
movl %r13d, (%rbx)
incl %r13d
addq $0x4, %r14
jmp 0x141a
movq %r15, %rdi
callq 0x1070
leaq 0xc7a(%rip), %rdi       # 0x2105
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1090
leaq 0xd33(%rip), %rdi       # 0x21d8
callq 0x1060
xorl %edi, %edi
callq 0x1120
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/miraclelib.c
// Function: safe_off_tx
void safe_off_tx(void *mapped_base)
{
	int pwr_supp_reg;

	pwr_supp_reg = read_reg_tx(36, mapped_base); // Get supply state
	write_reg_tx(66,0,mapped_base); // Turn off signal

	pwr_supp_reg = pwr_supp_reg | 0x1; // Turn on filter
	write_reg_tx(36,pwr_supp_reg,mapped_base);
	usleep(100000); // 100ms
	//printf("pwr_supp_reg = %d\n", pwr_supp_reg);

	pwr_supp_reg = pwr_supp_reg & 0x7; // Turn off comparator
	write_reg_tx(36,pwr_supp_reg,mapped_base);
	usleep(100000); // 100ms
	//printf("pwr_supp_reg = %d\n", pwr_supp_reg);

	pwr_supp_reg = pwr_supp_reg & 0x5; // Turn off 20V
	write_reg_tx(36,pwr_supp_reg,mapped_base);
	usleep(100000); // 100ms
	//printf("pwr_supp_reg = %d\n", pwr_supp_reg);

	pwr_supp_reg = pwr_supp_reg & 0x1; // Turn off 5V
	write_reg_tx(36,pwr_supp_reg,mapped_base);
	//printf("pwr_supp_reg = %d\n", pwr_supp_reg);
	return;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
pushq $0x24
popq %rdi
movq %rbx, %rsi
callq 0x14c2
movl %eax, %ebp
orl $0x1, %ebp
movl $0x80000024, %r14d      # imm = 0x80000024
movl %r14d, (%rbx)
movl %ebp, 0xcc(%rbx)
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1130
movl %ebp, %eax
andl $0x7, %eax
movl %r14d, (%rbx)
movl %eax, 0xcc(%rbx)
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1130
andl $0x5, %ebp
movl %r14d, (%rbx)
movl %ebp, 0xcc(%rbx)
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1130
movl %r14d, (%rbx)
movl $0x1, 0xcc(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/miraclelib.c
// Function: sys_off_tx
void sys_off_tx(void *mapped_base)
{
	int pwr_supp_reg;
	// Get current state of power supplies (pwr_supp_reg)
	pwr_supp_reg = read_reg_tx(36, mapped_base);
	//printf("pwr_supp_reg = %d\n", pwr_supp_reg);
	if (pwr_supp_reg >= 14)
	{
		printf("Turning OFF system...");
		safe_off_tx(mapped_base);
		write_reg_tx(32,0x1,mapped_base); // CS select bit
		write_reg_tx(33,0x000840,mapped_base); // Page DAC0 for TXEN control update.
		write_reg_tx(33,0x059604,mapped_base); // SPI turn on TXENx feature, but turn DAC0 off.
	
		printf("done.\n");
	}
	else if (pwr_supp_reg == 1)
	{
		printf("System is already off.\n");
	}
	else if (pwr_supp_reg == 0)
	{
		printf("CANNOT CONNECT TO MIRACLE. CHECK FMC CONNECTION,\n");
		printf("MAKE SURE MIRACLE POWER IS ON, AND TRY AGAIN.\n");
	}
	else
	{
		printf("SYSTEM IN UNDEFINED STATE\n");
		printf("SAFELY TURNING OFF...");
		safe_off_tx(mapped_base);
		printf("done.\n");
	}
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
pushq $0x24
popq %rdi
movq %rbx, %rsi
callq 0x14c2
cmpl $0xe, %eax
jl 0x1585
leaq 0xbad(%rip), %rdi       # 0x2111
xorl %eax, %eax
callq 0x10a0
movq %rbx, %rdi
callq 0x14d9
movl $0x80000021, (%rbx)     # imm = 0x80000021
movl $0x59604, 0xcc(%rbx)    # imm = 0x59604
jmp 0x15ce
cmpl $0x1, %eax
je 0x15a3
testl %eax, %eax
jne 0x15ac
leaq 0xcb1(%rip), %rdi       # 0x2246
callq 0x1060
leaq 0xcd6(%rip), %rdi       # 0x2277
jmp 0x15d5
leaq 0xc3d(%rip), %rdi       # 0x21e7
jmp 0x15d5
leaq 0xc73(%rip), %rdi       # 0x2226
callq 0x1060
leaq 0xb68(%rip), %rdi       # 0x2127
xorl %eax, %eax
callq 0x10a0
movq %rbx, %rdi
callq 0x14d9
leaq 0xc6b(%rip), %rdi       # 0x2240
popq %rbx
jmp 0x1060
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/miraclelib.c
// Function: sys_on_tx
void sys_on_tx(void *mapped_base)
{
	int pwr_supp_reg;
	
	pwr_supp_reg = read_reg_tx(36,mapped_base); // Check state of power supplies
	//printf("pwr_supp_reg = %d\n", pwr_supp_reg);
	if (pwr_supp_reg == 1 || pwr_supp_reg == 5) // Acceptable power states
	{
		printf("Turning ON system...");
		write_reg_tx(36,5,mapped_base); // ensure 5V supply and filter is on
		usleep(100000); // 100ms
		//printf("pwr_supp_reg = %d\n", pwr_supp_reg);
		write_reg_tx(36,7,mapped_base); // Turn on 25V supply
		usleep(100000); // 100ms
		//printf("pwr_supp_reg = %d\n", pwr_supp_reg);
		write_reg_tx(36,15,mapped_base); // Turn on comparator
		usleep(100000); // 100ms
		//printf("pwr_supp_reg = %d\n", pwr_supp_reg);
		write_reg_tx(36,14,mapped_base); // Turn off filter
		//printf("pwr_supp_reg = %d\n", pwr_supp_reg);
		
		// Enabled AD9173 output
		write_reg_tx(32,0x1,mapped_base); // CS select bit
		write_reg_tx(33,0x000840,mapped_base); // Page DAC0 for TXEN control update.
		write_reg_tx(33,0x05960C,mapped_base); // SPI turn on TXENx feature
		printf("done.\n");
	}
	else if (pwr_supp_reg == 14)
	{
		printf("System is already on.\n");
	}
	else if (pwr_supp_reg == 0) // Cannot connect to interposer
	{
		printf("CANNOT CONNECT TO MIRACLE. CHECK FMC CONNECTION,\n");
		printf("MAKE SURE MIRACLE POWER IS ON, AND TRY AGAIN.\n");
	}
	else // Weird power states.  Ideally should never get to this state
	{
		printf("SYSTEM IN UNDEFINED STATE\n");
		printf("SAFELY TURNING OFF...");
		safe_off_tx(mapped_base);
		printf("done.\n");
		printf("PLEASE TRY AGAIN.\n");
	}
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
pushq $0x24
popq %rdi
movq %rbx, %rsi
callq 0x14c2
movl %eax, %ecx
andl $-0x5, %ecx
cmpl $0x1, %ecx
jne 0x1664
leaq 0xb40(%rip), %rdi       # 0x213d
xorl %eax, %eax
callq 0x10a0
movl $0x80000024, %ebp       # imm = 0x80000024
movl %ebp, (%rbx)
movl $0x5, 0xcc(%rbx)
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1130
movl %ebp, (%rbx)
movl $0x7, 0xcc(%rbx)
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1130
movl %ebp, (%rbx)
movl $0xf, 0xcc(%rbx)
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1130
movl $0x80000021, (%rbx)     # imm = 0x80000021
movl $0x5960c, 0xcc(%rbx)    # imm = 0x5960C
leaq 0xbde(%rip), %rdi       # 0x2240
jmp 0x16c0
cmpl $0xe, %eax
je 0x1682
testl %eax, %eax
jne 0x168b
leaq 0xbd2(%rip), %rdi       # 0x2246
callq 0x1060
leaq 0xbf7(%rip), %rdi       # 0x2277
jmp 0x16c0
leaq 0xb87(%rip), %rdi       # 0x2210
jmp 0x16c0
leaq 0xb94(%rip), %rdi       # 0x2226
callq 0x1060
leaq 0xa89(%rip), %rdi       # 0x2127
xorl %eax, %eax
callq 0x10a0
movq %rbx, %rdi
callq 0x14d9
leaq 0xb8c(%rip), %rdi       # 0x2240
callq 0x1060
leaq 0xb3e(%rip), %rdi       # 0x21fe
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1060
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/miraclelib.c
// Function: stat_tx
void stat_tx(void *mapped_base)
{
	int pwr_supp_val, pwr_ctrl_val;
	double f;
	pwr_supp_val = read_reg_tx(36,mapped_base); // get system power state
	pwr_ctrl_val = read_reg_tx(66,mapped_base); // get power level
	f = get_freq_tx();
	if (pwr_supp_val == 1)
	{
		printf("System is OFF.\n");
	}
	else if (pwr_supp_val == 14)
	{
		printf("System is ON.\n"); 
		printf("Power level (0-32767): %d\n", pwr_ctrl_val);
		printf("TX frequency: %.0lf\n", f);
	}
	else if (pwr_supp_val == 0) // cannot connect to interposer
	{
		printf("CANNOT CONNECT TO MIRACLE. CHECK FMC CONNECTION,\n");
		printf("MAKE SURE MIRACLE POWER IS ON, AND TRY AGAIN.\n");
	}
	else // should never get to this, but just in case turn off safely
	{
		printf("SYSTEM IN UNDEFINED STATE\n");
		printf("SAFELY TURNING OFF...");
		safe_off_tx(mapped_base);
		printf("done.\n");
	}
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
pushq $0x24
popq %rdi
movq %rbx, %rsi
callq 0x14c2
movl %eax, %r14d
pushq $0x42
popq %rdi
movq %rbx, %rsi
callq 0x14c2
movl %eax, %ebp
callq 0x1b5a
testl %r14d, %r14d
je 0x174e
cmpl $0xe, %r14d
je 0x1710
cmpl $0x1, %r14d
jne 0x1763
leaq 0xba5(%rip), %rdi       # 0x22b3
jmp 0x178c
leaq 0xb8e(%rip), %rdi       # 0x22a5
movsd %xmm0, 0x8(%rsp)
callq 0x1060
leaq 0xa29(%rip), %rdi       # 0x2152
movl %ebp, %esi
xorl %eax, %eax
callq 0x10a0
leaq 0xa34(%rip), %rdi       # 0x216d
movsd 0x8(%rsp), %xmm0
movb $0x1, %al
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x10a0
leaq 0xaf1(%rip), %rdi       # 0x2246
callq 0x1060
leaq 0xb16(%rip), %rdi       # 0x2277
jmp 0x178c
leaq 0xabc(%rip), %rdi       # 0x2226
callq 0x1060
leaq 0x9b1(%rip), %rdi       # 0x2127
xorl %eax, %eax
callq 0x10a0
movq %rbx, %rdi
callq 0x14d9
leaq 0xab4(%rip), %rdi       # 0x2240
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x1060
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/miraclelib.c
// Function: ad9173_freq_calc
void ad9173_freq_calc(uint64_t fLO, uint64_t *A, uint64_t *B, uint64_t *X)
{
	uint64_t fDAC, c1, c2, M, N, Y; // need 64-bit computation

	fDAC = (uint64_t) 9.6e9; // needs to match AD9173 DAC frequency
	c1 = gcd(fLO,fDAC); // compute GCD of fLO and fDAC

	/* DDS modulus works using following equation:
	 * fLO/fDAC = M/N
	 *          = (X + A/B)/(2^48)
	 */

	M =  fLO/c1; // compute rational fraction M/N
	N = fDAC/c1;

	*X = (M << 48)/N; // Computer integer X
	Y = (M << 48) - (*X)*N; // Compute remainder y
	c2 = gcd(Y,N);
	*A = Y/c2; // Compute A/B modulus
	*B = N/c2;

	//printf("X=0x%" PRIX64 "\n", *X);
	//printf("A=0x%" PRIX64 "\n", *A);
	//printf("B=0x%" PRIX64 "\n", *B);
}

// Assembly:
movq %rdx, %r8
movabsq $0x23c346000, %r10      # imm = 0x23C346000
movq %rdi, %r9
testq %r10, %r10
je 0x17d4
movq %r9, %rax
xorl %edx, %edx
divq %r10
movq %r10, %r9
movq %rdx, %r10
jmp 0x17bf
movq %rdi, %rax
xorl %edx, %edx
divq %r9
movq %rax, %r10
movabsq $0x23c346000, %rax      # imm = 0x23C346000
xorl %edx, %edx
divq %r9
movq %rax, %rdi
shlq $0x30, %r10
movq %r10, %rax
xorl %edx, %edx
divq %rdi
movq %rdx, %r9
movq %rax, (%rcx)
movq %rdx, %rcx
movq %rdi, %r10
testq %r10, %r10
je 0x181e
movq %rcx, %rax
xorl %edx, %edx
divq %r10
movq %r10, %rcx
movq %rdx, %r10
jmp 0x1809
movq %r9, %rax
xorl %edx, %edx
divq %rcx
movq %rax, (%rsi)
movq %rdi, %rax
xorl %edx, %edx
divq %rcx
movq %rax, (%r8)
retq
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/miraclelib.c
// Function: init_tx
int init_tx(void *mapped_base)
{
	int jesd_phase; // jesd phase readback value
	int done = 0; // done flag
	ad9173_resync(mapped_base); // Sync AD9173 subclass 1
	usleep(100000); //100 msec pause
	write_reg_tx(32,1,mapped_base); // CS to AD9173
	write_reg_tx(33,0x830200,mapped_base); // readback LMFC delay
	jesd_phase = read_reg_tx(34, mapped_base);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
callq 0x19fa
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1130
movl $0x80000021, (%rbx)     # imm = 0x80000021
movl $0x830200, 0xcc(%rbx)   # imm = 0x830200
pushq $0x22
popq %rdi
movq %rbx, %rsi
popq %rbx
jmp 0x14c2
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/miraclelib.c
// Function: set_pwr_tx
void set_pwr_tx(int pwr_ctrl_reg, void *mapped_base)
{
	// Handle boundaries
	if (pwr_ctrl_reg > 32767) 
	{
		printf("Input is too large.\n\r");
		pwr_ctrl_reg = 32767;
	}
	else if(pwr_ctrl_reg < 0)
	{
		printf("Input is too small.\n\r");
		pwr_ctrl_reg = 0;
	}

	write_reg_tx(66, pwr_ctrl_reg, mapped_base); // set power level
	printf("Power is set to: %d\n", pwr_ctrl_reg);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
cmpl $0x7fff, %edi           # imm = 0x7FFF
jle 0x1ade
movl $0x7fff, %ebx           # imm = 0x7FFF
leaq 0x6a6(%rip), %rdi       # 0x2182
jmp 0x1aed
movl %edi, %ebx
testl %edi, %edi
jns 0x1af4
xorl %ebx, %ebx
leaq 0x6ab(%rip), %rdi       # 0x2198
xorl %eax, %eax
callq 0x10a0
movl $0x80000042, (%r14)     # imm = 0x80000042
movl %ebx, 0xcc(%r14)
leaq 0x6a5(%rip), %rdi       # 0x21ae
movl %ebx, %esi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x10a0
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/miraclelib.c
// Function: on_tx
void on_tx(void *mapped_base)
{
	int pwr_supp_reg;
	// Check state of power supplies
	pwr_supp_reg = read_reg_tx(36,mapped_base);
	if (pwr_supp_reg == 14)
	{
		write_reg_tx(66,32767,mapped_base); // signal gain max
	}
	else
	{
		printf("Supplies not in proper condition\n");
	}

}

// Assembly:
pushq %rbx
movq %rdi, %rbx
pushq $0x24
popq %rdi
movq %rbx, %rsi
callq 0x14c2
cmpl $0xe, %eax
jne 0x1b3f
movl $0x80000042, (%rbx)     # imm = 0x80000042
movl $0x7fff, 0xcc(%rbx)     # imm = 0x7FFF
popq %rbx
retq
leaq 0x77c(%rip), %rdi       # 0x22c2
popq %rbx
jmp 0x1060
// File: /workspace/github_c_makefile_star2_O2/eridanhq[P]miraclelib/miraclelib.c
// Function: set_freq_tx
void set_freq_tx(double fLO_in, void *mapped_base)
{
	int tab_line, fLO_mhz;
	char cmd_buff[50];
	uint64_t fLO;

	fLO = (uint64_t) fLO_in;

	if (fLO > 3700e6) // if input freq is too high, set to 3000
	{
		printf("Freq is too large, calibrating to 3700\n");
		fLO = 3700e6;
	}
	else if (fLO < 600e6) // if input freq is too low, set to 200
	{
		printf("Freq is too small, calibrating to 600\n");
		fLO = 600e6;
	}
	fLO_mhz = (int) (fLO/1e6);
	tab_line = (fLO_mhz+12)/25-24; // calculate line in air param matrix 

	//printf("fLO_mhz: %d\n", fLO_mhz);
	//printf("tab_line: %d\n", tab_line);

	write_reg_tx(64, tab_line, mapped_base); // calibrate
	ad9173_freq(fLO, mapped_base);

	//printf("A=0x%" PRIx64 "\n", A);
	sprintf(cmd_buff, "echo %lf > FLO", fLO_in);
	system(cmd_buff);
	return;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movl $0xdc898500, %r14d      # imm = 0xDC898500
cvttsd2si %xmm0, %rax
movq %rax, %rcx
movapd %xmm0, (%rsp)
subsd 0x4be(%rip), %xmm0      # 0x2078
cvttsd2si %xmm0, %rdi
sarq $0x3f, %rcx
andq %rcx, %rdi
orq %rax, %rdi
cmpq %r14, %rdi
jbe 0x1bd7
leaq 0x734(%rip), %rdi       # 0x2309
jmp 0x1bed
cmpq $0x23c345ff, %rdi       # imm = 0x23C345FF
ja 0x1bf5
movl $0x23c34600, %r14d      # imm = 0x23C34600
leaq 0x6f6(%rip), %rdi       # 0x22e3
callq 0x1060
movq %r14, %rdi
cvtsi2sd %rdi, %xmm0
divsd 0x47e(%rip), %xmm0      # 0x2080
cvttsd2si %xmm0, %eax
addl $0xc, %eax
pushq $0x19
popq %rcx
cltd
idivl %ecx
addl $-0x18, %eax
movl $0x80000040, (%rbx)     # imm = 0x80000040
movl %eax, 0xcc(%rbx)
movq %rbx, %rsi
callq 0x1835
leaq 0x59c(%rip), %rsi       # 0x21c9
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movaps (%rsp), %xmm0
movb $0x1, %al
callq 0x1110
movq %rbx, %rdi
callq 0x1090
addq $0x48, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/norx6441v2/ref/caesar.c
// Function: crypto_aead_encrypt
int crypto_aead_encrypt(
    unsigned char *c, unsigned long long *clen,
    const unsigned char *m, unsigned long long mlen,
    const unsigned char *ad, unsigned long long adlen,
    const unsigned char *nsec,
    const unsigned char *npub,
    const unsigned char *k
    )
{
    size_t outlen = 0;
    norx_aead_encrypt(c, &outlen, ad, adlen, m, mlen, NULL, 0, npub, k);
    *clen = outlen;
    (void)nsec; /* avoid warning */
    return 0;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq %rcx, %rax
movq %rdx, %r10
movq %rsi, %rbx
vmovups 0x48(%rsp), %xmm0
leaq 0x20(%rsp), %r14
andq $0x0, (%r14)
vmovups %xmm0, 0x10(%rsp)
vxorps %xmm0, %xmm0, %xmm0
vmovups %xmm0, (%rsp)
movq %r14, %rsi
movq %r8, %rdx
movq %r9, %rcx
movq %r10, %r8
movq %rax, %r9
callq 0x1030
movq (%r14), %rax
movq %rax, (%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/norx6441v2/ref/caesar.c
// Function: crypto_aead_decrypt
int crypto_aead_decrypt(
    unsigned char *m, unsigned long long *mlen,
    unsigned char *nsec,
    const unsigned char *c, unsigned long long clen,
    const unsigned char *ad, unsigned long long adlen,
    const unsigned char *npub,
    const unsigned char *k
    )
{
    size_t outlen = 0;
    int result = norx_aead_decrypt(m, &outlen, ad, adlen, c, clen, NULL, 0, npub, k);
    *mlen = outlen;
    (void)nsec; /* avoid warning */
    return result;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq %r9, %rdx
movq %r8, %r9
movq %rcx, %r8
movq %rsi, %rbx
movq 0x40(%rsp), %rcx
vmovups 0x48(%rsp), %xmm0
leaq 0x20(%rsp), %r14
andq $0x0, (%r14)
vmovups %xmm0, 0x10(%rsp)
vxorps %xmm0, %xmm0, %xmm0
vmovups %xmm0, (%rsp)
movq %r14, %rsi
callq 0x1050
movq (%r14), %rcx
movq %rcx, (%rbx)
addq $0x28, %rsp
popq %rbx
popq %r14
retq
nop