LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/JavieW[P]CSCC69_Ext2_File-System/utilities.c
// Function: searchFileInDir
int searchFileInDir(struct ext2_inode *parentInode, char *childFileName) {
    /**
     * return inode num if childFile is found, o/w 0
     */
    struct ext2_dir_entry_2 *cur_dir_entry = NULL;
    struct ext2_dir_entry_2 *pre_dir_entry = getPreDirent(parentInode, childFileName);
    if (strcmp(childFileName, ".") == 0) {
        return ((struct ext2_dir_entry_2 *)getBlock(parentInode->i_block[0]))->inode;
    }
    else if (pre_dir_entry != NULL) {
        cur_dir_entry = (void *)pre_dir_entry + pre_dir_entry->rec_len;
        return cur_dir_entry->inode;
    } 
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %r14
callq 0x1b42
movq %rax, %rbx
leaq 0x16bd(%rip), %rsi      # 0x31c2
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x1b1f
testq %rbx, %rbx
je 0x1b35
movzwl 0x4(%rbx), %eax
addq %rbx, %rax
jmp 0x1b31
movslq 0x28(%r14), %rax
leaq 0x3586(%rip), %rcx      # 0x50b0
shlq $0xa, %rax
addq (%rcx), %rax
movl (%rax), %eax
jmp 0x1b37
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/JavieW[P]CSCC69_Ext2_File-System/utilities.c
// Function: getPreDirent
struct ext2_dir_entry_2 *getPreDirent(struct ext2_inode *parentInode, char *childFileName) {
    struct ext2_dir_entry_2 * pre_dir_entry;
    struct ext2_dir_entry_2 * cur_dir_entry;
    int total_rec_len;

    // search in direct block
    for (int i=0; i<12; i++) {
        if (parentInode->i_block[i] == 0) {
            continue;
        } else {
            pre_dir_entry = (struct ext2_dir_entry_2 *)getBlock(parentInode->i_block[i]);
            total_rec_len = pre_dir_entry->rec_len;
            cur_dir_entry = (void *) pre_dir_entry + pre_dir_entry->rec_len;
        }

        // for each dir entry in the block
        while (total_rec_len < EXT2_BLOCK_SIZE) {
            if(strcmp(cur_dir_entry->name, childFileName)==0) {
                return pre_dir_entry;
            }
            total_rec_len = total_rec_len + cur_dir_entry->rec_len;
            pre_dir_entry = cur_dir_entry;
            cur_dir_entry = (void *) cur_dir_entry + cur_dir_entry->rec_len;
        }
    }
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, -0x38(%rbp)
leaq 0x354f(%rip), %rax      # 0x50b0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
xorl %r13d, %r13d
movq -0x38(%rbp), %rax
movslq 0x28(%rax,%r13,4), %r14
testq %r14, %r14
je 0x1bd8
shlq $0xa, %r14
movq -0x30(%rbp), %rax
movzwl 0x4(%rax,%r14), %r12d
cmpq $0x3ff, %r12            # imm = 0x3FF
ja 0x1bd8
addq -0x30(%rbp), %r14
leaq (%r14,%r12), %rdi
addq $0x8, %rdi
movq %rbx, %rsi
callq 0x10c0
testl %eax, %eax
je 0x1be6
addq %r12, %r14
movzwl 0x4(%r14), %eax
addl %eax, %r12d
cmpl $0x400, %r12d           # imm = 0x400
jae 0x1bd8
movq %r14, %r15
addq %rax, %r14
leaq (%r15,%rax), %rdi
addq $0x8, %rdi
movq %rbx, %rsi
callq 0x10c0
testl %eax, %eax
jne 0x1bab
jmp 0x1be9
incq %r13
cmpq $0xc, %r13
jne 0x1b6b
xorl %r15d, %r15d
jmp 0x1be9
movq %r14, %r15
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/JavieW[P]CSCC69_Ext2_File-System/utilities.c
// Function: allocateNewDirent
struct ext2_dir_entry_2 *allocateNewDirent(struct ext2_inode *parent_inode, int size) {
    struct ext2_dir_entry_2 *new_dir_entry = NULL;
    // search in all used direct block
    for(int i = 0; i<12;i++) {
        if (parent_inode->i_block[i] != 0) {
            new_dir_entry = allocateDirentHelper(parent_inode->i_block[i], size);
            if (new_dir_entry!=NULL)
                return new_dir_entry;
        }
    }

    // if we cannot find a space, try to allocate a new block
    int newBlockNum = 0;
    for(int i = 0; i<12;i++) {
        if (parent_inode->i_block[i] != 0) continue;
        newBlockNum = allocateNewBlock();
        parent_inode->i_block[i] = newBlockNum;

        // increse parentdir size
        parent_inode->i_blocks+=(EXT2_BLOCK_SIZE+511)/512;
        parent_inode->i_size+=EXT2_BLOCK_SIZE;

        // insert dummy head
        new_dir_entry = (struct ext2_dir_entry_2 *)getBlock(newBlockNum);
        new_dir_entry->file_type = EXT2_FT_UNKNOWN;
        new_dir_entry->inode = 0;
        new_dir_entry->name_len = 0;
        new_dir_entry->rec_len = ((sizeof(struct ext2_dir_entry_2)+3)/4)*4;

        // return new setted dir_entry
        new_dir_entry = (void *)new_dir_entry + new_dir_entry->rec_len;
        new_dir_entry->rec_len=EXT2_BLOCK_SIZE-((sizeof(struct ext2_dir_entry_2)+3)/4)*4;
        return new_dir_entry;
    }
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x3491(%rip), %r14      # 0x50b0
movq (%r14), %rcx
xorl %edx, %edx
xorl %edi, %edi
movslq 0x28(%rbx,%rdx,4), %r8
testq %r8, %r8
je 0x1c7e
shlq $0xa, %r8
addq %rcx, %r8
xorl %eax, %eax
movzbl 0x6(%r8), %r9d
addl $0xc, %r9d
andl $-0x4, %r9d
movzwl 0x4(%r8), %r11d
movl %r11d, %r10d
subl %r9d, %r10d
cmpl %esi, %r10d
jge 0x1c6a
addl %r11d, %eax
movl %r11d, %r9d
addq %r9, %r8
cmpl $0x400, %eax            # imm = 0x400
jb 0x1c39
xorl %eax, %eax
jmp 0x1c79
leaq (%r8,%r9), %rax
movw %r9w, 0x4(%r8)
movw %r10w, 0x4(%r8,%r9)
testq %rax, %rax
jne 0x1c93
cmpq $0xb, %rdx
leaq 0x1(%rdx), %r8
setae %dil
movq %r8, %rdx
cmpq $0xc, %r8
jne 0x1c26
testb $0x1, %dil
je 0x1cea
xorl %eax, %eax
xorl %r15d, %r15d
cmpl $0x0, 0x28(%rbx,%r15,4)
je 0x1cb1
incq %r15
cmpq $0xc, %r15
jne 0x1c9e
jmp 0x1cea
callq 0x1a6c
movl %eax, 0x28(%rbx,%r15,4)
addl $0x2, 0x1c(%rbx)
addl $0x400, 0x4(%rbx)       # imm = 0x400
movq (%r14), %rcx
cltq
shlq $0xa, %rax
movabsq $0x800000000, %rdx      # imm = 0x800000000
addq %rcx, %rax
addq $0x8, %rax
movq %rdx, -0x8(%rax)
movw $0x3f8, 0x4(%rax)       # imm = 0x3F8
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/JavieW[P]CSCC69_Ext2_File-System/utilities.c
// Function: allocateDirentHelper
struct ext2_dir_entry_2 *allocateDirentHelper(int blockNum, int size) {
    /*
    * Helper function for initDirent
    */
    struct ext2_dir_entry_2 *dir_entry, *new_dir_entry;
    int total_rec_len, actural_len, residue_len;

    dir_entry = (struct ext2_dir_entry_2 *)getBlock(blockNum);
    total_rec_len = 0;
    while (total_rec_len < EXT2_BLOCK_SIZE) {
        // calculate residue
        actural_len = calculateActuralSize(dir_entry);
        residue_len = dir_entry->rec_len - actural_len;
        if (residue_len >= size) {
            new_dir_entry = (void *)dir_entry+actural_len;
            dir_entry->rec_len=actural_len;
            new_dir_entry->rec_len=residue_len;
            return new_dir_entry;
        }
        total_rec_len = total_rec_len + dir_entry->rec_len;
        dir_entry = (void *) dir_entry + dir_entry->rec_len;
    }
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq 0x33b0(%rip), %rax      # 0x50b0
shll $0xa, %edi
movslq %edi, %rcx
addq (%rax), %rcx
xorl %eax, %eax
xorl %edx, %edx
movzbl 0x6(%rcx), %edi
addl $0xc, %edi
andl $-0x4, %edi
movzwl 0x4(%rcx), %r9d
movl %r9d, %r8d
subl %edi, %r8d
cmpl %esi, %r8d
jge 0x1d3a
addl %r9d, %edx
movl %r9d, %edi
addq %rdi, %rcx
cmpl $0x400, %edx            # imm = 0x400
jb 0x1d0d
jmp 0x1d48
leaq (%rcx,%rdi), %rax
movw %di, 0x4(%rcx)
movw %r8w, 0x4(%rcx,%rdi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/JavieW[P]CSCC69_Ext2_File-System/utilities.c
// Function: initNewDirent
struct ext2_dir_entry_2 *initNewDirent(struct ext2_inode *parentInode, int childInodeNum, int type, char *fileName) {
    int name_len, size;
    struct ext2_dir_entry_2 *newDirent; 

    // calculate actual size required for new dir_entry
    name_len = strlen(fileName);
    size = sizeof(struct ext2_dir_entry_2) + ((name_len+4)/4)*4;

    // allocate new dir_entry in parent directory
    newDirent = allocateNewDirent(parentInode, size);
    
    // initialize new dir_entry
    newDirent->inode = childInodeNum;
    newDirent->file_type = type;
    newDirent->name_len = (unsigned char) name_len;
    strcpy(newDirent->name, fileName);
    return newDirent;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, %r12
movq %rcx, %rdi
callq 0x1060
movq %rax, %r13
addl $0x4, %eax
leal 0x7(%r13), %esi
testl %eax, %eax
cmovnsl %eax, %esi
andl $-0x4, %esi
addl $0x8, %esi
movq %r12, %rdi
callq 0x1c0b
movq %rax, %r12
movl %r15d, (%rax)
movb %r14b, 0x7(%rax)
movb %r13b, 0x6(%rax)
leaq 0x8(%rax), %rdi
movq %rbx, %rsi
callq 0x1040
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/JavieW[P]CSCC69_Ext2_File-System/utilities.c
// Function: getInodeFromPath
int getInodeFromPath(char *path) {
    /*
    * return: inodeNum of the path, 0 if path is not found or invalid
    */
    struct ext2_inode *inodeTable = getInodeTable();
    int inode_num = EXT2_ROOT_INO;
    struct ext2_inode *cur_inode = &inodeTable[inode_num-1];
    char *next_file;
    int endWithDir = path[strlen(path)-1] == '/'; // is path endwith '/' ?

    if (path[0] != '/') {
        // invalid path: absolute path startwith 
        return 0;
    }

    // travel through path
    next_file = strtok(path, "/");
    while(next_file != NULL) {
        // cannot have a non-directory type file in the middle of path
        if (!(cur_inode->i_mode & EXT2_S_IFDIR)) {
            // Invalid path; non-dir type file inside path
            return 0;
        }

        // get next inode from current directory
        inode_num = searchFileInDir(cur_inode, next_file);
        // update inode to next file with next_file
        if (inode_num != 0) {
            cur_inode = &inodeTable[inode_num-1];
        } else {
            // invalid path: file name not found
            return 0;
        }

        next_file = strtok(NULL, "/");
    }

    if (!(cur_inode->i_mode & EXT2_S_IFDIR) && endWithDir) {
        // invalid path: path endwith '/' but have a non-dir type file at the end
        return 0;
    }
    return inode_num;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
callq 0x1060
xorl %r14d, %r14d
cmpb $0x2f, (%r15)
jne 0x1e98
movb -0x1(%r15,%rax), %r13b
leaq 0x32ab(%rip), %rax      # 0x50b0
movq (%rax), %r14
movl 0x808(%r14), %r12d
shll $0xa, %r12d
leaq (%r14,%r12), %rbx
addq $0x80, %rbx
leaq 0x135b(%rip), %rsi      # 0x3180
movq %r15, %rdi
callq 0x1100
testq %rax, %rax
je 0x1e7f
movb %r13b, -0x29(%rbp)
leaq (%r14,%r12), %r13
addq $-0x80, %r13
leaq 0x133b(%rip), %r12      # 0x3180
xorl %r14d, %r14d
testb $0x40, 0x1(%rbx)
je 0x1e98
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1ae6
testl %eax, %eax
je 0x1e98
movl %eax, %r15d
movslq %eax, %rbx
shlq $0x7, %rbx
addq %r13, %rbx
xorl %edi, %edi
movq %r12, %rsi
callq 0x1100
testq %rax, %rax
jne 0x1e48
movb -0x29(%rbp), %r13b
jmp 0x1e85
movl $0x2, %r15d
xorb $0x2f, %r13b
movb 0x1(%rbx), %al
andb $0x40, %al
xorl %r14d, %r14d
orb %r13b, %al
cmovnel %r15d, %r14d
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/JavieW[P]CSCC69_Ext2_File-System/utilities.c
// Function: getFileNameFromPath
void getFileNameFromPath(char *fileName, char *path) {
    /*
    * return the last section of path into fileName
    */
    char *curr = strtok(path, "/");
    while (curr != NULL) {
        strcpy(fileName, curr);
        curr = strtok(NULL, "/");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %rax
movq %rdi, %rbx
leaq 0x12c2(%rip), %rsi      # 0x3180
movq %rax, %rdi
callq 0x1100
testq %rax, %rax
je 0x1eec
leaq 0x12ae(%rip), %r14      # 0x3180
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1040
xorl %edi, %edi
movq %r14, %rsi
callq 0x1100
testq %rax, %rax
jne 0x1ed2
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/JavieW[P]CSCC69_Ext2_File-System/utilities.c
// Function: getParentDirPath
void getParentDirPath(char *path) {
    /*
    * modify input path
    */
    assert (strcmp(path, "/")!=0);

    int len = strlen(path);
    if (path[len-1]=='/')
        path[len-1] = '\0';
    char *target = strrchr(path, '/');
    *(target+1) = '\0';
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x127f(%rip), %rsi      # 0x3180
callq 0x10c0
testl %eax, %eax
je 0x1f38
movq %rbx, %rdi
callq 0x1060
decl %eax
cltq
cmpb $0x2f, (%rbx,%rax)
jne 0x1f20
movb $0x0, (%rbx,%rax)
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x1090
movb $0x0, 0x1(%rax)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x1243(%rip), %rdi      # 0x3182
leaq 0x1251(%rip), %rsi      # 0x3197
leaq 0x1256(%rip), %rcx      # 0x31a3
movl $0x153, %edx            # imm = 0x153
callq 0x10a0
// File: /workspace/github_c_makefile_star2_O1/opencoff[P]crypto-rand/error.c
// Function: error
void
error(int doexit, int err, const char* fmt, ...)
{
    va_list ap;

    fflush(stdout);
    fflush(stderr);
    va_start(ap, fmt);
    vfprintf(stderr, fmt, ap);
    va_end(ap);

    if (err > 0)
        fprintf(stderr, "\n  %s (Errno %d)\n", strerror(err), err);

    if (doexit) {
        fflush(stderr);
        exit(1);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xd0, %rsp
movq %rdx, %r14
movl %esi, %ebp
movl %edi, %ebx
leaq 0x20(%rsp), %r12
movq %rcx, 0x18(%r12)
movq %r8, 0x20(%r12)
movq %r9, 0x28(%r12)
testb %al, %al
je 0x1195
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 0x3e3c(%rip), %rax      # 0x4fd8
movq (%rax), %rdi
callq 0x10b0
movq 0x3e4d(%rip), %r15      # 0x4ff8
movq (%r15), %rdi
callq 0x10b0
movabsq $0x3000000018, %rax     # imm = 0x3000000018
movq %rsp, %rdx
movq %rax, (%rdx)
leaq 0x100(%rsp), %rax
movq %rax, 0x8(%rdx)
movq %r12, 0x10(%rdx)
movq (%r15), %rdi
movq %r14, %rsi
callq 0x10d0
testl %ebp, %ebp
jg 0x11f6
testl %ebx, %ebx
jne 0x1218
addq $0xd0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %r14
movl %ebp, %edi
callq 0x1110
leaq 0x2014(%rip), %rsi      # 0x321b
movq %r14, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x1080
jmp 0x11e2
movq (%r15), %rdi
callq 0x10b0
pushq $0x1
popq %rdi
callq 0x10f0
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O1/opencoff[P]crypto-rand/t_aesrand.c
// Function: main
int
main(int argc, const char *argv[])
{
    crypto_rand_state st;

    int r = crypto_rand_init(&st, CRYPTO_RAND_AES, getentropy);
    assert(r == 0);

    int n = 1024;

    if (argc > 1) {
        int z = atoi(argv[1]);
        if (z <= 0) error(1, 0, "invalid size %s", argv[1]);
        n = z;
    }

    uint8_t *buf = malloc(n);
    assert(buf);

    crypto_rand_buf(&st, buf, n);

    fwrite(buf, 1, n, stdout);
    free(buf);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x530, %rsp            # imm = 0x530
movq %rsi, %r14
movl %edi, %ebp
leaq 0xee9(%rip), %rdx       # 0x221c
movq %rsp, %rdi
movl $0x1, %esi
callq 0x140c
testl %eax, %eax
jne 0x13cd
movl $0x400, %ebx            # imm = 0x400
cmpl $0x2, %ebp
jl 0x137f
movq 0x8(%r14), %rbx
movq %rbx, %rdi
callq 0x10e0
movl %eax, %ebp
testl %eax, %eax
jg 0x137c
leaq 0x1cc9(%rip), %rdx      # 0x3034
movl $0x1, %edi
xorl %esi, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1130
movslq %ebp, %rbx
movq %rbx, %rdi
callq 0x10a0
testq %rax, %rax
je 0x13ec
movq %rax, %r14
movq %rsp, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x15be
movq 0x3c34(%rip), %rax      # 0x4fd8
movq (%rax), %rcx
movl $0x1, %esi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x1100
movq %r14, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x530, %rsp            # imm = 0x530
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x1c30(%rip), %rdi      # 0x3004
leaq 0x1c30(%rip), %rsi      # 0x300b
leaq 0x1c35(%rip), %rcx      # 0x3017
movl $0x17, %edx
callq 0x1050
leaq 0x1c51(%rip), %rdi      # 0x3044
leaq 0x1c11(%rip), %rsi      # 0x300b
leaq 0x1c16(%rip), %rcx      # 0x3017
movl $0x22, %edx
callq 0x1050
nop
// File: /workspace/github_c_makefile_star2_O1/opencoff[P]crypto-rand/cryptorand.c
// Function: crypto_rand_init
int
crypto_rand_init(crypto_rand_state *st, int algo, crypto_rand_entropy_t entropy)
{
    if (!entropy) return -EINVAL;


    memset(st, 0, sizeof *st);
    st->entropy = entropy;

    switch (algo) {
        case CRYPTO_RAND_AES:
            _aes_setup(st);
            __aes_init(st);
            break;

        case CRYPTO_RAND_CHACHA20:
            _chacha_setup(st);
            __chacha_init(st);
            break;

        default:
            return -EINVAL;
    }

    // When we startup, st->buf is zero so, we're encrypting a
    // zero-buf with a random key & IV.
    _rs_rekey(st, 0, 0);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x38, %rsp
movl $0xffffffea, %ebp       # imm = 0xFFFFFFEA
testq %rdx, %rdx
je 0x1573
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %rbx
movl $0x530, %edx            # imm = 0x530
xorl %esi, %esi
callq 0x1060
movq %r14, 0x510(%rbx)
cmpl $0x2, %r15d
je 0x14a6
cmpl $0x1, %r15d
jne 0x1573
leaq 0x2ba(%rip), %rax       # 0x1711
movq %rax, 0x518(%rbx)
leaq 0x2c0(%rip), %rax       # 0x1725
movq %rax, 0x520(%rbx)
leaq 0x2e4(%rip), %rax       # 0x1757
movq %rax, 0x528(%rbx)
movq %rsp, %rdi
movl $0x30, %esi
callq *%r14
testl %eax, %eax
jne 0x1580
leaq 0x20(%rsp), %rdx
leaq 0x410(%rbx), %rdi
movq %rsp, %rsi
callq 0x1f47
jmp 0x155f
leaq 0x31d(%rip), %rax       # 0x17ca
movq %rax, 0x518(%rbx)
leaq 0x891(%rip), %rax       # 0x1d4c
movq %rax, 0x520(%rbx)
leaq 0x8b2(%rip), %rax       # 0x1d7b
movq %rax, 0x528(%rbx)
movq %rsp, %rdi
movl $0x28, %esi
callq *%r14
testl %eax, %eax
jne 0x159f
movl (%rsp), %eax
movl %eax, 0x420(%rbx)
movl 0x4(%rsp), %eax
movl %eax, 0x424(%rbx)
movl 0x8(%rsp), %eax
movl %eax, 0x428(%rbx)
movl 0xc(%rsp), %eax
movl %eax, 0x42c(%rbx)
movl 0x10(%rsp), %eax
movl %eax, 0x430(%rbx)
movl 0x14(%rsp), %eax
movl %eax, 0x434(%rbx)
movl 0x18(%rsp), %eax
movl %eax, 0x438(%rbx)
movl 0x1c(%rsp), %eax
movl %eax, 0x43c(%rbx)
movaps 0x1b17(%rip), %xmm0     # 0x3050
movups %xmm0, 0x410(%rbx)
movq $0x0, 0x440(%rbx)
movl 0x20(%rsp), %eax
movl %eax, 0x448(%rbx)
movl 0x24(%rsp), %eax
movl %eax, 0x44c(%rbx)
movq %rbx, %rdi
callq *0x518(%rbx)
movq %rbx, %rdi
callq *0x520(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a7d(%rip), %rdi      # 0x3004
leaq 0x1ad2(%rip), %rsi      # 0x3060
leaq 0x1afc(%rip), %rcx      # 0x3091
movl $0x78, %edx
callq 0x1050
leaq 0x1a5e(%rip), %rdi      # 0x3004
leaq 0x1ab3(%rip), %rsi      # 0x3060
leaq 0x1b2b(%rip), %rcx      # 0x30df
movl $0x3e, %edx
callq 0x1050
// File: /workspace/github_c_makefile_star2_O1/opencoff[P]crypto-rand/cryptorand.c
// Function: crypto_rand_buf
void
crypto_rand_buf(crypto_rand_state* st, void *buf, size_t n)
{
    uint8_t *end = st->buf + sizeof st->buf;

    _rs_stir_if_needed(st, n);
    while (n > 0) {
        size_t avail = end - st->ptr;
        if (avail > 0) {
            size_t m = minimum(n, avail);

            memcpy(buf, st->ptr, m);

            buf     += m;
            n       -= m;
            st->ptr += m;
        } else 
            _rs_rekey(st, NULL, 0);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x400(%rdi), %r13
cmpq %rdx, 0x408(%rdi)
ja 0x160b
movq %r15, %rdi
callq *0x528(%r15)
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x1060
movq %r13, 0x400(%r15)
movq $0x20000, 0x408(%r15) # imm = 0x20000
subq %rbx, 0x408(%r15)
testq %rbx, %rbx
je 0x1657
movq (%r13), %rsi
movq %r13, %r12
subq %rsi, %r12
je 0x1641
cmpq %r12, %rbx
cmovbq %rbx, %r12
movq %r14, %rdi
movq %r12, %rdx
callq 0x1090
addq %r12, %r14
subq %r12, %rbx
addq %r12, (%r13)
jmp 0x1612
movq %r15, %rdi
callq *0x518(%r15)
movq %r15, %rdi
callq *0x520(%r15)
jmp 0x1612
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/opencoff[P]crypto-rand/cryptorand.c
// Function: crypto_rand_uniform32_bounded
uint32_t
crypto_rand_uniform32_bounded(crypto_rand_state *st, uint32_t upper_bound)
{
    uint32_t r, min;

    if (upper_bound < 2)
        return 0;

    /* 2**32 % x == (2**32 - x) % x */
    min = -upper_bound % upper_bound;

    /*
     * This could theoretically loop forever but each retry has
     * p > 0.5 (worst case, usually far better) of selecting a
     * number inside the range we need, so it should rarely need
     * to re-roll.
     */
    for (;;) {
        r = crypto_rand_uniform32(st);
        if (r >= min)
            break;
    }

    return r % upper_bound;
}

// Assembly:
xorl %eax, %eax
cmpl $0x2, %esi
jb 0x16b3
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movl %esi, %eax
negl %eax
xorl %edx, %edx
divl %esi
movl %edx, %ebp
leaq 0x4(%rsp), %r15
movl $0x0, 0x4(%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x15be
movl 0x4(%rsp), %eax
cmpl %ebp, %eax
jb 0x1683
xorl %edx, %edx
divl %ebx
movl %edx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/opencoff[P]crypto-rand/cryptorand.c
// Function: crypto_rand_uniform64_bounded
uint64_t
crypto_rand_uniform64_bounded(crypto_rand_state *st, uint64_t upper_bound)
{
    uint64_t r, min;

    if (upper_bound < 2)
        return 0;

    /* 2**64 % x == (2**64 - x) % x */
    min = -upper_bound % upper_bound;

    /*
     * This could theoretically loop forever but each retry has
     * p > 0.5 (worst case, usually far better) of selecting a
     * number inside the range we need, so it should rarely need
     * to re-roll.
     */
    for (;;) {
        r = crypto_rand_uniform64(st);
        if (r >= min)
            break;
    }

    return r % upper_bound;
}

// Assembly:
cmpq $0x2, %rsi
jae 0x16bd
xorl %eax, %eax
retq
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rax
negq %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r15
movq %rsp, %r12
movq $0x0, (%rsp)
movl $0x8, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x15be
movq (%rsp), %rax
cmpq %r15, %rax
jb 0x16dc
xorl %edx, %edx
divq %rbx
movq %rdx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/opencoff[P]crypto-rand/./cipher.h
// Function: _aes_rekey
static void
__aes_rekey(crypto_rand_state *st)
{
    uint8_t rnd[AESRAND_KEYSZ + AESRAND_IVSZ];

    int r = (*st->entropy)(rnd, sizeof rnd);
    assert(r == 0);

    _rs_rekey(st, rnd, sizeof(rnd));
}

// Assembly:
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
movq %rsp, %rdi
movl $0x30, %esi
callq *0x510(%rbx)
testl %eax, %eax
jne 0x17ab
movq %rbx, %rdi
callq *0x518(%rbx)
xorl %eax, %eax
movb (%rsp,%rax), %cl
xorb %cl, (%rbx,%rax)
incq %rax
cmpq $0x30, %rax
jne 0x177c
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq %rbx, %rdi
callq *0x520(%rbx)
addq $0x30, %rsp
popq %rbx
retq
leaq 0x1852(%rip), %rdi      # 0x3004
leaq 0x18a7(%rip), %rsi      # 0x3060
leaq 0x18ab(%rip), %rcx      # 0x306b
movl $0x5b, %edx
callq 0x1050
// File: /workspace/github_c_makefile_star2_O1/opencoff[P]crypto-rand/./cipher.h
// Function: _chacha_reinit
static void
__chacha_reinit(crypto_rand_state *st)
{
    uint8_t *key = &st->buf[0];
    uint8_t *iv  = key + ARC4R_KEYSZ;

    __chacha_key_setup(st, key, iv);

    // erase the key & iv, reduce the amount of rand we have
    memset(key, 0, ARC4R_KEYSZ + ARC4R_IVSZ);
    st->ptr = st->buf + (ARC4R_KEYSZ + ARC4R_IVSZ);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
leaq 0x20(%rdi), %rdx
movq %rdi, %rsi
callq 0x1df2
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movq $0x0, 0x20(%rbx)
leaq 0x28(%rbx), %rax
movq %rax, 0x400(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/opencoff[P]crypto-rand/./cipher.h
// Function: _chacha_rekey
static void
__chacha_rekey(crypto_rand_state *st)
{
    uint8_t rnd[ARC4R_KEYSZ + ARC4R_IVSZ];

    int r = (*st->entropy)(rnd, sizeof rnd);
    assert(r == 0);

    _rs_rekey(st, rnd, sizeof(rnd));
}

// Assembly:
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
movq %rsp, %rdi
movl $0x28, %esi
callq *0x510(%rbx)
testl %eax, %eax
jne 0x1dd3
movq %rbx, %rdi
callq *0x518(%rbx)
xorl %eax, %eax
movb (%rsp,%rax), %cl
xorb %cl, (%rbx,%rax)
incq %rax
cmpq $0x28, %rax
jne 0x1da0
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq $0x0, 0x20(%rsp)
movq %rbx, %rdi
callq *0x520(%rbx)
addq $0x30, %rsp
popq %rbx
retq
leaq 0x122a(%rip), %rdi      # 0x3004
leaq 0x127f(%rip), %rsi      # 0x3060
leaq 0x12ce(%rip), %rcx      # 0x30b6
movl $0x22, %edx
callq 0x1050
// File: /workspace/github_c_makefile_star2_O1/opencoff[P]crypto-rand/posix_entropy.c
// Function: getentropy
int
getentropy(void* buf, size_t n)
{
    static int fd = -1;
    uint8_t* b    = (uint8_t*)buf;

    if (fd < 0)
        fd = randopen("/dev/urandom");

    while (n > 0)
    {
        ssize_t m = (read)(fd, b, n);

        if (m < 0) {
            if (errno == EINTR) continue;
            error(1, errno, "Fatal read error while reading rand dev");
        }
        b += m;
        n -= m;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x0, 0x2e6f(%rip)      # 0x50a0
jns 0x2270
leaq 0xff3(%rip), %rdi       # 0x322d
xorl %esi, %esi
xorl %eax, %eax
callq 0x10c0
movl %eax, %ebp
testl %eax, %eax
jns 0x226a
callq 0x1040
movl (%rax), %esi
leaq 0x100b(%rip), %rdx      # 0x3262
leaq 0xfcf(%rip), %rcx       # 0x322d
movl $0x1, %edi
xorl %eax, %eax
callq 0x1130
movl %ebp, 0x2e30(%rip)      # 0x50a0
testq %rbx, %rbx
je 0x22bb
leaq 0xfbe(%rip), %r15       # 0x323a
movl 0x2e1e(%rip), %edi      # 0x50a0
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1070
movq %rax, %r12
testq %rax, %rax
jns 0x22b0
callq 0x1040
movl (%rax), %esi
cmpl $0x4, %esi
je 0x22b6
movl $0x1, %edi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1130
addq %r12, %r14
subq %r12, %rbx
testq %rbx, %rbx
jne 0x227c
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/clunk.c
// Function: computermove
struct move computermove(struct thudboard * board)
{
    struct move move;

    puts("Thinking...");
    fflush(stdout);
    // move = iterdeepen(board, SEARCHSECS);
    move = montecarlo(board, SEARCHSECS);
    showmove(& move);

    return move;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x3d5f(%rip), %rdi      # 0x508c
callq 0x1040
movq 0x6cbf(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
callq 0x11e0
movq %r14, %rdi
movq %rbx, %rsi
movl $0x3c, %edx
callq 0x3e08
movq %r14, %rdi
callq 0x3af1
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/clunk.c
// Function: main
int main(int numargs, char * args[])
{
    struct thudboard * board = & board_data;
    struct move move;

    int memuse = 1024 * 1024 * (numargs > 1 ? strtol(args[1], NULL, 10)
                                            : sizeof(struct tableentry));

    setupgame(board, memuse);

    using_history();
    setupsides();

    int moves_since_capt = 0;
    while (moves_since_capt <= DRAW_DEADLINE)
    {
        putchar('\n');
        show(board);

        eval_count = 0;

        //time_t start = time(NULL);
        move = movefuncs[board->isdwarfturn ? DWARF : TROLL](board);
        //time_t elapsed = time(NULL) - start;
        //printf("Thinking took %d second%s.\n", elapsed, pl(elapsed));
        domoveupdatecapts(board, & move);

        //printf("evaluated %d board positions\n", eval_count);

        if (move.numcapts) moves_since_capt = 0;
        else moves_since_capt += 1;
    }

    printf("game over, final score: dwarf=%d, troll=%d\n", board->trollscaptured*4, board->dwarfscaptured);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %rax
movl $0x2000000, %esi        # imm = 0x2000000
cmpl $0x2, %edi
jl 0x1398
movq 0x8(%rax), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1100
movq %rax, %rsi
shll $0x14, %esi
leaq 0x6e59(%rip), %rbx      # 0x81f8
movq %rbx, %rdi
callq 0x1754
callq 0x1160
callq 0x1451
xorl %ebp, %ebp
leaq 0x6d56(%rip), %r13      # 0x8110
leaq 0x60(%rsp), %r14
leaq 0x8(%rsp), %r15
xorl %r12d, %r12d
movl $0xa, %edi
callq 0x1080
movq %rbx, %rdi
callq 0x3415
leaq 0x6e98(%rip), %rax      # 0x8278
movl %ebp, (%rax)
movzbl 0x6e0f(%rip), %eax      # 0x81f8
xorl $0x1, %eax
movq %r14, %rdi
movq %rbx, %rsi
callq *(%r13,%rax,8)
movl $0x16, %ecx
movq %r15, %rdi
movq %r14, %rsi
rep  movsl (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3954
incl %r12d
cmpl %ebp, 0x1c(%rsp)
cmovnel %ebp, %r12d
cmpl $0xb, %r12d
jl 0x13c7
movl 0x6e46(%rip), %esi      # 0x826c
shll $0x2, %esi
movl 0x6e39(%rip), %edx      # 0x8268
leaq 0x3bf6(%rip), %rdi      # 0x502c
xorl %eax, %eax
callq 0x1030
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/clunk.c
// Function: setupsides
void setupsides(void)
{
    char * answer;
sideagain:
    answer = readline("Would you like to play Dwarf or Troll?\n");
    if (! answer) exit(EXIT_SUCCESS);

    char c = toupper(answer[0]);
    free(answer);

    if (c == 'T') movefuncs[TROLL] = humanmove;
    else if (c == 'D') movefuncs[DWARF] = humanmove;
    else if (c == 'B') movefuncs[TROLL] = movefuncs[DWARF] = humanmove;
    else if (c == 'N') /* computer vs computer */;
    else goto sideagain;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
leaq 0x3bf8(%rip), %rbx      # 0x5058
leaq 0x3b9d(%rip), %r15      # 0x5004
movq %rbx, %rdi
callq 0x1130
testq %rax, %rax
je 0x14e7
movq %rax, %r14
callq 0x10c0
movq (%rax), %rax
movsbq (%r14), %rcx
movl (%rax,%rcx,4), %r12d
movq %r14, %rdi
callq 0x10e0
shll $0x18, %r12d
addl $0xbe000000, %r12d      # imm = 0xBE000000
roll $0x7, %r12d
cmpl $0x9, %r12d
ja 0x1467
movslq (%r15,%r12,4), %rax
addq %r15, %rax
jmpq *%rax
leaq 0x3a(%rip), %rax        # 0x14ee
movq %rax, 0x6c55(%rip)      # 0x8110
jmp 0x14d4
leaq 0x2a(%rip), %rax        # 0x14ee
movq %rax, 0x6c45(%rip)      # 0x8110
jmp 0x14db
leaq 0x1a(%rip), %rax        # 0x14ee
movq %rax, 0x6c3d(%rip)      # 0x8118
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
xorl %edi, %edi
callq 0x1070
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/clunk.c
// Function: humanmove
struct move humanmove(struct thudboard * board)
{
    struct move move;

moveagain:
    move = getmove("Your move?\n");
    if (! legalmove(board, & move))
    {
        printf("illegal move\n");
        goto moveagain;
    }

    return move;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x60, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x3b78(%rip), %rsi      # 0x5080
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x1584
movl $0x16, %ecx
movq %rbx, %rdi
movq %r15, %rsi
rep  movsl (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3544
testb %al, %al
jne 0x1573
leaq 0x3b6d(%rip), %r15      # 0x50a5
leaq 0x3b41(%rip), %r12      # 0x5080
leaq 0x8(%rsp), %r13
movq %r15, %rdi
callq 0x1040
movq %r13, %rdi
movq %r12, %rsi
callq 0x1584
movl $0x16, %ecx
movq %rbx, %rdi
movq %r13, %rsi
rep  movsl (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3544
testb %al, %al
je 0x1544
movq %rbx, %rax
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/thudlib.c
// Function: setup
void setup(struct thudboard * board)
{
    erase(board);

    board->isdwarfturn = true;
    board->captless = 0;

    for (int y=0; y < SIZE; ++y)
    {
        for (int x=0; x < SIZE; ++x)
        {
            switch (toupper(stdlayout[y][x]))
            {
            case 'D':
                placedwarf(board, (struct coord) {x,y});
                break;
            case 'T':
                placetroll(board, (struct coord) {x,y});
                break;
            case '#':
                set(board->blocks, (struct coord) {x,y});
                break;
            case '.':
                break;
            default:
                fprintf(stderr, "unknown board character\n");
                exit(1);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movups %xmm0, 0x70(%rdi)
movups %xmm0, 0x60(%rdi)
movups %xmm0, 0x50(%rdi)
movups %xmm0, 0x40(%rdi)
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movb $0x1, (%rdi)
movl $0x0, 0x78(%rdi)
xorl %r12d, %r12d
callq 0x10c0
movq %rax, %r14
leaq 0x69ac(%rip), %r13      # 0x8170
xorl %ebp, %ebp
xorl %r15d, %r15d
movq (%r14), %rax
movq (%r13,%rbp,8), %rcx
movsbq (%rcx,%r15), %rcx
movl (%rax,%rcx,4), %eax
cmpl $0x43, %eax
jg 0x17ea
cmpl $0x23, %eax
je 0x1802
cmpl $0x2e, %eax
je 0x1831
jmp 0x1863
cmpl $0x54, %eax
je 0x1813
cmpl $0x44, %eax
jne 0x1863
leaq (%r12,%r15), %rsi
movq %rbx, %rdi
callq 0x33ab
jmp 0x1831
movl $0x4000, %eax           # imm = 0x4000
movl %r15d, %ecx
shrl %cl, %eax
orw %ax, 0x3e(%rbx,%rbp,2)
jmp 0x1831
leaq (%r12,%r15), %rsi
movq %rbx, %rdi
callq 0x4470
movl $0x4000, %eax           # imm = 0x4000
movl %r15d, %ecx
shrl %cl, %eax
orw %ax, 0x20(%rbx,%rbp,2)
incl 0x60(%rbx)
incq %r15
cmpq $0xf, %r15
jne 0x17c9
incq %rbp
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r12
cmpq $0xf, %rbp
jne 0x17c6
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1200
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/thudlib.c
// Function: BROKEiterdeepen
struct move BROKEiterdeepen(struct thudboard * board, int searchtime)
{
    struct move bestmove;

    struct thudboard tempboard = * board;
    time_t stoptime = time(NULL) + searchtime;

    jmp_buf stopsearch;
    if (setjmp(stopsearch) == 0) for (int depth=1; true; depth += 1)
    {
        bestmove = zerowindow(& tempboard, depth, stoptime, stopsearch);

        //??? write to log?
        //printf("best move at depth %d: ", depth);
        //showmove(& bestmove);
    }

    return bestmove;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x150, %rsp            # imm = 0x150
movl %edx, %ebp
movq %rdi, %rbx
movq %rsp, %rdi
movl $0x10, %ecx
rep  movsq (%rsi), %es:(%rdi)
xorl %eax, %eax
movl %eax, %edi
callq 0x11d0
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0x1050
testl %eax, %eax
je 0x18b7
movq %rbx, %rax
addq $0x150, %rsp            # imm = 0x150
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movslq %ebp, %rax
addq %rax, %r14
movl $0x1, %ebp
movq %rsp, %r15
leaq 0x80(%rsp), %r12
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r14, %rcx
movq %r12, %r8
callq 0x18e4
incl %ebp
jmp 0x18cd
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/thudlib.c
// Function: zerowindow
struct move zerowindow(struct thudboard * board, int depth,
                       time_t stoptime, jmp_buf stopsearch)
{
    struct movelist list = allmoves(board);
    struct moveheap queue = heapof(board, & list);

    //??? should make sure move exists
    struct scoredmove best = popscored(& queue);

    domove(board, best.move);
    best.score = mtdf(board, depth, best.score, stoptime, stopsearch);
    undomove(board, best.move);

    while (queue.used > 0)
    {
        struct scoredmove temp = popscored(& queue);

        domove(board, temp.move);

        int result = absearch(board, depth, FULL_WIDTH,
                              best.score-1, best.score, NULL,
                              stoptime, stopsearch);

        if (result > best.score)
        {
            best = temp;
            best.score = _mtdf(board, depth,
                               result, result, INT_MAX,
                               stoptime, stopsearch);
        }

        undomove(board, temp.move);
    }

    return * best.move;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %r14
movq %rcx, %r15
movl %edx, %ebp
movq %rsi, %r12
cmpb $0x1, (%rsi)
movq %rdi, 0x20(%rsp)
movq %rsi, %rdi
jne 0x1911
callq 0x21d1
jmp 0x1916
callq 0x2500
leaq 0x38(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
movq %r12, %rdi
callq 0x2057
leaq 0x28(%rsp), %rdi
movq %rax, (%rdi)
movq %rdx, 0x8(%rdi)
callq 0x3d58
movl %eax, %ebx
movq %rdx, %r13
movq %r12, %rdi
movq %rdx, %rsi
callq 0x20ee
movq %r14, (%rsp)
movq %r12, %rdi
movl %ebp, %esi
movl %ebx, %edx
movl $0x80000000, %ecx       # imm = 0x80000000
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %r15, %r9
callq 0x2134
movl %eax, %ebx
movq %r12, %rdi
movq %r13, 0x18(%rsp)
movq %r13, %rsi
callq 0x2126
leaq 0x28(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x19f6
leaq 0x28(%rsp), %rdi
callq 0x3d58
movq %rdx, %r13
movq %r12, %rdi
movq %rdx, %rsi
callq 0x20ee
leal -0x1(%rbx), %ecx
movq %r14, 0x8(%rsp)
movq %r15, (%rsp)
movq %r12, %rdi
movl %ebp, %esi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %ebx, %r8d
xorl %r9d, %r9d
callq 0x1af4
cmpl %ebx, %eax
jle 0x19e4
movq %r14, (%rsp)
movq %r12, %rdi
movl %ebp, %esi
movl %eax, %edx
movl %eax, %ecx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %r15, %r9
callq 0x2134
movl %eax, %ebx
movq %r13, 0x18(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x2126
cmpl $0x0, 0x28(%rsp)
jg 0x1985
movl $0x16, %ecx
movq 0x20(%rsp), %rax
movq %rax, %rdi
movq 0x18(%rsp), %rsi
rep  movsl (%rsi), %es:(%rdi)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/thudlib.c
// Function: iterdeepen
struct move iterdeepen(struct thudboard * board, int searchtime)
{
    struct move bestmove;

    struct thudboard tempboard = * board;
    time_t stoptime = time(NULL) + searchtime;

    jmp_buf stopsearch;
    if (setjmp(stopsearch) == 0) for (int depth=1; true; depth += 1)
    {
        struct move move;
        absearch(& tempboard, depth, FULL_WIDTH,
                 INT_MIN, INT_MAX, & move,
                 stoptime, stopsearch);
        bestmove = move;

        // log to stderr
        fprintf(stderr, "best move at depth %d: ", depth);
        fshowmove(stderr, & bestmove);
    }

    return bestmove;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movl %edx, %ebp
movq %rdi, %rbx
leaq 0x8(%rsp), %rdi
movl $0x10, %ecx
rep  movsq (%rsi), %es:(%rdi)
xorl %eax, %eax
movl %eax, %edi
callq 0x11d0
movq %rax, %r14
leaq 0xe0(%rsp), %rdi
callq 0x1050
testl %eax, %eax
je 0x1a6e
movq %rbx, %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %ebp, %rax
addq %rax, %r14
movq %r14, (%rsp)
movl $0x1, %r14d
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
leaq 0x88(%rsp), %r13
movq 0x6555(%rip), %r15      # 0x7fe8
xorl %eax, %eax
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
movl %r14d, %esi
movl %r12d, %edx
movl $0x80000000, %ecx       # imm = 0x80000000
movl %r12d, %r8d
movq %r13, %r9
leaq 0xe0(%rsp), %rax
pushq %rax
pushq 0x8(%rsp)
callq 0x1af4
addq $0x10, %rsp
movl $0x16, %ecx
movq %rbx, %rdi
movq %r13, %rsi
rep  movsl (%rsi), %es:(%rdi)
movq (%r15), %rdi
leaq 0x3696(%rip), %rsi      # 0x5170
movl %r14d, %edx
movl %ebp, %eax
callq 0x1190
movq (%r15), %rdi
movq %rbx, %rsi
callq 0x1e52
incl %r14d
jmp 0x1a97
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/thudlib.c
// Function: fshowmove
void fshowmove(FILE * stream, struct move * move)
{
    putc(move->isdwarfmove ? 'd' : 'T', stream);
    putc(' ', stream);
    fshowpos(stream, move->from);
    fputs("-", stream);
    fshowpos(stream, move->to);
    for (int i=0; i < move->numcapts; ++i)
    {
        fputs("x", stream);
        fshowpos(stream, move->capts[i]);
    }
    putc('\n', stream);
    fflush(stream);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movzbl (%rsi), %edi
shll $0x4, %edi
addl $0x54, %edi
movq %rbx, %rsi
callq 0x1110
movl $0x20, %edi
movq %rbx, %rsi
callq 0x1110
movq 0x4(%r14), %rcx
movslq %ecx, %rax
shrq $0x20, %rcx
movq 0x6357(%rip), %rdx      # 0x81e8
movsbl (%rdx,%rax), %edx
incl %ecx
leaq 0x3397(%rip), %r15      # 0x5235
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1190
leaq 0x322b(%rip), %rdi      # 0x50dd
movq %rbx, %rsi
callq 0x10f0
movq 0xc(%r14), %rcx
movslq %ecx, %rax
shrq $0x20, %rcx
movq 0x631c(%rip), %rdx      # 0x81e8
movsbl (%rdx,%rax), %edx
incl %ecx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1190
cmpl $0x0, 0x14(%r14)
jle 0x1f34
leaq 0x31e6(%rip), %r15      # 0x50d3
leaq 0x3341(%rip), %r12      # 0x5235
xorl %r13d, %r13d
movq %r15, %rdi
movq %rbx, %rsi
callq 0x10f0
movq 0x18(%r14,%r13,8), %rcx
movslq %ecx, %rax
shrq $0x20, %rcx
movq 0x62d3(%rip), %rdx      # 0x81e8
movsbl (%rdx,%rax), %edx
incl %ecx
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x1190
incq %r13
movslq 0x14(%r14), %rax
cmpq %rax, %r13
jl 0x1ef7
movl $0xa, %edi
movq %rbx, %rsi
callq 0x1110
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x11e0
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/thudlib.c
// Function: beamiterdeepen
struct move beamiterdeepen(struct thudboard * board, int searchtime)
{
    struct move bestmove;

    struct thudboard tempboard = * board;
    time_t stoptime = time(NULL) + searchtime;

    for (int depth=1; depth <= 4; depth += 1)
    {
        struct move move;
        absearch(& tempboard, depth, FULL_WIDTH,
                 INT_MIN, INT_MAX, & move,
                 0, NULL);
        bestmove = move;

        //??? write to log?
        //printf("best move at depth %d: ", depth);
        //showmove(& bestmove);
    }

    jmp_buf stopsearch;
    if (setjmp(stopsearch) == 0) for (int depth=5; true; depth += 1)
    {
        struct move move;
        absearch(& tempboard, depth, 20,
                 INT_MIN, INT_MAX, & move,
                 stoptime, stopsearch);
        bestmove = move;

        /*
        //??? won't work without a ttable fix of some kind
        bestmove = zerowindow(& tempboard, depth, stoptime, stopsearch);
        */

        //??? write to log?
        //printf("best width 20 move at depth %d: ", depth);
        //showmove(& bestmove);
    }

    return bestmove;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movl %edx, %ebp
movq %rdi, %rbx
movq %rdi, 0x20(%rsp)
leaq 0x28(%rsp), %r15
movl $0x10, %ecx
movq %r15, %rdi
rep  movsq (%rsi), %es:(%rdi)
xorl %eax, %eax
movl %eax, %edi
callq 0x11d0
movq %rax, %r12
movslq %ebp, %rax
movq %rax, 0x18(%rsp)
movl $0x1, %r14d
movl $0x80000000, %ebp       # imm = 0x80000000
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq %rsp, %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %r15, %rdi
movl %r14d, %esi
movl %r13d, %edx
movl %ebp, %ecx
movl %r13d, %r8d
movq %rbx, %r9
callq 0x1af4
movl %r14d, %eax
incl %eax
movl %eax, %r14d
cmpl $0x5, %eax
jne 0x1fa2
leaq 0x100(%rsp), %r13
movq %r13, %rdi
callq 0x1050
testl %eax, %eax
je 0x1ff9
movq 0x20(%rsp), %rax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq 0x18(%rsp), %r12
movl $0x5, %ebp
leaq 0xa8(%rsp), %r15
movl $0x16, %r14d
movq %rsp, %rax
movq %r13, 0x8(%rax)
movq %r12, (%rax)
leaq 0x28(%rsp), %rdi
movl %ebp, %esi
movl $0x14, %edx
movl $0x80000000, %ecx       # imm = 0x80000000
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %r15, %r9
callq 0x1af4
movq %r14, %rcx
movq %rbx, %rdi
movq %r15, %rsi
rep  movsl (%rsi), %es:(%rdi)
incl %ebp
jmp 0x2011
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/thudlib.c
// Function: heapof
struct moveheap heapof(struct thudboard * board, struct movelist * list)
{
    bool isdwarfturn = board->isdwarfturn;

    struct moveheap heap;
    initheap(& heap);

    for (int i=0; i < list->used; ++i)
    {
        struct move * move = & (list->moves[i]);

        domove(board, move);
        int score = evaluate(board);
        if (isdwarfturn) score *= -1;
        undomove(board, move);

        insert(& heap, score, move);
    }

    return heap;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movb (%rdi), %al
movb %al, 0x7(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x3ba4
cmpl $0x0, (%rbx)
jle 0x20d5
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x8(%rbx), %r12
addq %r15, %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x20ee
movq %r14, %rdi
callq 0x219f
movl %eax, %ebp
negl %ebp
cmpb $0x0, 0x7(%rsp)
cmovel %eax, %ebp
movq %r14, %rdi
movq %r12, %rsi
callq 0x2126
leaq 0x8(%rsp), %rdi
movl %ebp, %esi
movq %r12, %rdx
callq 0x3bd5
incq %r13
movslq (%rbx), %rax
addq $0x58, %r15
cmpq %rax, %r13
jl 0x2086
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/thudlib.c
// Function: mtdf
int _mtdf(struct thudboard * board, int depth,
          int guess, int min, int max,
          time_t stoptime, jmp_buf stopsearch)
{
    do
    {
        int beta = guess + (guess == min);

        guess = absearch(board, depth, FULL_WIDTH,
                         beta-1, beta, NULL,
                         stoptime, stopsearch);

        if (guess < beta) max = guess;
        else min = guess;
    } while (min < max);

    return guess;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %rbx
movl %r8d, %ebp
movl %ecx, %r14d
movl %edx, %eax
movl %esi, %r15d
movq %rdi, %r12
xorl %ecx, %ecx
cmpl %r14d, %eax
sete %cl
movl %eax, %r13d
addl %ecx, %r13d
addl %eax, %ecx
decl %ecx
movq %r12, %rdi
movl %r15d, %esi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %r13d, %r8d
xorl %r9d, %r9d
pushq 0x40(%rsp)
pushq %rbx
callq 0x1af4
addq $0x10, %rsp
cmpl %r13d, %eax
cmovll %eax, %ebp
cmovgel %eax, %r14d
cmpl %ebp, %r14d
jl 0x2150
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/icarroll[P]clunk/thudlib.c
// Function: evaluate
int evaluate(struct thudboard * board)
{
    eval_count += 1;
    struct tableentry * entry = ttget(board->hash);
    if (entry) return entry->scoreguess;
    else return heuristic(board);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
incl 0x60cf(%rip)            # 0x8278
movq 0x68(%rdi), %rdi
callq 0x45b0
testq %rax, %rax
je 0x21bc
movl 0x10(%rax), %eax
jmp 0x21cf
imull $0xfa0, 0x60(%rbx), %ecx # imm = 0xFA0
imull $0xfffffc18, 0x5c(%rbx), %eax # imm = 0xFFFFFC18
addl %ecx, %eax
subl 0x64(%rbx), %eax
popq %rbx
retq