// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
leaq 0xf52a(%rip), %rax      # 0x273fb
movq %rax, -0x30(%rbp)
leaq 0xf529(%rip), %rax      # 0x27405
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x84a0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
movl $0x10, %r8d
callq 0x18180
movq %rax, -0x40(%rbp)
callq 0x8170
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0xad(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0xa5(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x9d(%rbp)
movl 0x18(%rax), %ecx
movl %ecx, -0x95(%rbp)
movw 0x1c(%rax), %ax
movw %ax, -0x91(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x17f64
movq -0x18(%rbp), %rax
movb 0x2(%rax), %al
movb %al, -0xab(%rbp)
leaq -0xad(%rbp), %rdi
addq $0x1e, %rdi
movl $0x55, %esi
movl $0x3f, %edx
callq 0x8480
movb $0x0, -0x51(%rbp)
movq -0x30(%rbp), %rdi
leaq -0xad(%rbp), %rsi
leaq -0xad(%rbp), %rdx
addq $0x1e, %rdx
movl $0x3d, %ecx
movl $0x1, %r8d
callq 0x18180
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rcx
leaq -0xad(%rbp), %rdx
addq $0x1e, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x1f1(%rbp)
jne 0x18025
movq -0x48(%rbp), %rdi
leaq -0xad(%rbp), %rsi
movl $0x1d, %edx
callq 0x8510
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x1f1(%rbp)
jne 0x18025
movq -0x48(%rbp), %rdi
addq $0x1d, %rdi
movzbl -0xab(%rbp), %eax
andl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x17d87(%rip), %rax     # 0x2fd90
movq (%rax,%rcx,8), %rsi
movl $0x22, %edx
callq 0x8510
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x1f1(%rbp)
movb -0x1f1(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x50(%rbp)
leaq 0xf3e9(%rip), %rax      # 0x27423
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x150(%rbp), %rdx
movl $0x2, %ecx
callq 0x1e7e0
movq -0xb8(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
leaq -0x1f0(%rbp), %rdx
movl $0x4, %ecx
callq 0x1e7e0
movl -0x150(%rbp), %eax
xorl $0x10000, %eax          # imm = 0x10000
movl %eax, -0x150(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x50(%rbp)
movb %al, -0x1f2(%rbp)
je 0x18113
xorl %eax, %eax
cmpl $0xdb9c59bc, -0x150(%rbp) # imm = 0xDB9C59BC
movb %al, -0x1f2(%rbp)
jne 0x18113
xorl %eax, %eax
cmpl $0x33343500, -0x15c(%rbp) # imm = 0x33343500
movb %al, -0x1f2(%rbp)
jne 0x18113
leaq -0x100(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
movl $0x48, %edx
callq 0x8510
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x1f2(%rbp)
jne 0x18113
leaq -0x150(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
movl $0x48, %edx
callq 0x8510
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x1f2(%rbp)
movb -0x1f2(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x1f8(%rbp)
callq 0x8170
movl -0x1f8(%rbp), %ecx
movl %ecx, (%rax)
cmpl $0x0, -0x50(%rbp)
je 0x18147
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1816a
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x84a0
callq 0x8170
movl $0x16, (%rax)
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
nopw (%rax,%rax)