// File: /workspace/github_c_makefile_star2_O3/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
movq 0x9102(%rip), %rcx      # 0xd040
movl %edi, %r10d
movq %rdi, -0x70(%rbp)
testl %edi, %edi
je 0x3f71
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 0x3f4b
movq %rbx, -0x48(%rbp)
movq %r10, -0x78(%rbp)
movq %r14, -0x38(%rbp)
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 0x3f7f
movq %rcx, 0x908a(%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 0x3ff0
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 0x41e0
addq %rax, %r13
decl %r14d
jne 0x404a
cmpl $0x0, -0x70(%rbp)
movq -0x78(%rbp), %rbx
movq -0x48(%rbp), %rdi
je 0x40a0
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 0x408d
movq -0x50(%rbp), %rdx
shll $0xa, %edx
movq -0x38(%rbp), %rsi
vzeroupper
callq 0x1050
testl %eax, %eax
jne 0x421e
movl 0x10(%rbp), %ecx
testl %ecx, %ecx
je 0x4117
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 0x40d6
leaq -0x480(%rbp), %rdi
leaq -0x880(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
vzeroupper
callq 0x1050
testl %eax, %eax
jne 0x423d
vmovq %r13, %xmm0
vpunpckldq 0x638c(%rip), %xmm0, %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
vsubpd 0x6394(%rip), %xmm0, %xmm0 # 0xa4c0
vhaddpd %xmm0, %xmm0, %xmm0
movq 0x8ec1(%rip), %rax      # 0xcff8
vcvtsi2sd %rbx, %xmm2, %xmm1
movq (%rax), %rdi
vdivsd %xmm1, %xmm0, %xmm0
vmulsd 0x6525(%rip), %xmm0, %xmm0 # 0xa670
leaq 0x66ef(%rip), %rsi      # 0xa841
movq -0x68(%rbp), %rdx
movb $0x1, %al
callq 0x1040
testl %r15d, %r15d
movabsq $0x5851f42d4c957f2d, %rsi # imm = 0x5851F42D4C957F2D
je 0x41d1
xorl %r15d, %r15d
leaq 0x4eda(%rip), %r13      # 0x9050
leaq -0x880(%rbp), %rbx
movq 0x8ebc(%rip), %rax      # 0xd040
movq %rax, %rcx
shrq $0x20, %rcx
imulq %rsi, %rax
movzbl %cl, %edx
cmpb $0x0, (%rdx,%r13)
jns 0x4184
movq %rax, 0x8ea0(%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 0x41ff
movb %r14b, (%r12,%r15)
incq %r15
cmpq -0x30(%rbp), %r15
movabsq $0x5851f42d4c957f2d, %rsi # imm = 0x5851F42D4C957F2D
jne 0x417d
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6539(%rip), %rdi      # 0xa720
leaq 0x6534(%rip), %rsi      # 0xa722
leaq 0x6542(%rip), %rcx      # 0xa737
movl $0x7b, %edx
callq 0x1030
leaq 0x6658(%rip), %rdi      # 0xa85e
leaq 0x6515(%rip), %rsi      # 0xa722
leaq 0x6523(%rip), %rcx      # 0xa737
movl $0x91, %edx
callq 0x1030
leaq 0x65e0(%rip), %rdi      # 0xa805
leaq 0x64f6(%rip), %rsi      # 0xa722
leaq 0x6504(%rip), %rcx      # 0xa737
movl $0x80, %edx
callq 0x1030
leaq 0x65df(%rip), %rdi      # 0xa823
leaq 0x64d7(%rip), %rsi      # 0xa722
leaq 0x64e5(%rip), %rcx      # 0xa737
movl $0x84, %edx
callq 0x1030