// File: /workspace/github_cpp_makefile_star2_O1/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 0x86be(%rip), %rsi      # 0xd1a8
movq %rbx, %rdi
callq 0x275e
testb %al, %al
je 0x4b0d
leaq 0x869b(%rip), %rsi      # 0xd198
movq %r14, %rdi
callq 0x275e
testb %al, %al
jne 0x4e62
leaq 0x86b4(%rip), %rsi      # 0xd1c8
movq %rbx, %rdi
callq 0x275e
testb %al, %al
je 0x4b45
leaq 0x8691(%rip), %rsi      # 0xd1b8
movq %r14, %rdi
callq 0x275e
testb %al, %al
je 0x4b45
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm1, 0x10(%r13)
jmp 0x4b7b
leaq 0x10(%r12), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x275e
testb %al, %al
je 0x4b9c
movq %r12, %rdi
movq %r14, %rsi
callq 0x275e
testb %al, %al
je 0x4b9c
movups 0x8659(%rip), %xmm0     # 0xd1c8
movups %xmm0, 0x10(%r13)
movups 0x863d(%rip), %xmm0     # 0xd1b8
movups %xmm0, (%r13)
movups 0x8611(%rip), %xmm0     # 0xd198
movups %xmm0, 0x20(%r13)
movdqu 0x8614(%rip), %xmm0     # 0xd1a8
movdqu %xmm0, 0x30(%r13)
jmp 0x4c00
leaq 0x8605(%rip), %rsi      # 0xd1a8
movq %r15, %rdi
callq 0x275e
testb %al, %al
je 0x4bc2
leaq 0x85e2(%rip), %rsi      # 0xd198
movq %r12, %rdi
callq 0x275e
testb %al, %al
jne 0x4bd1
movq %r12, %rdi
movq %r14, %rsi
callq 0x4226
testb %al, %al
je 0x4c08
movups 0x85d0(%rip), %xmm0     # 0xd1a8
movups %xmm0, 0x10(%r13)
movups 0x85b4(%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 0x4e53
movups 0x8599(%rip), %xmm0     # 0xd1a8
movups %xmm0, 0x10(%r13)
movups 0x857d(%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 0x4ea8
movzwl %ax, %ebx
movq %r14, %rdi
callq 0x4ea8
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 0x3399(%rip), %rbp      # 0x8008
movdqu (%rbp), %xmm0
movdqu %xmm0, (%r13)
testl %eax, %eax
jns 0x4c88
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 0x3b1c
movq %r12, %rdi
callq 0x4ea8
movzwl %ax, %r12d
movq %r14, %rdi
callq 0x4ea8
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 0x4ce9
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, (%r13)
leaq 0x84c8(%rip), %rsi      # 0xd1b8
leaq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3b1c
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x41bc
testb %al, %al
je 0x4d73
leaq 0x84a1(%rip), %rbx      # 0xd1b8
leaq 0x8(%rsp), %r12
leaq 0x50(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x3d6e
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 0x3d6e
movdqu (%r12), %xmm0
movups 0x10(%r12), %xmm1
movaps %xmm1, 0x10(%r13)
movdqa %xmm0, (%r13)
movq %r15, %rdi
movq %r14, %rsi
callq 0x4290
testb %al, %al
je 0x4e4f
movq (%rsp), %rax
addq $0x10, %rax
movq %rax, 0x28(%rsp)
leaq 0x50(%rsp), %rbp
leaq 0x8(%rsp), %r12
leaq 0x30(%rsp), %r13
leaq 0x840f(%rip), %rbx      # 0xd1b8
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4290
testb %al, %al
je 0x4df6
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x4450
movdqu 0x8(%rsp), %xmm0
movups 0x18(%rsp), %xmm1
movups %xmm1, 0x10(%r15)
movdqu %xmm0, (%r15)
movq 0x28(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x25f4
movq (%rsp), %rdi
movq %r13, %rsi
callq 0x25f4
movq %r12, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x3d6e
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 0x3d6e
movdqu 0x8(%rsp), %xmm0
movups 0x18(%rsp), %xmm1
movaps %xmm1, 0x40(%rsp)
movdqa %xmm0, 0x30(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x4290
testb %al, %al
jne 0x4da9
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 0x31b2(%rip), %rsi      # 0x8028
movq %rax, %rdi
callq 0x20e0
movq 0x810b(%rip), %rsi      # 0xcf90
movq 0x8114(%rip), %rdx      # 0xcfa0
movq %rbx, %rdi
callq 0x2240
movq %rax, %r14
movq %rbx, %rdi
callq 0x2100
movq %r14, %rdi
callq 0x2250
nop