// File: /workspace/github_cpp_makefile_star2_O2/sokolcom[P]tp-blockchain-task06/uint256_t/uint256_t.cpp
// Function: uint256_t::divmod(uint256_t const&, uint256_t const&) const
std::pair <uint256_t, uint256_t> uint256_t::divmod(const uint256_t & lhs, const uint256_t & rhs) const{
    // Save some calculations /////////////////////
    if (rhs == uint256_0){
        throw std::domain_error("Error: division or modulus by 0");
    }
    else if (rhs == uint256_1){
        return std::pair <uint256_t, uint256_t> (lhs, uint256_0);
    }
    else if (lhs == rhs){
        return std::pair <uint256_t, uint256_t> (uint256_1, uint256_0);
    }
    else if ((lhs == uint256_0) || (lhs < rhs)){
        return std::pair <uint256_t, uint256_t> (uint256_0, lhs);
    }

    std::pair <uint256_t, uint256_t> qr(uint256_0, lhs);
    uint256_t copyd = rhs << (lhs.bits() - rhs.bits());
    uint256_t adder = uint256_1 << (lhs.bits() - rhs.bits());
    if (copyd > qr.second){
        copyd >>= uint256_1;
        adder >>= uint256_1;
    }
    while (qr.second >= rhs){
        if (qr.second >= copyd){
            qr.second -= copyd;
            qr.first |= adder;
        }
        copyd >>= uint256_1;
        adder >>= uint256_1;
    }
    return qr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r14
movq %rdx, %r12
movq %rdi, %rbx
leaq 0x79b2(%rip), %rsi      # 0xc1b0
movq %rcx, %rdi
callq 0x3e80
testb %al, %al
jne 0x4966
leaq 0x79bb(%rip), %rsi      # 0xc1d0
movq %r14, %rdi
callq 0x3e80
testb %al, %al
je 0x4832
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm1, 0x10(%rbx)
jmp 0x4853
movq %r12, %rdi
movq %r14, %rsi
callq 0x3e80
testb %al, %al
je 0x487e
movups 0x7998(%rip), %xmm0     # 0xc1e0
movups %xmm0, 0x10(%rbx)
movups 0x797d(%rip), %xmm0     # 0xc1d0
movups %xmm0, (%rbx)
movups 0x7953(%rip), %xmm0     # 0xc1b0
movups %xmm0, 0x20(%rbx)
movups 0x7958(%rip), %xmm0     # 0xc1c0
movups %xmm0, 0x30(%rbx)
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x792b(%rip), %rsi      # 0xc1b0
movq %r12, %rdi
callq 0x3e80
testb %al, %al
jne 0x48a0
movq %r12, %rdi
movq %r14, %rsi
callq 0x3f9a
testb %al, %al
je 0x48ca
movups 0x7919(%rip), %xmm0     # 0xc1c0
movups %xmm0, 0x10(%rbx)
movups 0x78fe(%rip), %xmm0     # 0xc1b0
movups %xmm0, (%rbx)
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm0, 0x20(%rbx)
movups %xmm1, 0x30(%rbx)
jmp 0x486c
movups 0x78ef(%rip), %xmm0     # 0xc1c0
movups %xmm0, 0x10(%rbx)
movups 0x78d4(%rip), %xmm0     # 0xc1b0
movups %xmm0, (%rbx)
leaq 0x20(%rbx), %r15
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm0, 0x20(%rbx)
movups %xmm1, 0x30(%rbx)
movq %r12, %rdi
callq 0x4a0a
movzwl %ax, %ebp
movq %r14, %rdi
callq 0x4a0a
movzwl %ax, %eax
subl %eax, %ebp
leaq 0x8(%rsp), %rdx
movl %ebp, (%rdx)
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x5c40
movq %r12, %rdi
callq 0x4a0a
movzwl %ax, %ebp
movq %r14, %rdi
callq 0x4a0a
movzwl %ax, %eax
subl %eax, %ebp
leaq 0x4(%rsp), %rdx
movl %ebp, (%rdx)
leaq 0x7885(%rip), %rsi      # 0xc1d0
leaq 0x8(%rsp), %rdi
callq 0x5c40
movq %r13, %rdi
movq %r15, %rsi
callq 0x3f30
testb %al, %al
jne 0x49a9
jmp 0x49ca
pushq $0x10
popq %rdi
callq 0x20b0
movq %rax, %rbx
leaq 0x26b0(%rip), %rsi      # 0x7028
movq %rax, %rdi
callq 0x20e0
movq 0x7609(%rip), %rsi      # 0xbf90
movq 0x7612(%rip), %rdx      # 0xbfa0
movq %rbx, %rdi
callq 0x2260
movq %rax, %r14
movq %rbx, %rdi
callq 0x2100
movq %r14, %rdi
callq 0x2270
leaq 0x7820(%rip), %r12      # 0xc1d0
leaq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0x3d98
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x3d98
movq %r15, %rdi
movq %r14, %rsi
callq 0x4004
testb %al, %al
je 0x486c
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x4004
testb %al, %al
je 0x49a9
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x423e
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3830
jmp 0x49a9