// File: SMT-COMP[P]scrambler/scrambler.cpp
// Function: print_scrambled(std::ostream&, annotation_mode)
void print_scrambled(std::ostream &out, annotation_mode keep_annotations)
{
    if (!no_scramble) {
        // identify consecutive declarations and shuffle them
        for (size_t i = 0; i < commands.size(); ) {
            if (commands[i]->symbol == "declare-fun") {
                size_t j = i+1;
                while (j < commands.size() &&
                       commands[j]->symbol == "declare-fun") {
                    ++j;
                }
                if (j - i > 1) {
                    shuffle_list(&commands, i, j);
                }
                i = j;
            } else {
                ++i;
            }
        }

        // identify consecutive assertions and shuffle them
        for (size_t i = 0; i < commands.size(); ) {
            if (commands[i]->symbol == "assert") {
                size_t j = i+1;
                while (j < commands.size() &&
                       commands[j]->symbol == "assert"){
                    ++j;
                }
                if (j - i > 1) {
                    shuffle_list(&commands, i, j);
                }
                i = j;
            } else {
                ++i;
            }
        }

        // Generate a random permutation of name ids. Note that index
        // 0 is unused in the permuted_name_ids vector (but present to
        // simplify indexing), and index next_name_id is out of range.
        size_t old_size = permuted_name_ids.size();
        assert(old_size <= next_name_id);
        // Since the print_scrambled function may be called multiple
        // times (for different parts of the benchmark), we only need
        // to permute those name ids that have been declared since the
        // last call to print_scrambled.
        if (old_size < next_name_id) {
            permuted_name_ids.reserve(next_name_id);
            for (size_t i = old_size; i < next_name_id; ++i) {
                permuted_name_ids.push_back(i);
                assert(permuted_name_ids[i] == i);
            }
            assert(permuted_name_ids.size() == next_name_id);
            // index 0 must not be shuffled
            if (old_size == 0) {
                old_size = 1;
            }
            // Knuth shuffle
            for (size_t i = old_size; i < next_name_id - 1; ++i) {
                size_t j = i + next_rand_int(next_name_id - i);
                std::swap(permuted_name_ids[i], permuted_name_ids[j]);
            }
        }
    }

    // print all commands
    for (size_t i = 0; i < commands.size(); ++i) {
        print_command(out, commands[i], keep_annotations);
        del_node(commands[i]);
    }
    commands.clear();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
testb $0x1, 0x21057(%rip)     # 0x262f0
jne 0x5644
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq 0x2108a(%rip), %rdi     # 0x26340
callq 0x7430
movq %rax, %rcx
movq -0x60(%rbp), %rax
cmpq %rcx, %rax
jae 0x539a
movq -0x18(%rbp), %rsi
leaq 0x2106a(%rip), %rdi     # 0x26340
callq 0x7450
movq (%rax), %rdi
leaq 0x14007(%rip), %rsi     # 0x192ec
callq 0x74e0
testb $0x1, %al
jne 0x52f3
jmp 0x5389
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq 0x21032(%rip), %rdi     # 0x26340
callq 0x7430
movq -0x70(%rbp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x61(%rbp)
jae 0x5346
movq -0x20(%rbp), %rsi
leaq 0x21011(%rip), %rdi     # 0x26340
callq 0x7450
movq (%rax), %rdi
leaq 0x13fae(%rip), %rsi     # 0x192ec
callq 0x74e0
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x534f
jmp 0x535d
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x52ff
movq -0x20(%rbp), %rax
subq -0x18(%rbp), %rax
cmpq $0x1, %rax
jbe 0x537f
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq 0x20fc6(%rip), %rdi     # 0x26340
callq 0x40a0
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x5395
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x52a7
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq 0x20f8f(%rip), %rdi     # 0x26340
callq 0x7430
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0x549b
movq -0x28(%rbp), %rsi
leaq 0x20f6f(%rip), %rdi     # 0x26340
callq 0x7450
movq (%rax), %rdi
leaq 0x15e40(%rip), %rsi     # 0x1b220
callq 0x74e0
testb $0x1, %al
jne 0x53ee
jmp 0x548a
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq 0x20f34(%rip), %rdi     # 0x26340
callq 0x7430
movq -0x88(%rbp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x79(%rbp)
jae 0x5447
movq -0x30(%rbp), %rsi
leaq 0x20f10(%rip), %rdi     # 0x26340
callq 0x7450
movq (%rax), %rdi
leaq 0x15de1(%rip), %rsi     # 0x1b220
callq 0x74e0
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x5450
jmp 0x545e
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x53fa
movq -0x30(%rbp), %rax
subq -0x28(%rbp), %rax
cmpq $0x1, %rax
jbe 0x5480
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq 0x20ec5(%rip), %rdi     # 0x26340
callq 0x40a0
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x5496
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x53a2
leaq 0x20ebe(%rip), %rdi     # 0x26360
callq 0x75b0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq 0x20de2(%rip), %rax     # 0x26298
ja 0x54ba
jmp 0x54d9
leaq 0x13e37(%rip), %rdi     # 0x192f8
leaq 0x13b4d(%rip), %rsi     # 0x19015
movl $0x2cd, %edx            # imm = 0x2CD
leaq 0x13e3d(%rip), %rcx     # 0x19311
callq 0x31a0
movq -0x38(%rbp), %rax
cmpq 0x20db4(%rip), %rax     # 0x26298
jae 0x5642
movq 0x20da7(%rip), %rsi     # 0x26298
leaq 0x20e68(%rip), %rdi     # 0x26360
callq 0x75f0
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq 0x20d88(%rip), %rax     # 0x26298
jae 0x556c
leaq 0x20e47(%rip), %rdi     # 0x26360
leaq -0x40(%rbp), %rsi
callq 0x76f0
movq -0x40(%rbp), %rsi
leaq 0x20e33(%rip), %rdi     # 0x26360
callq 0x75d0
movq (%rax), %rax
cmpq -0x40(%rbp), %rax
jne 0x553d
jmp 0x555c
leaq 0x13e03(%rip), %rdi     # 0x19347
leaq 0x13aca(%rip), %rsi     # 0x19015
movl $0x2d6, %edx            # imm = 0x2D6
leaq 0x13dba(%rip), %rcx     # 0x19311
callq 0x31a0
jmp 0x555e
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x5505
leaq 0x20ded(%rip), %rdi     # 0x26360
callq 0x75b0
cmpq 0x20d19(%rip), %rax     # 0x26298
jne 0x5583
jmp 0x55a2
leaq 0x13dd7(%rip), %rdi     # 0x19361
leaq 0x13a84(%rip), %rsi     # 0x19015
movl $0x2d8, %edx            # imm = 0x2D8
leaq 0x13d74(%rip), %rcx     # 0x19311
callq 0x31a0
cmpq $0x0, -0x38(%rbp)
jne 0x55b1
movq $0x1, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq 0x20cd4(%rip), %rcx     # 0x26298
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x5640
movq -0x48(%rbp), %rax
movq %rax, -0x98(%rbp)
movq 0x20cb9(%rip), %rdi     # 0x26298
subq -0x48(%rbp), %rdi
callq 0x37c0
movq %rax, %rcx
movq -0x98(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rsi
leaq 0x20d5c(%rip), %rdi     # 0x26360
callq 0x75d0
movq %rax, -0x90(%rbp)
movq -0x50(%rbp), %rsi
leaq 0x20d45(%rip), %rdi     # 0x26360
callq 0x75d0
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x7760
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x55b9
jmp 0x5642
jmp 0x5644
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq 0x20ce2(%rip), %rdi     # 0x26340
callq 0x7430
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
jae 0x56c5
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x58(%rbp), %rsi
leaq 0x20cb8(%rip), %rdi     # 0x26340
callq 0x7450
movq -0xa8(%rbp), %rdi
movq (%rax), %rsi
movl -0xc(%rbp), %edx
callq 0x5240
movq -0x58(%rbp), %rsi
leaq 0x20c96(%rip), %rdi     # 0x26340
callq 0x7450
movq (%rax), %rdi
callq 0x4010
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x564c
leaq 0x20c74(%rip), %rdi     # 0x26340
callq 0x77a0
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)