// File: sokolcom[P]tp-blockchain-task06/uint256_t/uint128_t.cpp
// Function: uint128_t::str[abi:cxx11](unsigned char, unsigned int const&) const
std::string uint128_t::str(uint8_t base, const unsigned int & len) const{
    if ((base < 2) || (base > 16)){
        throw std::invalid_argument("Base must be in the range [2, 16]");
    }
    std::string out = "";
    if (!(*this)){
        out = "0";
    }
    else{
        std::pair <uint128_t, uint128_t> qr(*this, uint128_0);
        do{
            qr = divmod(qr.first, base);
            out = "0123456789abcdef"[(uint8_t) qr.second] + out;
        } while (qr.first);
    }
    if (out.size() < len){
        out = std::string(len - out.size(), '0') + out;
    }
    return out;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x100(%rbp)
movb %dl, %al
movq %rdi, %rdx
movq %rdx, -0xf8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
movzbl -0x11(%rbp), %eax
cmpl $0x2, %eax
jl 0x4e6a
movzbl -0x11(%rbp), %eax
cmpl $0x10, %eax
jle 0x4ec6
movl $0x10, %edi
callq 0x30e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x108(%rbp)
leaq 0xa19c(%rip), %rsi      # 0xf024
callq 0x33b0
jmp 0x4e8f
movq -0x108(%rbp), %rdi
movq 0x11133(%rip), %rsi     # 0x15fd0
movq 0x1111c(%rip), %rdx     # 0x15fc0
callq 0x3360
movq -0x108(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x3190
jmp 0x514a
movb $0x0, -0x2d(%rbp)
leaq -0x2e(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x3390
movq -0x100(%rbp), %rdi
movq -0x110(%rbp), %rdx
leaq 0xa26b(%rip), %rsi      # 0xf15a
callq 0x5ac0
jmp 0x4ef6
leaq -0x2e(%rbp), %rdi
callq 0x3250
movq -0xf0(%rbp), %rdi
callq 0x4040
testb $0x1, %al
jne 0x4f11
jmp 0x4f56
movq -0x100(%rbp), %rdi
leaq 0xa103(%rip), %rsi      # 0xf022
callq 0x32d0
jmp 0x4f26
jmp 0x5013
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x2e(%rbp), %rdi
callq 0x3250
jmp 0x514a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x513e
movq -0xf0(%rbp), %rsi
leaq 0x112ac(%rip), %rdx     # 0x16210
leaq -0x50(%rbp), %rdi
callq 0x59e0
jmp 0x4f6f
jmp 0x4f71
leaq -0x50(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x11(%rbp), %rsi
callq 0x5b70
jmp 0x4f8b
movq -0x118(%rbp), %rdx
movq -0xf0(%rbp), %rsi
leaq -0x70(%rbp), %rdi
leaq -0x80(%rbp), %rcx
callq 0x48f0
jmp 0x4fa8
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x5ba0
leaq -0x40(%rbp), %rdi
callq 0x3a60
movq -0x100(%rbp), %rdx
movzbl %al, %eax
leaq 0xa077(%rip), %rcx      # 0xf046
movsbl (%rax,%rcx), %esi
leaq -0xa0(%rbp), %rdi
callq 0x5be0
jmp 0x4fe1
movq -0x100(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3290
leaq -0xa0(%rbp), %rdi
callq 0x3140
leaq -0x50(%rbp), %rdi
callq 0x3a40
testb $0x1, %al
jne 0x4f71
jmp 0x5013
movq -0x100(%rbp), %rdi
callq 0x3170
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
jae 0x5118
movq -0x100(%rbp), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x130(%rbp)
callq 0x3170
movq %rax, %rcx
movq -0x130(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x128(%rbp)
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x3390
movq -0x128(%rbp), %rsi
movq -0x120(%rbp), %rcx
leaq -0xe0(%rbp), %rdi
movl $0x30, %edx
callq 0x5d30
jmp 0x508f
movq -0x100(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x5ce0
jmp 0x50ab
movq -0x100(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x3290
leaq -0xc0(%rbp), %rdi
callq 0x3140
leaq -0xe0(%rbp), %rdi
callq 0x3140
leaq -0xe1(%rbp), %rdi
callq 0x3250
jmp 0x5118
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x510a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x3140
leaq -0xe1(%rbp), %rdi
callq 0x3250
jmp 0x513e
movb $0x1, -0x2d(%rbp)
testb $0x1, -0x2d(%rbp)
jne 0x512e
movq -0x100(%rbp), %rdi
callq 0x3140
movq -0xf8(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x100(%rbp), %rdi
callq 0x3140
movq -0x28(%rbp), %rdi
callq 0x3380
nopw %cs:(%rax,%rax)