// File: adrianphoulady[P]weighted-tsetlin-machine-cpp/./weightm.h
// Function: weightm::weightm(int, int, double, double, int, int)
weightm(int features, int clauses, double p, double gamma, int threshold, int states = 8)
    : features{features},
      clauses{clauses},
      p{p},
      gamma{gamma},
      threshold{threshold},
      states{states},
      literals{(2 * features - 1) / word_bits + 1},
      actmask{~((bool) (2 * features % word_bits) * ~((word) 0) << 2 * features % word_bits)},
      state{clauses, literals, states},
      lmask{literals},
      clause{clauses},
      weight{clauses} {
        for (int c = 0; c < clauses; ++c) {
            // even clauses are positive and and odds are negative
            weight(c) = c & 1? -1: +1;
            // initialize all the states to 2^states - 1
            for (int l = 0; l < literals; ++l) {
                for (int b = 0; b < states - 1; ++b)
                    state(c, l, b) = ~((word) 0);
                state(c, l, states - 1) = 0;
            }
        }
    }

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movl %esi, 0x5c(%rsp)
movl %edx, 0x58(%rsp)
movsd %xmm0, 0x50(%rsp)
movsd %xmm1, 0x48(%rsp)
movl %ecx, 0x44(%rsp)
movl %r8d, 0x40(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x18(%rsp)
movl 0x5c(%rsp), %ecx
movl %ecx, (%rax)
movl 0x58(%rsp), %ecx
movl %ecx, 0x4(%rax)
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x8(%rax)
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x10(%rax)
movl 0x44(%rsp), %ecx
movl %ecx, 0x18(%rax)
movl 0x40(%rsp), %ecx
movl %ecx, 0x1c(%rax)
movl 0x5c(%rsp), %ecx
movl %ecx, %edx
leal -0x1(%rdx,%rdx), %ecx
leal 0x1e(%rdx,%rdx), %edx
testl %ecx, %ecx
cmovsl %edx, %ecx
sarl $0x5, %ecx
incl %ecx
movl %ecx, 0x20(%rax)
movl 0x5c(%rsp), %esi
movl %esi, %ecx
addl %ecx, %ecx
movl %esi, %edx
leal 0x1f(%rdx,%rdx), %esi
testl %ecx, %ecx
movl %ecx, %edx
cmovsl %esi, %edx
andl $-0x20, %edx
subl %edx, %ecx
xorl %edx, %edx
movl %ecx, %esi
negl %esi
sbbl %edx, %edx
shll %cl, %edx
movl %edx, %ecx
notl %ecx
movl %ecx, 0x24(%rax)
movq %rax, %rdi
addq $0x28, %rdi
movq %rdi, 0x10(%rsp)
movl 0x58(%rsp), %esi
movl 0x20(%rax), %edx
movl 0x40(%rsp), %ecx
callq 0x4f10
movq 0x18(%rsp), %rax
movq %rax, %rdi
addq $0x40, %rdi
movq %rdi, 0x20(%rsp)
movl 0x20(%rax), %esi
callq 0x4f70
jmp 0x521e
movq 0x18(%rsp), %rdi
addq $0x50, %rdi
movq %rdi, 0x8(%rsp)
movl 0x58(%rsp), %esi
callq 0x40f0
jmp 0x5237
movq 0x18(%rsp), %rdi
addq $0x60, %rdi
movl 0x58(%rsp), %esi
callq 0x4fb0
jmp 0x524b
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x58(%rsp), %eax
jge 0x5379
movq 0x18(%rsp), %rdi
movl 0x30(%rsp), %edx
andl $0x1, %edx
movl $0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x0, %edx
cmovnel %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, (%rsp)
addq $0x60, %rdi
movl 0x30(%rsp), %esi
callq 0x5090
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movl $0x0, 0x2c(%rsp)
movq 0x18(%rsp), %rcx
movl 0x2c(%rsp), %eax
cmpl 0x20(%rcx), %eax
jge 0x5367
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
movl 0x40(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x5334
movq 0x18(%rsp), %rdi
addq $0x28, %rdi
movl 0x30(%rsp), %esi
movl 0x2c(%rsp), %edx
movl 0x28(%rsp), %ecx
callq 0x5050
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x52be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x38(%rsp)
movl %eax, 0x34(%rsp)
jmp 0x5388
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x38(%rsp)
movl %eax, 0x34(%rsp)
jmp 0x537e
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x38(%rsp)
movl %eax, 0x34(%rsp)
callq 0x4520
jmp 0x537e
movq 0x18(%rsp), %rdi
addq $0x28, %rdi
movl 0x30(%rsp), %esi
movl 0x2c(%rsp), %edx
movl 0x40(%rsp), %ecx
subl $0x1, %ecx
callq 0x5050
movl $0x0, (%rax)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x52a4
jmp 0x5369
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x5253
addq $0x68, %rsp
retq
movq 0x20(%rsp), %rdi
callq 0x50e0
movq 0x10(%rsp), %rdi
callq 0x5110
movq 0x38(%rsp), %rdi
callq 0x2360
nopl (%rax)