// File: /workspace/github_cpp_makefile_star2_O2/sokolcom[P]tp-blockchain-task06/uint256_t/uint256_t.cpp
// Function: uint256_t::operator*(uint256_t const&) const
uint256_t uint256_t::operator*(const uint256_t & rhs) const{
    // split values into 4 64-bit parts
    uint128_t top[4] = {UPPER.upper(), UPPER.lower(), LOWER.upper(), LOWER.lower()};
    uint128_t bottom[4] = {rhs.upper().upper(), rhs.upper().lower(), rhs.lower().upper(), rhs.lower().lower()};
    uint128_t products[4][4];

    // multiply each component of the values
    for(int y = 3; y > -1; y--){
        for(int x = 3; x > -1; x--){
            products[3 - y][x] = top[x] * bottom[y];
        }
    }

    // first row
    uint128_t fourth64 = uint128_t(products[0][3].lower());
    uint128_t third64  = uint128_t(products[0][2].lower()) + uint128_t(products[0][3].upper());
    uint128_t second64 = uint128_t(products[0][1].lower()) + uint128_t(products[0][2].upper());
    uint128_t first64  = uint128_t(products[0][0].lower()) + uint128_t(products[0][1].upper());

    // second row
    third64  += uint128_t(products[1][3].lower());
    second64 += uint128_t(products[1][2].lower()) + uint128_t(products[1][3].upper());
    first64  += uint128_t(products[1][1].lower()) + uint128_t(products[1][2].upper());

    // third row
    second64 += uint128_t(products[2][3].lower());
    first64  += uint128_t(products[2][2].lower()) + uint128_t(products[2][3].upper());

    // fourth row
    first64  += uint128_t(products[3][3].lower());

    // combines the values, taking care of carry over
    return uint256_t(first64 << uint128_64, uint128_0) +
           uint256_t(third64.upper(), third64 << uint128_64) +
           uint256_t(second64, uint128_0) +
           uint256_t(fourth64);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, 0x28(%rsp)
leaq 0x10(%rsi), %r15
movq %r15, %rdi
callq 0x2cce
movq (%rax), %rax
movq %rax, 0xa0(%rsp)
andq $0x0, 0xa8(%rsp)
movq %r15, %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, 0xb0(%rsp)
andq $0x0, 0xb8(%rsp)
movq %rbx, %rdi
callq 0x2cce
movq (%rax), %rax
movq %rax, 0xc0(%rsp)
andq $0x0, 0xc8(%rsp)
movq %rbx, %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, 0xd0(%rsp)
andq $0x0, 0xd8(%rsp)
leaq 0x10(%r14), %rbx
movq %rbx, %rdi
callq 0x2cce
movq (%rax), %rax
movq %rax, 0x60(%rsp)
andq $0x0, 0x68(%rsp)
movq %rbx, %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, 0x70(%rsp)
andq $0x0, 0x78(%rsp)
movq %r14, %rdi
callq 0x2cce
movq (%rax), %rax
movq %rax, 0x80(%rsp)
andq $0x0, 0x88(%rsp)
movq %r14, %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, 0x90(%rsp)
andq $0x0, 0x98(%rsp)
pushq $0x3
popq %r14
movq %r14, %r15
testq %r15, %r15
js 0x4403
movq %r15, %rax
shlq $0x4, %rax
leaq (%rsp,%rax), %rbx
addq $0x60, %rbx
movq %r14, %rax
subq %r15, %rax
shlq $0x6, %rax
leaq (%rsp,%rax), %r12
addq $0x120, %r12            # imm = 0x120
pushq $0x3
popq %r13
testl %r13d, %r13d
js 0x43fe
movl %r13d, %ebp
shlq $0x4, %rbp
leaq (%rsp,%rbp), %rdi
addq $0xa0, %rdi
movq %rbx, %rsi
callq 0x2834
movq %rax, (%rbp,%r12)
movq %rdx, 0x8(%rbp,%r12)
decl %r13d
jmp 0x43d0
decq %r15
jmp 0x43a3
leaq 0x150(%rsp), %rbx
movq %rbx, %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, 0x20(%rsp)
leaq 0x140(%rsp), %r15
movq %r15, %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rsp, %r13
movq %rax, (%r13)
andq $0x0, 0x8(%r13)
movq %rbx, %rdi
callq 0x2cce
movq (%rax), %rax
leaq 0x30(%rsp), %rbx
movq %rax, (%rbx)
andq $0x0, 0x8(%rbx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x27ec
leaq 0x50(%rsp), %rcx
movq %rax, (%rcx)
movq %rdx, 0x8(%rcx)
leaq 0x130(%rsp), %r12
movq %r12, %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, (%r13)
andq $0x0, 0x8(%r13)
movq %r15, %rdi
callq 0x2cce
movq (%rax), %rax
movq %rax, (%rbx)
andq $0x0, 0x8(%rbx)
movq %rsp, %rbx
leaq 0x30(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x27ec
leaq 0x110(%rsp), %r15
movq %rax, (%r15)
movq %rdx, 0x8(%r15)
leaq 0x120(%rsp), %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, (%rbx)
andq $0x0, 0x8(%rbx)
movq %r12, %rdi
callq 0x2cce
movq (%rax), %rax
movq %rax, (%r13)
andq $0x0, 0x8(%r13)
movq %rsp, %rbx
leaq 0x30(%rsp), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x27ec
leaq 0x100(%rsp), %r12
movq %rax, (%r12)
movq %rdx, 0x8(%r12)
leaq 0x190(%rsp), %r14
movq %r14, %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, (%rbx)
andq $0x0, 0x8(%rbx)
movq %rsp, %rbx
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x27fc
leaq 0x180(%rsp), %r13
movq %r13, %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, (%rbp)
andq $0x0, 0x8(%rbp)
movq %r14, %rdi
callq 0x2cce
movq (%rax), %rax
leaq 0xe0(%rsp), %rbp
movq %rax, (%rbp)
andq $0x0, 0x8(%rbp)
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x27ec
movq %rax, (%rbx)
movq %rdx, 0x8(%rbx)
movq %rsp, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x27fc
leaq 0x170(%rsp), %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, (%r14)
andq $0x0, 0x8(%r14)
movq %r13, %rdi
callq 0x2cce
movq (%rax), %rax
movq %rax, (%rbp)
andq $0x0, 0x8(%rbp)
leaq 0x30(%rsp), %rbp
leaq 0xe0(%rsp), %r13
movq %rbp, %rdi
movq %r13, %rsi
callq 0x27ec
movq %rax, (%rbx)
movq %rdx, 0x8(%rbx)
movq %rsp, %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x27fc
leaq 0x1d0(%rsp), %r14
movq %r14, %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, (%rbx)
andq $0x0, 0x8(%rbx)
movq %rsp, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x27fc
leaq 0x1c0(%rsp), %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, (%rbp)
andq $0x0, 0x8(%rbp)
movq %r14, %rdi
callq 0x2cce
movq (%rax), %rax
movq %rax, (%r13)
andq $0x0, 0x8(%r13)
leaq 0x30(%rsp), %rdi
leaq 0xe0(%rsp), %r13
movq %r13, %rsi
callq 0x27ec
movq %rax, (%rbx)
movq %rdx, 0x8(%rbx)
movq %rsp, %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x27fc
leaq 0x210(%rsp), %rdi
callq 0x2cd4
movq (%rax), %rax
movq %rax, (%rbx)
andq $0x0, 0x8(%rbx)
movq %rsp, %rsi
movq %r12, %rdi
callq 0x27fc
leaq 0x7aeb(%rip), %rbx      # 0xc180
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2628
leaq 0x2961(%rip), %r12      # 0x7008
movups (%r12), %xmm0
movaps %xmm0, (%r13)
movq %rax, 0x10(%r13)
movq %rdx, 0x18(%r13)
leaq 0x50(%rsp), %r13
movq %r13, %rdi
callq 0x2cce
movq %rax, %r14
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2628
leaq 0x268(%rsp), %rcx
movq %rax, (%rcx)
movq %rdx, 0x8(%rcx)
movq (%r14), %rax
movq %rax, 0x10(%rcx)
andq $0x0, 0x18(%rcx)
leaq 0x30(%rsp), %rbx
leaq 0xe0(%rsp), %rsi
movq %rbx, %rdi
movq %rcx, %rdx
callq 0x40a0
movups (%r12), %xmm0
leaq 0x220(%rsp), %rdx
movaps %xmm0, (%rdx)
movups (%r15), %xmm0
movaps %xmm0, 0x10(%rdx)
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40a0
leaq 0x248(%rsp), %rdx
movq 0x20(%rsp), %rax
movq %rax, (%rdx)
andq $0x0, 0x8(%rdx)
movups (%r12), %xmm0
movups %xmm0, 0x10(%rdx)
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x40a0
movq %rbx, %rax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq