// File: /workspace/github_c_makefile_star2_O3/aerospike[P]aerospike-common/src/main/aerospike/crypt_blowfish.c
// Function: crypt_blowfish_rn
char *_crypt_blowfish_rn(const char *key, const char *setting,
	char *output, int size)
{
	const char *test_key = "8b \xd0\xc1\xd2\xcf\xcc\xd8";
	const char *test_setting = "$2a$00$abcdefghijklmnopqrstuu";
	static const char * const test_hash[2] =
		{"VUrPmXD6q/nVSSp7pNDhCR9071IfIRe\0\x55", /* $2x$ */
		"i1D709vfamulimlGcq0qq3UvuUasvEa\0\x55"}; /* $2a$, $2y$ */
	char *retval;
	const char *p;
	int save_errno, ok;
	struct {
		char s[7 + 22 + 1];
		char o[7 + 22 + 31 + 1 + 1 + 1];
	} buf;

/* Hash the supplied password */
	_crypt_output_magic(setting, output, size);
	retval = BF_crypt(key, setting, output, size, 16);
	save_errno = errno;

/*
 * Do a quick self-test.  It is important that we make both calls to BF_crypt()
 * from the same scope such that they likely use the same stack locations,
 * which makes the second call overwrite the first call's sensitive data on the
 * stack and makes it more likely that any alignment related issues would be
 * detected by the self-test.
 */
	memcpy(buf.s, test_setting, sizeof(buf.s));
	if (retval)
		buf.s[2] = setting[2];
	memset(buf.o, 0x55, sizeof(buf.o));
	buf.o[sizeof(buf.o) - 1] = 0;
	p = BF_crypt(test_key, buf.s, buf.o, sizeof(buf.o) - (1 + 1), 1);

	ok = (p == buf.o &&
	    !memcmp(p, buf.s, 7 + 22) &&
	    !memcmp(p + (7 + 22),
	    test_hash[(unsigned int)(unsigned char)buf.s[2] & 1],
	    31 + 1 + 1 + 1));

	{
		const char *k = "\xff\xa3" "34" "\xff\xff\xff\xa3" "345";
		BF_key ae, ai, ye, yi;
		BF_set_key(k, ae, ai, 2); /* $2a$ */
		BF_set_key(k, ye, yi, 4); /* $2y$ */
		ai[0] ^= 0x10000; /* undo the safety (for comparison) */
		ok = ok && ai[0] == 0xdb9c59bc && ye[17] == 0x33343500 &&
		    !memcmp(ae, ye, sizeof(ae)) &&
		    !memcmp(ai, yi, sizeof(ai));
	}

	__set_errno(save_errno);
	if (ok)
		return retval;

/* Should not happen */
	_crypt_output_magic(setting, output, size);
	__set_errno(EINVAL); /* pretend we don't support this hash type */
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rdx, %rbx
movq %rsi, %r14
cmpl $0x3, %ecx
jl 0x114ff
movw $0x302a, (%rbx)         # imm = 0x302A
movb $0x0, 0x2(%rbx)
cmpb $0x2a, (%r14)
jne 0x114ff
cmpb $0x30, 0x1(%r14)
jne 0x114ff
movb $0x31, 0x1(%rbx)
movq %r14, %rsi
movq %rbx, %rdx
movl $0x10, %r8d
movl %ecx, 0x4(%rsp)
callq 0x11726
movq %rax, %r12
callq 0x8150
movq %rax, %r15
movl (%rax), %eax
movabsq $0x6124303024613224, %rdx # imm = 0x6124303024613224
movabsq $0x6968676665646362, %rcx # imm = 0x6968676665646362
testq %r12, %r12
movq %rdx, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movabsq $0x71706f6e6d6c6b6a, %rdx # imm = 0x71706F6E6D6C6B6A
movabsq $0x75757473727170, %rcx # imm = 0x75757473727170
movq %rdx, 0x20(%rsp)
movq %rcx, 0x26(%rsp)
movl %eax, (%rsp)
je 0x1156d
movb 0x2(%r14), %al
movb %al, 0x12(%rsp)
leaq 0x2e(%rsp), %r13
movabsq $0x5555555555555555, %rax # imm = 0x5555555555555555
leaq 0x6e88(%rip), %rdi      # 0x1840b
leaq 0x10(%rsp), %rsi
movl $0x3d, %ecx
movl $0x1, %r8d
movq %r13, %rdx
movq %rax, 0x36(%r13)
movq %rax, 0x30(%r13)
movq %rax, 0x28(%r13)
movq %rax, 0x20(%r13)
movq %rax, 0x18(%r13)
movq %rax, 0x10(%r13)
movq %rax, 0x8(%r13)
movq %rax, (%r13)
movb $0x0, 0x3e(%r13)
callq 0x11726
cmpq %r13, %rax
movq %r14, 0x8(%rsp)
jne 0x115fb
movdqu (%rax), %xmm0
movdqu 0x10(%rsp), %xmm2
movdqu 0xd(%rax), %xmm1
movdqu 0x1d(%rsp), %xmm3
pcmpeqb %xmm0, %xmm2
pcmpeqb %xmm1, %xmm3
pand %xmm2, %xmm3
pmovmskb %xmm3, %ecx
cmpl $0xffff, %ecx           # imm = 0xFFFF
je 0x116f4
xorl %ebp, %ebp
leaq 0x6e2f(%rip), %r13      # 0x18433
leaq 0x110(%rsp), %r14
leaq 0x160(%rsp), %rsi
movl $0x2, %ecx
movq %r13, %rdi
movq %r14, %rdx
callq 0x13640
leaq 0x70(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
movq %r13, %rdi
movl $0x4, %ecx
callq 0x13640
movl (%r14), %eax
movl %eax, %ecx
xorl $0x10000, %ecx          # imm = 0x10000
testb %bpl, %bpl
movl %ecx, (%r14)
je 0x11680
cmpl $0xdb9d59bc, %eax       # imm = 0xDB9D59BC
jne 0x11680
cmpl $0x33343500, 0xb4(%rsp) # imm = 0x33343500
jne 0x11680
leaq 0x160(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x48, %edx
callq 0x8770
testl %eax, %eax
je 0x116c9
movl (%rsp), %eax
movl %eax, (%r15)
movq 0x8(%rsp), %rax
cmpl $0x3, 0x4(%rsp)
jl 0x116aa
movw $0x302a, (%rbx)         # imm = 0x302A
movb $0x0, 0x2(%rbx)
cmpb $0x2a, (%rax)
jne 0x116aa
cmpb $0x30, 0x1(%rax)
jne 0x116aa
movb $0x31, 0x1(%rbx)
xorl %r12d, %r12d
movl $0x16, (%r15)
movq %r12, %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x110(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
movl $0x48, %edx
callq 0x8770
testl %eax, %eax
movl (%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, (%r15)
jne 0x1168b
jmp 0x116b4
movzbl 0x12(%rsp), %ecx
leaq 0x6d40(%rip), %rdx      # 0x18440
addq $0x1d, %rax
movq %rax, %rdi
andl $0x1, %ecx
movslq (%rdx,%rcx,4), %rsi
addq %rdx, %rsi
movl $0x22, %edx
callq 0x8770
testl %eax, %eax
sete %bpl
jmp 0x115fd