// File: /workspace/github_cpp_makefile_star2_O1/NeoResearch[P]dbft3-spork-detect/main.cpp
// Function: makeTest(int, int)
vector<int> makeTest(int f, int failed = 0)
{
    cout << "making test (f=" << f << "; failed=" << failed << ")" << endl;
    int N = 3 * f + 1;

    vector<int> choices(N, -1);

    int count_primaries = 0;
    // must have at least one primary alive (non-faulty)
    while (count_primaries == 0)
    {
        count_primaries = 2; // two primaries (must have at least one alive)
        // double proposal
        choices[0] = 0;
        choices[1] = 1;
        // set failed nodes
        while (failed > 0)
        {
            int i = rand() % N; // failed
            if (choices[i] != -2)
            {
                choices[i] = -2;
                cout << " --> failed " << i << endl;
                failed--;
                if ((i == 0) || (i == 1))
                {
                    cout << "-----> lost primary!" << endl;
                    count_primaries--;
                }
            }
        }
    }

    // set rest of nodes first responses
    for (unsigned i = 2; i < N; i++)
    {
        int c = choices[i];
        while (c == -1) // not selected yet
        {
            c = rand() % 2;       // double proposal
            if (choices[c] == -2) // re-propose because it's faulty
            {
                c = -1;
                continue;
            }
        }
        choices[i] = c;
    }

    return choices;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r14d
movl %esi, %r12d
movq %rdi, %rbx
movq 0x6b30(%rip), %r15      # 0x8fd8
leaq 0x3b88(%rip), %rsi      # 0x6037
movl $0xf, %edx
movq %r15, %rdi
callq 0x2170
movq %r15, %rdi
movl %r12d, %esi
callq 0x2210
movq %rax, %r13
leaq 0x3b76(%rip), %rsi      # 0x6047
movl $0x9, %edx
movq %rax, %rdi
callq 0x2170
movq %r13, %rdi
movl %r14d, %esi
callq 0x2210
movq %rax, %r13
leaq 0x3e4e(%rip), %rsi      # 0x6341
movl $0x1, %edx
movq %rax, %rdi
callq 0x2170
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
leal (%r12,%r12,2), %r15d
incl %r15d
movslq %r15d, %rsi
leaq -0x34(%rbp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
leaq -0x29(%rbp), %rcx
movq %rbx, %rdi
callq 0x4c6c
movq (%rbx), %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
movq %rcx, (%rax)
testl %r14d, %r14d
jle 0x2644
movl $0x2, -0x30(%rbp)
callq 0x2060
cltd
idivl %r15d
movslq %edx, %rax
movq (%rbx), %rcx
cmpl $-0x2, (%rcx,%rax,4)
je 0x2632
movl %edx, %r13d
movl $0xfffffffe, (%rcx,%rax,4) # imm = 0xFFFFFFFE
movl $0xc, %edx
movq 0x6a41(%rip), %rdi      # 0x8fd8
leaq 0x3ab3(%rip), %rsi      # 0x6051
callq 0x2170
movq 0x6a2e(%rip), %rdi      # 0x8fd8
movl %r13d, %esi
callq 0x2210
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
decl %r14d
cmpl $0x1, %r13d
ja 0x2632
movl $0x14, %edx
movq 0x69e7(%rip), %rdi      # 0x8fd8
leaq 0x3a66(%rip), %rsi      # 0x605e
callq 0x2170
movq 0x69d4(%rip), %rcx      # 0x8fd8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq 0x69b6(%rip), %rdi      # 0x8fd8
callq 0x2030
movq %rax, %rdi
callq 0x20e0
decl -0x30(%rbp)
testl %r14d, %r14d
jg 0x2568
cmpl $0x0, -0x30(%rbp)
sete %al
jmp 0x2646
xorl %eax, %eax
testb %al, %al
jne 0x2548
cmpl $0x3, %r15d
jb 0x26a0
movl %r15d, %r14d
movl $0x2, %r15d
movq (%rbx), %rax
movl (%rax,%r15,4), %eax
cmpl $-0x1, %eax
jne 0x2691
callq 0x2060
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
andl $-0x2, %ecx
subl %ecx, %eax
movslq %eax, %rcx
movq (%rbx), %rdx
cmpl $-0x2, (%rdx,%rcx,4)
sete %dl
cmpl $-0x1, %ecx
sete %cl
orb %dl, %cl
jne 0x2669
movq (%rbx), %rcx
movl %eax, (%rcx,%r15,4)
incq %r15
cmpq %r14, %r15
jne 0x265d
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x26c9
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x2150
movq %r14, %rdi
callq 0x2220