// File: /workspace/github_c_makefile_star2_O1/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 $0x858, %rsp            # imm = 0x858
movl %r8d, %r12d
movl %ecx, -0x3c(%rbp)
movq %rdx, -0x60(%rbp)
movq %rsi, %r8
movq %rdi, -0x68(%rbp)
movabsq $0x685f98a2018fade9, %rax # imm = 0x685F98A2018FADE9
movabsq $0x5851f42d4c957f2d, %r11 # imm = 0x5851F42D4C957F2D
movl %r12d, %edi
shll $0x8, %edi
leal 0x1(%rdi), %ecx
leaq 0xf(,%rcx,4), %rcx
movabsq $0x3fffffc10, %rdx      # imm = 0x3FFFFFC10
andq %rcx, %rdx
movq %rsp, %rbx
subq %rdx, %rbx
movq %rbx, %rsp
movq %rsp, %r14
subq %rdx, %r14
movq %r14, %rsp
movl %edi, %r10d
movq %rdi, -0x70(%rbp)
testl %edi, %edi
je 0x3f4b
movq 0x9124(%rip), %rcx      # 0xd040
xorl %edx, %edx
movq %rcx, %r15
shrq $0x20, %r15
movq %rcx, %rdi
imulq %r11, %rdi
movl %r15d, (%rbx,%rdx,4)
shrq $0x20, %rdi
imulq %rax, %rcx
movl %edi, (%r14,%rdx,4)
incq %rdx
cmpq %rdx, %r10
jne 0x3f1e
movq %rcx, 0x90f5(%rip)      # 0xd040
movq %rbx, -0x48(%rbp)
movq %r10, -0x78(%rbp)
movq %r14, -0x38(%rbp)
movq 0x90e2(%rip), %rcx      # 0xd040
xorl %edx, %edx
movq %rcx, %rsi
shrq $0x20, %rsi
movq %rcx, %rdi
imulq %r11, %rdi
movl %esi, -0x480(%rbp,%rdx,4)
shrq $0x20, %rdi
imulq %rax, %rcx
movl %edi, -0x880(%rbp,%rdx,4)
incq %rdx
cmpq $0x100, %rdx            # imm = 0x100
jne 0x3f60
movq %rcx, 0x90a9(%rip)      # 0xd040
movl %r9d, %eax
shll $0x8, %eax
movq %rsp, %rcx
movq %rax, -0x80(%rbp)
addl $0x10, %eax
subq %rax, %rcx
movq %rcx, %rsp
movw $0x4d62, (%rcx)         # imm = 0x4D62
addq $0x2, %rcx
movq %rcx, -0x58(%rbp)
movl %r9d, -0x30(%rbp)
xorl %r14d, %r14d
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r12, -0x50(%rbp)
movq -0x48(%rbp), %r15
movq %r8, %r12
movl %r14d, %eax
leaq (%r15,%rax,4), %rdi
movl %ebx, %esi
addq -0x58(%rbp), %rsi
movl -0x480(%rbp,%r13,4), %edx
callq *%r12
incq %r13
addl -0x30(%rbp), %ebx
addl -0x50(%rbp), %r14d
cmpq $0x100, %r13            # imm = 0x100
jne 0x3fd1
movq -0x80(%rbp), %r15
movl %r15d, %eax
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %r12
movb $0x78, (%r12,%rax)
movl 0x18(%rbp), %eax
addl %r15d, %eax
movb $0x0, (%r12,%rax)
movl $0x10000, %r14d         # imm = 0x10000
xorl %r13d, %r13d
leaq -0x880(%rbp), %rbx
movq %r12, %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
callq *-0x60(%rbp)
testq %rax, %rax
je 0x41c1
addq %rax, %r13
decl %r14d
jne 0x402b
cmpl $0x0, -0x70(%rbp)
movq -0x78(%rbp), %rbx
movq -0x48(%rbp), %rdi
je 0x4081
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl -0x3c(%rbp), %ecx
shll %cl, %eax
notl %eax
vmovd %eax, %xmm0
vpbroadcastd %xmm0, %ymm0
xorl %eax, %eax
vpand (%rdi,%rax,4), %ymm0, %ymm1
vmovdqu %ymm1, (%rdi,%rax,4)
addq $0x8, %rax
cmpq %rax, %rbx
jne 0x406e
movq -0x50(%rbp), %rdx
shll $0xa, %edx
movq -0x38(%rbp), %rsi
vzeroupper
callq 0x1050
testl %eax, %eax
jne 0x41ff
movl 0x10(%rbp), %ecx
testl %ecx, %ecx
je 0x40f8
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
notl %eax
vmovd %eax, %xmm0
vpbroadcastd %xmm0, %ymm0
xorl %eax, %eax
vpand -0x480(%rbp,%rax,4), %ymm0, %ymm1
vmovdqu %ymm1, -0x480(%rbp,%rax,4)
addq $0x8, %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x40b7
leaq -0x480(%rbp), %rdi
leaq -0x880(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
vzeroupper
callq 0x1050
testl %eax, %eax
jne 0x421e
vmovq %r13, %xmm0
vpunpckldq 0x63ab(%rip), %xmm0, %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
vsubpd 0x63b3(%rip), %xmm0, %xmm0 # 0xa4c0
vhaddpd %xmm0, %xmm0, %xmm0
movq 0x8ee0(%rip), %rax      # 0xcff8
vcvtsi2sd %rbx, %xmm2, %xmm1
movq (%rax), %rdi
vdivsd %xmm1, %xmm0, %xmm0
vmulsd 0x6544(%rip), %xmm0, %xmm0 # 0xa670
leaq 0x670e(%rip), %rsi      # 0xa841
movq -0x68(%rbp), %rdx
movb $0x1, %al
callq 0x1040
testl %r15d, %r15d
movabsq $0x5851f42d4c957f2d, %rsi # imm = 0x5851F42D4C957F2D
je 0x41b2
xorl %r15d, %r15d
leaq 0x4ef9(%rip), %r13      # 0x9050
leaq -0x880(%rbp), %rbx
movq 0x8edb(%rip), %rax      # 0xd040
movq %rax, %rcx
shrq $0x20, %rcx
imulq %rsi, %rax
movzbl %cl, %edx
cmpb $0x0, (%rdx,%r13)
jns 0x4165
movq %rax, 0x8ebf(%rip)      # 0xd040
movb (%r12,%r15), %r14b
movb %cl, (%r12,%r15)
movq %r12, %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
callq *-0x60(%rbp)
testq %rax, %rax
jne 0x41e0
movb %r14b, (%r12,%r15)
incq %r15
cmpq -0x30(%rbp), %r15
movabsq $0x5851f42d4c957f2d, %rsi # imm = 0x5851F42D4C957F2D
jne 0x415e
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6558(%rip), %rdi      # 0xa720
leaq 0x6553(%rip), %rsi      # 0xa722
leaq 0x6561(%rip), %rcx      # 0xa737
movl $0x7b, %edx
callq 0x1030
leaq 0x6677(%rip), %rdi      # 0xa85e
leaq 0x6534(%rip), %rsi      # 0xa722
leaq 0x6542(%rip), %rcx      # 0xa737
movl $0x91, %edx
callq 0x1030
leaq 0x65ff(%rip), %rdi      # 0xa805
leaq 0x6515(%rip), %rsi      # 0xa722
leaq 0x6523(%rip), %rcx      # 0xa737
movl $0x80, %edx
callq 0x1030
leaq 0x65fe(%rip), %rdi      # 0xa823
leaq 0x64f6(%rip), %rsi      # 0xa722
leaq 0x6504(%rip), %rcx      # 0xa737
movl $0x84, %edx
callq 0x1030