// File: /workspace/github_c_makefile_star2_O0/neosploit[P]compiler/libfort/lib/fort.c
// Function: wsnprint_n_string
static
int wsnprint_n_string(wchar_t *buf, size_t length, size_t n, const char *str)
{
    size_t str_len = strlen(str);

    /* note: maybe it's, better to return -1 in case of multibyte character
     * strings (not sure this case is done correctly).
     */
    if (str_len > 1) {
        const unsigned char *p = (const unsigned char *)str;
        while (*p) {
            if (*p <= 127)
                p++;
            else {
                wchar_t wcs[WCS_SIZE];
                const char *ptr = str;
                size_t wcs_len;
                mbstate_t mbst;
                memset(&mbst, 0, sizeof(mbst));
                wcs_len = mbsrtowcs(wcs, (const char **)&ptr, WCS_SIZE, &mbst);
                /* for simplicity */
                if ((wcs_len == (size_t) - 1) || wcs_len > 1) {
                    return -1;
                } else {
                    wcs[wcs_len] = L'\0';
                    size_t k = n;
                    while (k) {
                        *buf = *wcs;
                        ++buf;
                        --k;
                    }
                    buf[n] = L'\0';
                    return (int)n;
                }
            }
        }
    }

    if (length <= n * str_len)
        return -1;

    if (n == 0)
        return 0;

    /* To ensure valid return value it is safely not print such big strings */
    if (n * str_len > INT_MAX)
        return -1;

    if (str_len == 0)
        return 0;

    int status = swprintf(buf, length, L"%0*d", (int)(n * str_len), 0);
    if (status < 0)
        return status;

    size_t i = 0;
    for (i = 0; i < n; ++i) {
        const char *str_p = str;
        while (*str_p)
            *(buf++) = (wchar_t) * (str_p++);
    }
    return (int)(n * str_len);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x70d0
movq %rax, -0x30(%rbp)
cmpq $0x1, -0x30(%rbp)
jbe 0x1c1ae
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpb $0x0, (%rax)
je 0x1c1ac
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x7f, %eax
jg 0x1c0d5
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1c1a7
movq -0x28(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0x158(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x7130
leaq -0x140(%rbp), %rdi
leaq -0x148(%rbp), %rsi
movl $0x40, %edx
leaq -0x158(%rbp), %rcx
callq 0x71c0
movq %rax, -0x150(%rbp)
cmpq $-0x1, -0x150(%rbp)
je 0x1c12d
cmpq $0x1, -0x150(%rbp)
jbe 0x1c139
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1c2d7
movq -0x150(%rbp), %rax
movl $0x0, -0x140(%rbp,%rax,4)
movq -0x20(%rbp), %rax
movq %rax, -0x160(%rbp)
cmpq $0x0, -0x160(%rbp)
je 0x1c18c
movl -0x140(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x10(%rbp)
movq -0x160(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x160(%rbp)
jmp 0x1c156
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movq -0x20(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x1c2d7
jmp 0x1c0ab
jmp 0x1c1ae
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
imulq -0x30(%rbp), %rcx
cmpq %rcx, %rax
ja 0x1c1cc
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1c2d7
cmpq $0x0, -0x20(%rbp)
jne 0x1c1df
movl $0x0, -0x4(%rbp)
jmp 0x1c2d7
movq -0x20(%rbp), %rax
imulq -0x30(%rbp), %rax
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jbe 0x1c1fc
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1c2d7
cmpq $0x0, -0x30(%rbp)
jne 0x1c20f
movl $0x0, -0x4(%rbp)
jmp 0x1c2d7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rax
imulq -0x30(%rbp), %rax
movl %eax, %ecx
leaq 0x8597(%rip), %rdx      # 0x247c0
xorl %r8d, %r8d
movb $0x0, %al
callq 0x7180
movl %eax, -0x164(%rbp)
cmpl $0x0, -0x164(%rbp)
jge 0x1c250
movl -0x164(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1c2d7
movq $0x0, -0x170(%rbp)
movq $0x0, -0x170(%rbp)
movq -0x170(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x1c2cb
movq -0x28(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rax
cmpb $0x0, (%rax)
je 0x1c2b5
movq -0x178(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x178(%rbp)
movsbl (%rax), %ecx
movq -0x10(%rbp), %rax
movq %rax, %rdx
addq $0x4, %rdx
movq %rdx, -0x10(%rbp)
movl %ecx, (%rax)
jmp 0x1c27e
jmp 0x1c2b7
movq -0x170(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x170(%rbp)
jmp 0x1c266
movq -0x20(%rbp), %rax
imulq -0x30(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
nopw %cs:(%rax,%rax)