// File: Lut99[P]RayTracer/src/lib/ProgressBar.cpp
// Function: std::ProgressBar::draw() const
void ProgressBar::draw() const {
    // If needed, first get the width of the console
    size_t width = this->width;
    if (this->var_width) {
        width = this->resize_to_term_width();
    }
    // The inner width is the same minus to, to account for []
    size_t bar_inner_width = width - 8 - this->left.length() - this->right.length() - 2;
    // Check if this is possible
    if (bar_inner_width < 1) {
        throw runtime_error("Given width " + to_string(width) + " is too small for the progress bar.");
    }

    cout << '\r';
    cout << this->left;
    cout << " [";

    // Draw as many '=' as we have progress
    double ratio = ((double) (this->progress - this->min) / (double) (this->max) - this->min);
    size_t things_to_print = (size_t) (ratio * bar_inner_width);

    for (size_t i = 0; i < things_to_print; i++) {
        cout << '=';
    }
    for (size_t i = things_to_print; i < bar_inner_width; i++) {
        cout << ' ';
    }

    cout << "] ";
    // Draw percentage
    cout << ((int) (ratio * 100)) << "%";

    cout.flush();
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x28(%rsp)
movslq 0x60(%rax), %rcx
movq %rcx, 0xc8(%rsp)
testb $0x1, 0x6c(%rax)
je 0x1606b2
movq 0x28(%rsp), %rdi
callq 0x1609c0
cltq
movq %rax, 0xc8(%rsp)
movq 0x28(%rsp), %rdi
movq 0xc8(%rsp), %rax
subq $0x8, %rax
movq %rax, 0x18(%rsp)
addq $0x20, %rdi
callq 0xd0880
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movq 0x18(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x20(%rsp)
addq $0x40, %rdi
callq 0xd0880
movq %rax, %rcx
movq 0x20(%rsp), %rax
subq %rcx, %rax
subq $0x2, %rax
movq %rax, 0xc0(%rsp)
cmpq $0x1, 0xc0(%rsp)
jae 0x160826
movb $0x1, 0x53(%rsp)
movl $0x10, %edi
callq 0xd02b0
movq %rax, 0x10(%rsp)
movq 0xc8(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x12e250
jmp 0x16073d
leaq 0x17947(%rip), %rsi     # 0x17808b
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0x12d820
jmp 0x160758
leaq 0x17939(%rip), %rdx     # 0x178098
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xe6bb0
jmp 0x160776
movq 0x10(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xd0920
jmp 0x16078a
movq 0x10(%rsp), %rdi
movb $0x0, 0x53(%rsp)
movq 0x4b855(%rip), %rsi     # 0x1abff0
movq 0x4b7c6(%rip), %rdx     # 0x1abf68
callq 0xd09b0
jmp 0x1609bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x16080e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x160804
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x1607f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0xd0b38
leaq 0x80(%rsp), %rdi
callq 0xd0b38
leaq 0x60(%rsp), %rdi
callq 0xd0b38
testb $0x1, 0x53(%rsp)
jne 0x160817
jmp 0x160821
movq 0x10(%rsp), %rdi
callq 0xd0430
jmp 0x1609b2
movq 0x4b75b(%rip), %rdi     # 0x1abf88
movq %rdi, 0x8(%rsp)
movl $0xd, %esi
callq 0xd06c0
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
addq $0x20, %rsi
callq 0xd0540
movq 0x8(%rsp), %rdi
leaq 0x17861(%rip), %rsi     # 0x1780bc
callq 0xd05b0
movq 0x28(%rsp), %rcx
movq 0x8(%rcx), %rdx
movq 0x10(%rcx), %rax
subq %rax, %rdx
cvtsi2sd %rdx, %xmm0
cvtsi2sdq 0x18(%rcx), %xmm1
divsd %xmm1, %xmm0
cvtsi2sd %rax, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
movaps 0x17095(%rip), %xmm2    # 0x177930
movq 0xc0(%rsp), %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x17090(%rip), %xmm2    # 0x177940
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x17416(%rip), %xmm1    # 0x177cf0
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x40(%rsp), %rax
jae 0x160924
movq 0x4b67e(%rip), %rdi     # 0x1abf88
movl $0x3d, %esi
callq 0xd06c0
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x1608f7
movq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0xc0(%rsp), %rax
jae 0x16095e
movq 0x4b644(%rip), %rdi     # 0x1abf88
movl $0x20, %esi
callq 0xd06c0
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x16092e
movq 0x4b623(%rip), %rdi     # 0x1abf88
leaq 0x11b31(%rip), %rsi     # 0x17249d
callq 0xd05b0
movsd 0xf6bf(%rip), %xmm0     # 0x170038
mulsd 0x48(%rsp), %xmm0
cvttsd2si %xmm0, %esi
movq 0x4b5fe(%rip), %rdi     # 0x1abf88
callq 0xd09e0
movq %rax, %rdi
leaq 0x17726(%rip), %rsi     # 0x1780bf
callq 0xd05b0
movq 0x4b5e3(%rip), %rdi     # 0x1abf88
callq 0xd03e0
addq $0xd8, %rsp
retq
movq 0x58(%rsp), %rdi
callq 0xd0a10
nopl (%rax)