// File: /workspace/github_c_makefile_star2_O2/wjmelements[P]evm/src/uint256.c
// Function: divmod512
void divmod512(const uint512_t *l, const uint512_t *r, uint512_t *retDiv, uint512_t *retMod) {
    if (gt512(r, l)) {
        copy512(retMod, l);
        clear512(retDiv);
    } else {
        uint512_t copyd, adder, resDiv, resMod;
        uint512_t one;
        clear512(&one);
        LOWER(LOWER(LOWER(one))) = 1;
        uint32_t diffBits = bits512(l) - bits512(r);
        copy512(&resMod, l);
        shiftl512(r, diffBits, &copyd);
        shiftl512(&one, diffBits, &adder);
        if (gt512(&copyd, &resMod)) {
            shiftr512(&copyd, 1, &copyd);
            shiftr512(&adder, 1, &adder);
        }
        clear512(&resDiv);
        while (gte512(&resMod, r)) {
            if (gte512(&resMod, &copyd)) {
                minus512(&resMod, &copyd, &resMod);
                or512(&resDiv, &adder, &resDiv);
            }
            shiftr512(&copyd, 1, &copyd);
            shiftr512(&adder, 1, &adder);
        }
        copy512(retDiv, &resDiv);
        copy512(retMod, &resMod);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
movq %rsi, %rdi
movq %rbx, %rsi
callq 0x3a5e
testb %al, %al
je 0x4978
movq %r14, %rdi
movq %rbx, %rsi
callq 0x327b
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%r12)
movups %xmm0, 0x20(%r12)
movups %xmm0, 0x10(%r12)
movups %xmm0, (%r12)
jmp 0x4b25
movq %r12, (%rsp)
movq %r14, 0x8(%rsp)
xorps %xmm0, %xmm0
leaq 0x110(%rsp), %r14
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
andq $0x0, 0x30(%r14)
movq $0x1, 0x38(%r14)
movq %rbx, %rdi
callq 0x3980
movl %eax, %ebp
movq %r15, %rdi
callq 0x3980
subl %eax, %ebp
movups (%rbx), %xmm0
leaq 0x10(%rsp), %r12
movaps %xmm0, (%r12)
movups 0x10(%rbx), %xmm0
movaps %xmm0, 0x10(%r12)
movups 0x20(%rbx), %xmm0
movaps %xmm0, 0x20(%r12)
movups 0x30(%rbx), %xmm0
movaps %xmm0, 0x30(%r12)
leaq 0xd0(%rsp), %rbx
movq %r15, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x34c6
leaq 0x90(%rsp), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x34c6
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3a5e
testb %al, %al
je 0x4a43
pushq $0x1
popq %rbx
leaq 0xd0(%rsp), %rdi
movl %ebx, %esi
movq %rdi, %rdx
callq 0x376a
leaq 0x90(%rsp), %rdi
movl %ebx, %esi
movq %rdi, %rdx
callq 0x376a
leaq 0x50(%rsp), %r12
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%r12)
movaps %xmm0, 0x20(%r12)
movaps %xmm0, 0x10(%r12)
movaps %xmm0, (%r12)
leaq 0x10(%rsp), %r13
leaq 0xd0(%rsp), %rbp
leaq 0x90(%rsp), %rbx
pushq $0x1
popq %r14
movq %r13, %rdi
movq %r15, %rsi
callq 0x3ad2
testb %al, %al
je 0x4ad3
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3ad2
testb %al, %al
je 0x4ab5
movq %r13, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x3c3d
movq %r12, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x3d02
movq %rbp, %rdi
movl %r14d, %esi
movq %rbp, %rdx
callq 0x376a
movq %rbx, %rdi
movl %r14d, %esi
movq %rbx, %rdx
callq 0x376a
jmp 0x4a7b
movaps 0x50(%rsp), %xmm0
movq (%rsp), %rax
movups %xmm0, (%rax)
movaps 0x60(%rsp), %xmm0
movups %xmm0, 0x10(%rax)
movaps 0x70(%rsp), %xmm0
movups %xmm0, 0x20(%rax)
movaps 0x80(%rsp), %xmm0
movups %xmm0, 0x30(%rax)
movaps 0x10(%rsp), %xmm0
movq 0x8(%rsp), %rax
movups %xmm0, (%rax)
movaps 0x20(%rsp), %xmm0
movups %xmm0, 0x10(%rax)
movaps 0x30(%rsp), %xmm0
movups %xmm0, 0x20(%rax)
movaps 0x40(%rsp), %xmm0
movups %xmm0, 0x30(%rax)
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq