LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O2/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 0x2627(%rip), %rax      # 0x40a8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
xorl %r13d, %r13d
cmpq $0xc, %r13
je 0x1ae6
movq -0x38(%rbp), %rax
movslq 0x28(%rax,%r13,4), %rax
testq %rax, %rax
je 0x1ae1
shlq $0xa, %rax
movq -0x30(%rbp), %rcx
leaq (%rcx,%rax), %r12
movzwl 0x4(%rcx,%rax), %eax
movzwl %ax, %r14d
cmpl $0x3ff, %r14d           # imm = 0x3FF
ja 0x1ae1
movzwl %ax, %r15d
addq %r12, %r15
leaq 0x8(%r15), %rdi
movq %rbx, %rsi
callq 0x10b0
testl %eax, %eax
je 0x1ae9
movzwl 0x4(%r15), %eax
addl %eax, %r14d
movq %r15, %r12
jmp 0x1ab4
incq %r13
jmp 0x1a8b
xorl %r12d, %r12d
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
movl %esi, %r14d
movq %rdi, %rbx
xorl %r15d, %r15d
cmpq $0xc, %r15
je 0x1b3f
movl 0x28(%rbx,%r15,4), %edi
testl %edi, %edi
je 0x1b3a
movl %r14d, %esi
callq 0x1ba2
testq %rax, %rax
jne 0x1b97
incq %r15
jmp 0x1b1e
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0xc, %rcx
je 0x1b97
leaq 0x1(%rcx), %r14
cmpl $0x0, 0x28(%rbx,%rcx,4)
movq %r14, %rcx
jne 0x1b43
callq 0x19c9
movl %eax, 0x24(%rbx,%r14,4)
addl $0x2, 0x1c(%rbx)
addl $0x400, 0x4(%rbx)       # imm = 0x400
leaq 0x2535(%rip), %rcx      # 0x40a8
movq (%rcx), %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_O2/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 0x24fb(%rip), %rax      # 0x40a8
shll $0xa, %edi
movslq %edi, %rcx
addq (%rax), %rcx
xorl %eax, %eax
xorl %edx, %edx
cmpl $0x3ff, %edx            # imm = 0x3FF
ja 0x1bf5
movzbl 0x6(%rcx), %edi
addl $0xc, %edi
andl $-0x4, %edi
movzwl 0x4(%rcx), %r9d
movl %r9d, %r8d
subl %edi, %r8d
cmpl %esi, %r8d
jge 0x1be7
addl %r9d, %edx
movl %r9d, %edi
addq %rdi, %rcx
jmp 0x1bba
leaq (%rcx,%rdi), %rax
movw %di, 0x4(%rcx)
movw %r8w, 0x4(%rcx,%rdi)
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x4
popq %rcx
cltd
idivl %ecx
leal 0x8(,%rax,4), %esi
movq %r12, %rdi
callq 0x1b0b
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_O2/JavieW[P]CSCC69_Ext2_File-System/utilities.c
// Function: initSingleIndirect
unsigned int *initSingleIndirect(int blockNum) {
    unsigned int *singleIndirect = (unsigned int *)getBlock(blockNum);
    for (int i=0; i<(EXT2_BLOCK_SIZE/4); i++) {
        singleIndirect[i] = 0;
    }
    return singleIndirect;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq 0x243d(%rip), %rcx      # 0x40a8
shll $0xa, %edi
movslq %edi, %rax
addq (%rcx), %rax
xorl %ecx, %ecx
cmpq $0x100, %rcx            # imm = 0x100
je 0x1c88
andl $0x0, (%rax,%rcx,4)
incq %rcx
jmp 0x1c76
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 %r12d, %r12d
cmpb $0x2f, (%r15)
jne 0x1d40
movb -0x1(%r15,%rax), %al
movb %al, -0x29(%rbp)
leaq 0x23ec(%rip), %rax      # 0x40a8
movq (%rax), %r12
movl 0x808(%r12), %r13d
shll $0xa, %r13d
leaq (%r12,%r13), %r14
addq $0x80, %r14
leaq 0x4a3(%rip), %rbx       # 0x2180
movq %r15, %rdi
movq %rbx, %rsi
callq 0x10f0
addq %r12, %r13
addq $-0x80, %r13
pushq $0x2
popq %r15
xorl %r12d, %r12d
movzwl (%r14), %ecx
testq %rax, %rax
je 0x1d2d
btl $0xe, %ecx
jae 0x1d40
movq %r14, %rdi
movq %rax, %rsi
callq 0x1a18
testl %eax, %eax
je 0x1d40
movl %eax, %r15d
movslq %eax, %r14
shlq $0x7, %r14
addq %r13, %r14
xorl %edi, %edi
movq %rbx, %rsi
callq 0x10f0
jmp 0x1cf6
xorl %r12d, %r12d
cmpb $0x2f, -0x29(%rbp)
cmovnel %r15d, %r12d
btl $0xe, %ecx
cmovbl %r15d, %r12d
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 %rdi, %rbx
leaq 0x41d(%rip), %r14       # 0x2180
movq %rsi, %rdi
movq %r14, %rsi
callq 0x10f0
testq %rax, %rax
je 0x1d82
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1040
xorl %esi, %esi
jmp 0x1d63
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
cmpb $0x2f, (%rdi)
jne 0x1d9b
cmpb $0x0, 0x1(%rbx)
je 0x1dc7
movq %rbx, %rdi
callq 0x1060
decl %eax
cltq
cmpb $0x2f, (%rbx,%rax)
jne 0x1db1
movb $0x0, (%rbx,%rax)
pushq $0x2f
popq %rsi
movq %rbx, %rdi
callq 0x1090
movb $0x0, 0x1(%rax)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x3b4(%rip), %rdi       # 0x2182
leaq 0x3c2(%rip), %rsi       # 0x2197
leaq 0x3c7(%rip), %rcx       # 0x21a3
movl $0x153, %edx            # imm = 0x153
callq 0x10a0
// File: /workspace/github_c_makefile_star2_O2/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 0xeb5(%rip), %rdx       # 0x20e8
movq %rsp, %rdi
pushq $0x1
popq %rsi
callq 0x1300
testl %eax, %eax
jne 0x12c7
movl $0x400, %ebx            # imm = 0x400
cmpl $0x2, %ebp
jl 0x127b
movq 0x8(%r14), %rbx
movq %rbx, %rdi
callq 0x10e0
movl %eax, %ebp
testl %eax, %eax
jg 0x1278
leaq 0x1dcb(%rip), %rdx      # 0x3034
pushq $0x1
popq %rdi
xorl %esi, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1ff0
movslq %ebp, %rbx
movq %rbx, %rdi
callq 0x10a0
testq %rax, %rax
je 0x12e0
movq %rax, %r14
movq %rsp, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x1471
movq 0x3d38(%rip), %rax      # 0x4fd8
movq (%rax), %rcx
pushq $0x1
popq %rsi
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 0x1d36(%rip), %rdi      # 0x3004
leaq 0x1d36(%rip), %rsi      # 0x300b
leaq 0x1d3b(%rip), %rcx      # 0x3017
pushq $0x17
jmp 0x12f7
leaq 0x1d5d(%rip), %rdi      # 0x3044
leaq 0x1d1d(%rip), %rsi      # 0x300b
leaq 0x1d22(%rip), %rcx      # 0x3017
pushq $0x22
popq %rdx
callq 0x1050
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/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
pushq $-0x16
popq %r15
testq %rdx, %rdx
je 0x13e3
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
movl $0x530, %edx            # imm = 0x530
xorl %esi, %esi
callq 0x1060
movq %r14, 0x510(%rbx)
cmpl $0x2, %ebp
je 0x138d
cmpl $0x1, %ebp
jne 0x13e3
leaq 0x285(%rip), %rax       # 0x15cc
movq %rax, 0x518(%rbx)
leaq 0x28b(%rip), %rax       # 0x15e0
movq %rax, 0x520(%rbx)
leaq 0x2af(%rip), %rax       # 0x1612
movq %rax, 0x528(%rbx)
movq %rsp, %rdi
pushq $0x30
popq %rsi
callq *%r14
testl %eax, %eax
jne 0x13f1
leaq 0x20(%rsp), %rdx
leaq 0x410(%rbx), %rdi
movq %rsp, %rsi
callq 0x1db6
jmp 0x13d4
leaq 0x2c7(%rip), %rax       # 0x165b
movq %rax, 0x518(%rbx)
leaq 0x845(%rip), %rax       # 0x1be7
movq %rax, 0x520(%rbx)
leaq 0x863(%rip), %rax       # 0x1c13
movq %rax, 0x528(%rbx)
movq %rsp, %rdi
pushq $0x28
popq %rsi
callq *%r14
testl %eax, %eax
jne 0x140a
leaq 0x20(%rsp), %rdx
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x1c5c
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1427
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c0c(%rip), %rdi      # 0x3004
leaq 0x1c61(%rip), %rsi      # 0x3060
leaq 0x1c8b(%rip), %rcx      # 0x3091
pushq $0x78
jmp 0x1421
leaq 0x1bf3(%rip), %rdi      # 0x3004
leaq 0x1c48(%rip), %rsi      # 0x3060
leaq 0x1cc0(%rip), %rcx      # 0x30df
pushq $0x3e
popq %rdx
callq 0x1050
// File: /workspace/github_c_makefile_star2_O2/opencoff[P]crypto-rand/cryptorand.c
// Function: rs_rekey
static inline void
_rs_rekey(crypto_rand_state* st, uint8_t *dat, size_t datlen)
{
    st->crypt_buf(st);

    /* mix in optional user provided data */
    if (dat) {
        size_t i, m;

        m = minimum(datlen, sizeof st->buf);
        for (i = 0; i < m; i++)
            st->buf[i] ^= dat[i];

        memset(dat, 0, datlen);
    }

    /* immediately reinit for backtracking resistance */
    st->crypt_reinit(st);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
callq *0x518(%rdi)
testq %r14, %r14
je 0x1463
xorl %eax, %eax
movq %r15, %rdx
cmpq %rax, %rbx
je 0x1456
movb (%r14,%rax), %cl
xorb %cl, (%rdx,%rax)
incq %rax
jmp 0x1445
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1060
movq %r15, %rdi
popq %rbx
popq %r14
popq %r15
jmpq *0x520(%rdi)
// File: /workspace/github_c_makefile_star2_O2/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
movq 0x408(%rdi), %rax
cmpq %rdx, %rax
ja 0x14bb
movq %r15, %rdi
callq *0x528(%r15)
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x1060
movq %r13, 0x400(%r15)
movl $0x20000, %eax          # imm = 0x20000
subq %rbx, %rax
movq %rax, 0x408(%r15)
testq %rbx, %rbx
je 0x1502
movq (%r13), %rsi
movq %r13, %r12
subq %rsi, %r12
jne 0x14e4
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1427
jmp 0x14c5
cmpq %r12, %rbx
cmovbq %rbx, %r12
movq %r14, %rdi
movq %r12, %rdx
callq 0x1090
addq %r12, %r14
subq %r12, %rbx
addq %r12, (%r13)
jmp 0x14c5
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x1564
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %esi, %ebx
movq %rdi, %r14
movl %esi, %eax
negl %eax
xorl %edx, %edx
divl %esi
movl %edx, %ebp
leaq 0xc(%rsp), %r15
pushq $0x4
popq %r12
andl $0x0, 0xc(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1471
movl 0xc(%rsp), %eax
cmpl %ebp, %eax
jb 0x1537
xorl %edx, %edx
divl %ebx
movl %edx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x156e
xorl %eax, %eax
retq
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rax
negq %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %r15
leaq 0x8(%rsp), %r12
pushq $0x8
popq %r13
andq $0x0, 0x8(%rsp)
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1471
movq 0x8(%rsp), %rax
cmpq %r15, %rax
jb 0x1598
xorl %edx, %edx
divq %rbx
movq %rdx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x30
popq %rsi
callq *0x510(%rbx)
testl %eax, %eax
jne 0x163e
movq %rsp, %rsi
pushq $0x30
popq %rdx
movq %rbx, %rdi
callq 0x1427
addq $0x30, %rsp
popq %rbx
retq
leaq 0x19bf(%rip), %rdi      # 0x3004
leaq 0x1a14(%rip), %rsi      # 0x3060
leaq 0x1a18(%rip), %rcx      # 0x306b
pushq $0x5b
popq %rdx
callq 0x1050
// File: /workspace/github_c_makefile_star2_O2/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 0x1c5c
xorps %xmm0, %xmm0
andq $0x0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
leaq 0x28(%rbx), %rax
movq %rax, 0x400(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x28
popq %rsi
callq *0x510(%rbx)
testl %eax, %eax
jne 0x1c3f
movq %rsp, %rsi
pushq $0x28
popq %rdx
movq %rbx, %rdi
callq 0x1427
addq $0x30, %rsp
popq %rbx
retq
leaq 0x13be(%rip), %rdi      # 0x3004
leaq 0x1413(%rip), %rsi      # 0x3060
leaq 0x1462(%rip), %rcx      # 0x30b6
pushq $0x22
popq %rdx
callq 0x1050
// File: /workspace/github_c_makefile_star2_O2/opencoff[P]crypto-rand/./chacha_private.h
// Function: _chacha_key_setup
static inline void
chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits,u32 ivbits)
{
    const char *constants;

    (void)ivbits;

    x->input[4] = U8TO32_LITTLE(k + 0);
    x->input[5] = U8TO32_LITTLE(k + 4);
    x->input[6] = U8TO32_LITTLE(k + 8);
    x->input[7] = U8TO32_LITTLE(k + 12);
    if (kbits == 256) { /* recommended */
        k += 16;
        constants = sigma;
    } else { /* kbits == 128 */
        constants = tau;
    }
    x->input[8] = U8TO32_LITTLE(k + 0);
    x->input[9] = U8TO32_LITTLE(k + 4);
    x->input[10] = U8TO32_LITTLE(k + 8);
    x->input[11] = U8TO32_LITTLE(k + 12);
    x->input[0] = U8TO32_LITTLE(constants + 0);
    x->input[1] = U8TO32_LITTLE(constants + 4);
    x->input[2] = U8TO32_LITTLE(constants + 8);
    x->input[3] = U8TO32_LITTLE(constants + 12);
}

// Assembly:
movl (%rsi), %eax
movl %eax, 0x420(%rdi)
movl 0x4(%rsi), %eax
movl %eax, 0x424(%rdi)
movl 0x8(%rsi), %eax
movl %eax, 0x428(%rdi)
movl 0xc(%rsi), %eax
movl %eax, 0x42c(%rdi)
movl 0x10(%rsi), %eax
movl %eax, 0x430(%rdi)
movl 0x14(%rsi), %eax
movl %eax, 0x434(%rdi)
movl 0x18(%rsi), %eax
movl %eax, 0x438(%rdi)
movl 0x1c(%rsi), %eax
movl %eax, 0x43c(%rdi)
movaps 0x13a6(%rip), %xmm0     # 0x3050
movups %xmm0, 0x410(%rdi)
andq $0x0, 0x440(%rdi)
movl (%rdx), %eax
movl %eax, 0x448(%rdi)
movl 0x4(%rdx), %eax
movl %eax, 0x44c(%rdi)
retq
nop
// File: /workspace/github_c_makefile_star2_O2/opencoff[P]crypto-rand/aes.c
// Function: AddRoundKey
static void AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey)
{
  uint8_t i,j;
  for (i = 0; i < 4; ++i)
  {
    for (j = 0; j < 4; ++j)
    {
      (*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j];
    }
  }
}

// Assembly:
shll $0x4, %edi
addq %rdx, %rdi
xorl %eax, %eax
cmpq $0x4, %rax
je 0x1fec
xorl %ecx, %ecx
cmpq $0x4, %rcx
je 0x1fdf
movb (%rdi,%rcx), %dl
xorb %dl, (%rsi,%rcx)
incq %rcx
jmp 0x1fce
incq %rax
addq $0x4, %rsi
addq $0x4, %rdi
jmp 0x1fc6
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/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 0x2055
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 0x2f7c(%rip), %rax      # 0x4fd8
movq (%rax), %rdi
callq 0x10b0
movq 0x2f8d(%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 0x20b6
testl %ebx, %ebx
jne 0x20d8
addq $0xd0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %r14
movl %ebp, %edi
callq 0x1110
leaq 0x1164(%rip), %rsi      # 0x322b
movq %r14, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x1080
jmp 0x20a2
movq (%r15), %rdi
callq 0x10b0
pushq $0x1
popq %rdi
callq 0x10f0
// File: /workspace/github_c_makefile_star2_O2/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, 0x2fa3(%rip)      # 0x50a0
jns 0x213a
leaq 0x1137(%rip), %rdi      # 0x323d
xorl %esi, %esi
xorl %eax, %eax
callq 0x10c0
movl %eax, %ebp
testl %eax, %eax
jns 0x2134
callq 0x1040
movl (%rax), %esi
leaq 0x114f(%rip), %rdx      # 0x3272
leaq 0x1113(%rip), %rcx      # 0x323d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x1ff0
movl %ebp, 0x2f66(%rip)      # 0x50a0
leaq 0x1109(%rip), %r15      # 0x324a
pushq $0x1
popq %rbp
testq %rbx, %rbx
je 0x2182
movl 0x2f51(%rip), %edi      # 0x50a0
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1070
movq %rax, %r12
testq %rax, %rax
jns 0x217a
callq 0x1040
movl (%rax), %esi
cmpl $0x4, %esi
je 0x2144
movl %ebp, %edi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1ff0
addq %r12, %r14
subq %r12, %rbx
jmp 0x2144
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x3d8f(%rip), %rdi      # 0x508c
callq 0x1040
movq 0x6cef(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
callq 0x11e0
pushq $0x3c
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3a64
movq %r14, %rdi
callq 0x3763
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x1364
movq 0x8(%rax), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x1100
movq %rax, %rsi
shll $0x14, %esi
leaq 0x6e8d(%rip), %rbx      # 0x81f8
movq %rbx, %rdi
callq 0x1704
callq 0x1160
callq 0x141d
xorl %r13d, %r13d
leaq 0x60(%rsp), %r14
pushq $0x16
popq %r15
leaq 0x8(%rsp), %r12
xorl %ebp, %ebp
cmpl $0xa, %ebp
jg 0x13ec
pushq $0xa
popq %rdi
callq 0x1080
movq %rbx, %rdi
callq 0x3117
leaq 0x6ecc(%rip), %rax      # 0x8278
andl $0x0, (%rax)
movzbl 0x6e42(%rip), %eax      # 0x81f8
xorl $0x1, %eax
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x6d4a(%rip), %rcx      # 0x8110
callq *(%rcx,%rax,8)
movq %r15, %rcx
movq %r12, %rdi
movq %r14, %rsi
rep  movsl (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3627
incl %ebp
cmpl %r13d, 0x1c(%rsp)
cmovnel %r13d, %ebp
jmp 0x1390
movl 0x6e7a(%rip), %esi      # 0x826c
shll $0x2, %esi
movl 0x6e6d(%rip), %edx      # 0x8268
leaq 0x3c2a(%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_O2/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 0x3c2c(%rip), %rbx      # 0x5058
leaq 0x3bd1(%rip), %r15      # 0x5004
movq %rbx, %rdi
callq 0x1130
testq %rax, %rax
je 0x14b3
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 0x1433
movslq (%r15,%r12,4), %rax
addq %r15, %rax
jmpq *%rax
leaq 0x3a(%rip), %rax        # 0x14ba
movq %rax, 0x6c89(%rip)      # 0x8110
jmp 0x14a0
leaq 0x2a(%rip), %rax        # 0x14ba
movq %rax, 0x6c79(%rip)      # 0x8110
jmp 0x14a7
leaq 0x1a(%rip), %rax        # 0x14ba
movq %rax, 0x6c71(%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_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x3bab(%rip), %r15      # 0x5080
movq %rsp, %r12
pushq $0x16
popq %r13
leaq 0x3bc2(%rip), %rbp      # 0x50a5
movq %r12, %rdi
movq %r15, %rsi
callq 0x1524
movq %r13, %rcx
movq %rbx, %rdi
movq %r12, %rsi
rep  movsl (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3252
testb %al, %al
jne 0x1512
movq %rbp, %rdi
callq 0x1040
jmp 0x14e3
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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)
xorl %r12d, %r12d
callq 0x10c0
movq %rax, %r14
leaq 0x6a03(%rip), %rbp      # 0x8170
xorl %r13d, %r13d
cmpq $0xf, %r13
je 0x17e6
xorl %r15d, %r15d
cmpq $0xf, %r15
je 0x17d4
movq (%r14), %rax
movq (%rbp,%r13,8), %rcx
movsbq (%rcx,%r15), %rcx
movl (%rax,%rcx,4), %eax
cmpl $0x23, %eax
je 0x17bf
cmpl $0x2e, %eax
je 0x17cf
cmpl $0x54, %eax
je 0x17b1
cmpl $0x44, %eax
jne 0x17f5
leaq (%r12,%r15), %rsi
movq %rbx, %rdi
callq 0x30ad
jmp 0x17cf
leaq (%r12,%r15), %rsi
movq %rbx, %rdi
callq 0x2e53
jmp 0x17cf
movl $0x4000, %eax           # imm = 0x4000
movl %r15d, %ecx
shrl %cl, %eax
orw %ax, 0x3e(%rbx,%r13,2)
incq %r15
jmp 0x1779
incq %r13
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r12
jmp 0x1770
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x67ec(%rip), %rax      # 0x7fe8
movq (%rax), %rcx
leaq 0x3982(%rip), %rdi      # 0x5188
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
callq 0x1170
pushq $0x1
popq %rdi
callq 0x1070
// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x10
popq %rcx
movq %rsp, %rdi
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 0x1866
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
pushq $0x1
popq %rbp
movq %rsp, %r15
leaq 0x80(%rsp), %r12
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r14, %rcx
movq %r12, %r8
callq 0x1891
incl %ebp
jmp 0x187a
// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %r8, %r14
movq %rcx, %r15
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, 0x10(%rsp)
movq %rsi, %rdi
callq 0x1f02
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
movq %r12, %rdi
callq 0x1f10
leaq 0x18(%rsp), %rdi
movq %rax, (%rdi)
movq %rdx, 0x8(%rdi)
callq 0x3980
movl %eax, %ebx
movq %rdx, %r13
movq %r12, %rdi
movq %rdx, %rsi
callq 0x1fa4
movq %r12, %rdi
movl %ebp, 0x4(%rsp)
movl %ebp, %esi
movl %ebx, %edx
movq %r15, %rbp
movq %r15, %rcx
movq %r14, %r15
movq %r14, %r8
callq 0x1fc2
movl %eax, %ebx
movq %r13, 0x8(%rsp)
leal -0x1(%rbx), %r14d
movq %r12, %rdi
movq %r13, %rsi
callq 0x1fdc
cmpl $0x0, 0x18(%rsp)
jle 0x1985
leaq 0x18(%rsp), %rdi
callq 0x3980
movq %rdx, %r13
movq %r12, %rdi
movq %rdx, %rsi
callq 0x1fa4
movq %r12, %rdi
movl 0x4(%rsp), %esi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %r14d, %ecx
movl %ebx, %r8d
xorl %r9d, %r9d
pushq %r15
pushq %rbp
callq 0x1a79
addq $0x10, %rsp
cmpl %ebx, %eax
jle 0x1913
subq $0x8, %rsp
movq %r12, %rdi
movl 0xc(%rsp), %esi
movl %eax, %edx
movl %eax, %ecx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %rbp, %r9
pushq %r15
callq 0x1fea
popq %rcx
popq %rdx
jmp 0x1908
pushq $0x16
popq %rcx
movq 0x10(%rsp), %rax
movq %rax, %rdi
movq 0x8(%rsp), %rsi
rep  movsl (%rsi), %es:(%rdi)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x10
popq %rcx
leaq 0x8(%rsp), %rdi
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 0x19f9
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)
pushq $0x1
popq %r14
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
leaq 0x88(%rsp), %r13
movq 0x65cc(%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 0x1a79
popq %rcx
popq %rdx
pushq $0x16
popq %rcx
movq %rbx, %rdi
movq %r13, %rsi
rep  movsl (%rsi), %es:(%rdi)
movq (%r15), %rdi
leaq 0x3711(%rip), %rsi      # 0x5170
movl %r14d, %edx
movl %ebp, %eax
callq 0x1190
movq (%r15), %rdi
movq %rbx, %rsi
callq 0x1d76
incl %r14d
jmp 0x1a20
// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movzbl (%rsi), %edi
shll $0x4, %edi
addl $0x54, %edi
movq %rbx, %rsi
callq 0x1110
pushq $0x20
popq %rdi
movq %rbx, %rsi
callq 0x1110
movq 0x4(%r14), %rsi
movq %rbx, %rdi
callq 0x372c
leaq 0x332a(%rip), %rdi      # 0x50dd
movq %rbx, %rsi
callq 0x10f0
movq 0xc(%r14), %rsi
movq %rbx, %rdi
callq 0x372c
xorl %r12d, %r12d
leaq 0x3302(%rip), %r15      # 0x50d3
movslq 0x14(%r14), %rax
cmpq %rax, %r12
jge 0x1df7
movq %r15, %rdi
movq %rbx, %rsi
callq 0x10f0
movq 0x18(%r14,%r12,8), %rsi
movq %rbx, %rdi
callq 0x372c
incq %r12
jmp 0x1dd1
pushq $0xa
popq %rdi
movq %rbx, %rsi
callq 0x1110
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x11e0
// File: /workspace/github_c_makefile_star2_O2/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, 0x18(%rsp)
movq %rdi, 0x20(%rsp)
pushq $0x10
popq %rcx
leaq 0x28(%rsp), %r15
movq %r15, %rdi
rep  movsq (%rsi), %es:(%rdi)
xorl %eax, %eax
movl %eax, %edi
callq 0x11d0
movq %rax, %r12
movslq %ebp, %rbx
pushq $0x1
popq %r14
movl $0x80000000, %ebp       # imm = 0x80000000
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
cmpl $0x5, %r14d
je 0x1e8a
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 0x18(%rsp), %r9
callq 0x1a79
incl %r14d
jmp 0x1e5e
leaq 0x100(%rsp), %r13
movq %r13, %rdi
callq 0x1050
testl %eax, %eax
je 0x1eb5
movq 0x20(%rsp), %rax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %rbx, %r12
pushq $0x5
popq %rbx
leaq 0xa8(%rsp), %r15
pushq $0x16
popq %r14
movq 0x18(%rsp), %rbp
movq %rsp, %rax
movq %r13, 0x8(%rax)
movq %r12, (%rax)
leaq 0x28(%rsp), %rdi
movl %ebx, %esi
pushq $0x14
popq %rdx
movl $0x80000000, %ecx       # imm = 0x80000000
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %r15, %r9
callq 0x1a79
movq %r14, %rcx
movq %rbp, %rdi
movq %r15, %rsi
rep  movsl (%rsi), %es:(%rdi)
incl %ebx
jmp 0x1ecc
// File: /workspace/github_c_makefile_star2_O2/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 0x3818
xorl %r15d, %r15d
xorl %r13d, %r13d
movslq (%rbx), %rax
cmpq %rax, %r13
jge 0x1f8b
movq 0x8(%rbx), %r12
addq %r15, %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x1fa4
movq %r14, %rdi
callq 0x2053
movl %eax, %ebp
negl %ebp
cmpb $0x0, 0x7(%rsp)
cmovel %eax, %ebp
movq %r14, %rdi
movq %r12, %rsi
callq 0x1fdc
leaq 0x8(%rsp), %rdi
movl %ebp, %esi
movq %r12, %rdx
callq 0x3846
incq %r13
addq $0x58, %r15
jmp 0x1f3a
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_O2/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 0x1a79
popq %rcx
popq %rdx
cmpl %r13d, %eax
cmovll %eax, %ebp
cmovgel %eax, %r14d
cmpl %ebp, %r14d
jl 0x2006
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x621b(%rip)            # 0x8278
movq 0x68(%rdi), %rdi
callq 0x4097
testq %rax, %rax
je 0x2070
movl 0x10(%rax), %eax
jmp 0x2083
imull $0xfa0, 0x60(%rbx), %ecx # imm = 0xFA0
imull $0xfffffc18, 0x5c(%rbx), %eax # imm = 0xFFFFFC18
addl %ecx, %eax
subl 0x64(%rbx), %eax
popq %rbx
retq