// File: /workspace/github_c_makefile_star2_O2/svpv[P]rpmset/bench-base64unpack.c
// Function: bench_LOOP
void bench_LOOP(const char *name,
	void (*pack)(const uint32_t *v, char *s, unsigned e),
	uint64_t (*unpack_loop16)(const char *s, uint32_t *v, unsigned *e),
	unsigned m, unsigned n, unsigned c, unsigned em, unsigned o)
{
    uint32_t v[LOOP*n+1], w[LOOP*n+1];
    for (unsigned i = 0; i < LOOP*n; i++)
	v[i] = rand32(), w[i] = rand32();
    unsigned ev[LOOP], ew[LOOP];
    for (unsigned i = 0; i < LOOP; i++)
	ev[i] = rand32(), ew[i] = rand32();
    char s_[2+LOOP*c+2], *s = s_ + 2;
    s_[0] = 'b', s_[1] = 'M';
    for (unsigned i = 0; i < LOOP; i++)
	pack(v + n * i, s + c * i, ev[i]);
    s[LOOP*c] = 'x', s[LOOP*c+o] = '\0';
    uint64_t t = 0;
    for (unsigned i = 0; i < (1<<16); i++) {
	uint64_t x = unpack_loop16(s, w, ew);
	assert(x);
	t += x;
    }
    for (unsigned i = 0; i < LOOP*n; i++)
	v[i] &= (1 << m) - 1;
    assert(memcmp(v, w, LOOP*n * 4) == 0);
    if (em) {
	for (unsigned i = 0; i < LOOP; i++)
	    ev[i] &= (1 << em) - 1;
	assert(memcmp(ev, ew, LOOP * 4) == 0);
    }
    fprintf(stderr, "%s: %.2f cycles per integer\n",
	    name, (double) t / (LOOP*n) / (1<<16));
    // Must fail on invalid inputs.
    for (unsigned i = 0; i < LOOP*c; i++) {
	char fita; // Gogol's indecent letter
	do
	    fita = rand32();
	while ((int32_t)base64dec1(&fita) >= 0);
	char save = s[i];
	s[i] = fita;
	uint64_t x = unpack_loop16(s, w, ew);
	assert(x == 0);
	s[i] = save;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x848, %rsp            # imm = 0x848
movl %r9d, -0x30(%rbp)
movl %r8d, %r9d
movl %ecx, -0x3c(%rbp)
movq %rdx, -0x50(%rbp)
movq %rsi, -0x70(%rbp)
movq %rdi, -0x58(%rbp)
movabsq $0x685f98a2018fade9, %rax # imm = 0x685F98A2018FADE9
movabsq $0x5851f42d4c957f2d, %r8 # imm = 0x5851F42D4C957F2D
movq %r9, -0x48(%rbp)
shll $0x8, %r9d
leal 0x1(%r9), %ecx
leaq 0xf(,%rcx,4), %rcx
movabsq $0x3fffffc10, %rdx      # imm = 0x3FFFFFC10
andq %rcx, %rdx
movq %rsp, %r15
subq %rdx, %r15
movq %r15, %rsp
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x38(%rbp)
movq %rcx, %rsp
movq 0x9450(%rip), %rcx      # 0xc040
xorl %edx, %edx
cmpq %rdx, %r9
je 0x2c24
movq %rcx, %rsi
shrq $0x20, %rsi
movq %rcx, %rdi
imulq %r8, %rdi
movl %esi, (%r15,%rdx,4)
shrq $0x20, %rdi
imulq %rax, %rcx
movq %rcx, 0x9428(%rip)      # 0xc040
movq -0x38(%rbp), %rsi
movl %edi, (%rsi,%rdx,4)
incq %rdx
jmp 0x2bf2
xorl %edx, %edx
cmpq $0x100, %rdx            # imm = 0x100
je 0x2c58
movq %rcx, %rsi
shrq $0x20, %rsi
movq %rcx, %rdi
imulq %r8, %rdi
movl %esi, -0x870(%rbp,%rdx,4)
shrq $0x20, %rdi
imulq %rax, %rcx
movl %edi, -0x470(%rbp,%rdx,4)
incq %rdx
jmp 0x2c26
movq %r9, -0x60(%rbp)
movq %rcx, 0x93dd(%rip)      # 0xc040
movl -0x30(%rbp), %eax
shll $0x8, %eax
movq %rsp, %r12
movq %rax, -0x68(%rbp)
addl $0x10, %eax
subq %rax, %r12
movq %r12, %rsp
movw $0x4d62, (%r12)         # imm = 0x4D62
addq $0x2, %r12
xorl %r14d, %r14d
xorl %ebx, %ebx
xorl %r13d, %r13d
cmpq $0x100, %r13            # imm = 0x100
je 0x2cb8
movl %r14d, %eax
leaq (%r15,%rax,4), %rdi
movl %ebx, %esi
addq %r12, %rsi
movl -0x870(%rbp,%r13,4), %edx
callq *-0x70(%rbp)
incq %r13
addl -0x30(%rbp), %ebx
addl -0x48(%rbp), %r14d
jmp 0x2c8c
movq -0x68(%rbp), %rcx
movl %ecx, %eax
movq %rax, -0x30(%rbp)
movb $0x78, (%r12,%rax)
movl 0x18(%rbp), %eax
addl %ecx, %eax
movb $0x0, (%r12,%rax)
movl $0x10000, %r13d         # imm = 0x10000
xorl %r14d, %r14d
leaq -0x470(%rbp), %rbx
subl $0x1, %r13d
jb 0x2d02
movq %r12, %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
callq *-0x50(%rbp)
testq %rax, %rax
je 0x2e3a
addq %rax, %r14
jmp 0x2ce1
pushq $-0x1
popq %rbx
movl %ebx, %eax
movl -0x3c(%rbp), %ecx
shll %cl, %eax
notl %eax
xorl %ecx, %ecx
movq -0x60(%rbp), %r13
cmpq %rcx, %r13
je 0x2d22
andl %eax, (%r15,%rcx,4)
incq %rcx
jmp 0x2d14
movq -0x48(%rbp), %rdx
shll $0xa, %edx
movq %r15, %rdi
movq -0x38(%rbp), %rsi
callq 0x1050
testl %eax, %eax
jne 0x2e76
movl 0x10(%rbp), %ecx
testl %ecx, %ecx
je 0x2d7e
shll %cl, %ebx
notl %ebx
xorl %eax, %eax
cmpq $0x100, %rax            # imm = 0x100
je 0x2d5e
andl %ebx, -0x870(%rbp,%rax,4)
incq %rax
jmp 0x2d4a
leaq -0x870(%rbp), %rdi
leaq -0x470(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x1050
testl %eax, %eax
jne 0x2e95
vmovq %r14, %xmm0
vpunpckldq 0x5725(%rip), %xmm0, %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
vsubpd 0x572d(%rip), %xmm0, %xmm0 # 0x84c0
vhaddpd %xmm0, %xmm0, %xmm0
movq 0x925a(%rip), %rax      # 0xbff8
vcvtsi2sd %r13, %xmm1, %xmm1
movq (%rax), %rdi
vdivsd %xmm1, %xmm0, %xmm0
vmulsd 0x579e(%rip), %xmm0, %xmm0 # 0x8550
leaq 0x5988(%rip), %rsi      # 0x8741
movq -0x58(%rbp), %rdx
movb $0x1, %al
callq 0x1040
xorl %r14d, %r14d
leaq 0x4282(%rip), %r15      # 0x7050
leaq -0x470(%rbp), %rbx
movabsq $0x5851f42d4c957f2d, %rsi # imm = 0x5851F42D4C957F2D
cmpq -0x30(%rbp), %r14
je 0x2e2b
movq 0x9254(%rip), %rax      # 0xc040
movq %rax, %rcx
shrq $0x20, %rcx
imulq %rsi, %rax
movzbl %cl, %edx
cmpb $0x0, (%rdx,%r15)
jns 0x2dec
movq %rax, 0x9238(%rip)      # 0xc040
movb (%r12,%r14), %r13b
movb %cl, (%r12,%r14)
movq %r12, %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
callq *-0x50(%rbp)
testq %rax, %rax
jne 0x2e57
movb %r13b, (%r12,%r14)
incq %r14
jmp 0x2dd5
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x57df(%rip), %rdi      # 0x8620
leaq 0x57da(%rip), %rsi      # 0x8622
leaq 0x57e8(%rip), %rcx      # 0x8637
pushq $0x7b
popq %rdx
callq 0x1030
leaq 0x5900(%rip), %rdi      # 0x875e
leaq 0x57bd(%rip), %rsi      # 0x8622
leaq 0x57cb(%rip), %rcx      # 0x8637
movl $0x91, %edx
callq 0x1030
leaq 0x5888(%rip), %rdi      # 0x8705
leaq 0x579e(%rip), %rsi      # 0x8622
leaq 0x57ac(%rip), %rcx      # 0x8637
movl $0x80, %edx
callq 0x1030
leaq 0x5887(%rip), %rdi      # 0x8723
leaq 0x577f(%rip), %rsi      # 0x8622
leaq 0x578d(%rip), %rcx      # 0x8637
movl $0x84, %edx
callq 0x1030