// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %rcx, %r14
movq %rdx, %r12
movq %rdi, %r13
leaq 0x10(%rcx), %rbx
leaq 0x86c6(%rip), %rsi      # 0xd1a8
movq %rbx, %rdi
callq 0x2744
testb %al, %al
je 0x4b05
leaq 0x86a3(%rip), %rsi      # 0xd198
movq %r14, %rdi
callq 0x2744
testb %al, %al
jne 0x4e5a
leaq 0x86bc(%rip), %rsi      # 0xd1c8
movq %rbx, %rdi
callq 0x2744
testb %al, %al
je 0x4b3d
leaq 0x8699(%rip), %rsi      # 0xd1b8
movq %r14, %rdi
callq 0x2744
testb %al, %al
je 0x4b3d
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm1, 0x10(%r13)
jmp 0x4b73
leaq 0x10(%r12), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2744
testb %al, %al
je 0x4b94
movq %r12, %rdi
movq %r14, %rsi
callq 0x2744
testb %al, %al
je 0x4b94
movups 0x8661(%rip), %xmm0     # 0xd1c8
movups %xmm0, 0x10(%r13)
movups 0x8645(%rip), %xmm0     # 0xd1b8
movups %xmm0, (%r13)
movups 0x8619(%rip), %xmm0     # 0xd198
movups %xmm0, 0x20(%r13)
movdqu 0x861c(%rip), %xmm0     # 0xd1a8
movdqu %xmm0, 0x30(%r13)
jmp 0x4bf8
leaq 0x860d(%rip), %rsi      # 0xd1a8
movq %r15, %rdi
callq 0x2744
testb %al, %al
je 0x4bba
leaq 0x85ea(%rip), %rsi      # 0xd198
movq %r12, %rdi
callq 0x2744
testb %al, %al
jne 0x4bc9
movq %r12, %rdi
movq %r14, %rsi
callq 0x421e
testb %al, %al
je 0x4c00
movups 0x85d8(%rip), %xmm0     # 0xd1a8
movups %xmm0, 0x10(%r13)
movups 0x85bc(%rip), %xmm0     # 0xd198
movups %xmm0, (%r13)
movdqu (%r12), %xmm0
movups 0x10(%r12), %xmm1
movdqu %xmm0, 0x20(%r13)
movups %xmm1, 0x30(%r13)
movq %r13, %rax
jmp 0x4e4b
movups 0x85a1(%rip), %xmm0     # 0xd1a8
movups %xmm0, 0x10(%r13)
movups 0x8585(%rip), %xmm0     # 0xd198
movups %xmm0, (%r13)
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm0, 0x20(%r13)
movups %xmm1, 0x30(%r13)
movq %r12, %rdi
callq 0x4ea0
movzwl %ax, %ebx
movq %r14, %rdi
callq 0x4ea0
movzwl %ax, %eax
subl %eax, %ebx
movslq %ebx, %rax
movq %r13, %rdx
leaq 0x18(%rsp), %r13
movq %rax, -0x10(%r13)
movl %eax, %ecx
sarl $0x1f, %ecx
movslq %ecx, %rcx
movq %rcx, -0x8(%r13)
leaq 0x33a1(%rip), %rbp      # 0x8008
movdqu (%rbp), %xmm0
movdqu %xmm0, (%r13)
testl %eax, %eax
jns 0x4c80
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, (%r13)
movq %rdx, (%rsp)
leaq 0x20(%rdx), %r15
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rbx
movq %r14, %rsi
movq %rbx, %rdx
callq 0x3b14
movq %r12, %rdi
callq 0x4ea0
movzwl %ax, %r12d
movq %r14, %rdi
callq 0x4ea0
movzwl %ax, %eax
subl %eax, %r12d
movslq %r12d, %rax
movq %rax, (%rbx)
movl %eax, %ecx
sarl $0x1f, %ecx
movslq %ecx, %rcx
movq %rcx, 0x8(%rbx)
movdqu (%rbp), %xmm0
movdqu %xmm0, 0x10(%rbx)
testl %eax, %eax
jns 0x4ce1
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, (%r13)
leaq 0x84d0(%rip), %rsi      # 0xd1b8
leaq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3b14
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x41b4
testb %al, %al
je 0x4d6b
leaq 0x84a9(%rip), %rbx      # 0xd1b8
leaq 0x8(%rsp), %r12
leaq 0x50(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x3d66
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movaps %xmm1, 0x10(%r13)
movaps %xmm0, (%r13)
leaq 0x8(%rsp), %r12
leaq 0x30(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x3d66
movdqu (%r12), %xmm0
movups 0x10(%r12), %xmm1
movaps %xmm1, 0x10(%r13)
movdqa %xmm0, (%r13)
movq %r15, %rdi
movq %r14, %rsi
callq 0x4288
testb %al, %al
je 0x4e47
movq (%rsp), %rax
addq $0x10, %rax
movq %rax, 0x28(%rsp)
leaq 0x50(%rsp), %rbp
leaq 0x8(%rsp), %r12
leaq 0x30(%rsp), %r13
leaq 0x8417(%rip), %rbx      # 0xd1b8
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4288
testb %al, %al
je 0x4dee
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x4448
movdqu 0x8(%rsp), %xmm0
movups 0x18(%rsp), %xmm1
movups %xmm1, 0x10(%r15)
movdqu %xmm0, (%r15)
movq 0x28(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x25de
movq (%rsp), %rdi
movq %r13, %rsi
callq 0x25de
movq %r12, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x3d66
movups 0x8(%rsp), %xmm0
movups 0x18(%rsp), %xmm1
movaps %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x3d66
movdqu 0x8(%rsp), %xmm0
movups 0x18(%rsp), %xmm1
movaps %xmm1, 0x40(%rsp)
movdqa %xmm0, 0x30(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x4288
testb %al, %al
jne 0x4da1
movq (%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x20b0
movq %rax, %rbx
leaq 0x31ba(%rip), %rsi      # 0x8028
movq %rax, %rdi
callq 0x20e0
movq 0x8113(%rip), %rsi      # 0xcf90
movq 0x811c(%rip), %rdx      # 0xcfa0
movq %rbx, %rdi
callq 0x2240
movq %rax, %r14
movq %rbx, %rdi
callq 0x2100
movq %r14, %rdi
callq 0x2250
nop