// File: theuni[P]libutreexo/crypto/sha256.cpp
// Function: SHA256AutoDetect[abi:cxx11]()
std::string SHA256AutoDetect()
{
    std::string ret = "standard";
#if defined(USE_ASM) && defined(HAVE_GETCPUID)
    bool have_sse4 = false;
    bool have_xsave = false;
    bool have_avx = false;
    bool have_avx2 = false;
    bool have_shani = false;
    bool enabled_avx = false;

    (void)AVXEnabled;
    (void)have_sse4;
    (void)have_avx;
    (void)have_xsave;
    (void)have_avx2;
    (void)have_shani;
    (void)enabled_avx;

    uint32_t eax, ebx, ecx, edx;
    GetCPUID(1, 0, eax, ebx, ecx, edx);
    have_sse4 = (ecx >> 19) & 1;
    have_xsave = (ecx >> 27) & 1;
    have_avx = (ecx >> 28) & 1;
    if (have_xsave && have_avx) {
        enabled_avx = AVXEnabled();
    }
    if (have_sse4) {
        GetCPUID(7, 0, eax, ebx, ecx, edx);
        have_avx2 = (ebx >> 5) & 1;
        have_shani = (ebx >> 29) & 1;
    }

#if defined(ENABLE_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
    if (have_shani) {
        Transform = sha256_shani::Transform;
        TransformD64 = TransformD64Wrapper<sha256_shani::Transform>;
        TransformD64_2way = sha256d64_shani::Transform_2way;
        ret = "shani(1way,2way)";
        have_sse4 = false; // Disable SSE4/AVX2;
        have_avx2 = false;
    }
#endif

    if (have_sse4) {
#if defined(__x86_64__) || defined(__amd64__)
        Transform = sha256_sse4::Transform;
        TransformD64 = TransformD64Wrapper<sha256_sse4::Transform>;
        ret = "sse4(1way)";
#endif
#if defined(ENABLE_SSE41) && !defined(BUILD_BITCOIN_INTERNAL)
        TransformD64_4way = sha256d64_sse41::Transform_4way;
        ret += ",sse41(4way)";
#endif
    }

#if defined(ENABLE_AVX2) && !defined(BUILD_BITCOIN_INTERNAL)
    if (have_avx2 && have_avx && enabled_avx) {
        TransformD64_8way = sha256d64_avx2::Transform_8way;
        ret += ",avx2(8way)";
    }
#endif
#endif

    assert(SelfTest());
    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x48(%rbp)
movq %rdi, %rax
movq %rax, -0x50(%rbp)
movq %rdi, -0x8(%rbp)
movb $0x0, -0x9(%rbp)
leaq -0xa(%rbp), %rdi
movq %rdi, -0x40(%rbp)
callq 0x1100
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0x50c56(%rip), %rsi     # 0x5201d
callq 0x10d0
jmp 0x13ce
leaq -0xa(%rbp), %rdi
callq 0x10b0
movb $0x0, -0x1d(%rbp)
movb $0x0, -0x1e(%rbp)
movb $0x0, -0x1f(%rbp)
movb $0x0, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movb $0x0, -0x22(%rbp)
movl $0x1, %edi
xorl %esi, %esi
leaq -0x28(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
leaq -0x30(%rbp), %r8
leaq -0x34(%rbp), %r9
callq 0x1640
jmp 0x140d
movl -0x30(%rbp), %eax
shrl $0x13, %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x1d(%rbp)
movl -0x30(%rbp), %eax
shrl $0x1b, %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x1e(%rbp)
movl -0x30(%rbp), %eax
shrl $0x1c, %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x1f(%rbp)
testb $0x1, -0x1e(%rbp)
je 0x149d
testb $0x1, -0x1f(%rbp)
je 0x149d
callq 0x1620
movb %al, -0x51(%rbp)
jmp 0x145f
movb -0x51(%rbp), %al
andb $0x1, %al
movb %al, -0x22(%rbp)
jmp 0x149d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0xa(%rbp), %rdi
callq 0x10b0
jmp 0x160e
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x1070
jmp 0x160e
testb $0x1, -0x1d(%rbp)
je 0x14e9
movl $0x7, %edi
xorl %esi, %esi
leaq -0x28(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
leaq -0x30(%rbp), %r8
leaq -0x34(%rbp), %r9
callq 0x1640
jmp 0x14c1
movl -0x2c(%rbp), %eax
shrl $0x5, %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x20(%rbp)
movl -0x2c(%rbp), %eax
shrl $0x1d, %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x21(%rbp)
testb $0x1, -0x21(%rbp)
je 0x1533
movq -0x48(%rbp), %rdi
leaq 0x271d6(%rip), %rax     # 0x286d0
movq %rax, 0x53b9f(%rip)     # 0x550a0
leaq 0x198(%rip), %rax       # 0x16a0
movq %rax, 0x53b99(%rip)     # 0x550a8
leaq 0x2983a(%rip), %rax     # 0x2ad50
movq %rax, 0x53b9b(%rip)     # 0x550b8
leaq 0x50b02(%rip), %rsi     # 0x52026
callq 0x10c0
jmp 0x152b
movb $0x0, -0x1d(%rbp)
movb $0x0, -0x20(%rbp)
testb $0x1, -0x1d(%rbp)
je 0x1589
movq -0x48(%rbp), %rdi
leaq 0x358cc(%rip), %rax     # 0x36e10
movq %rax, 0x53b55(%rip)     # 0x550a0
leaq 0x2ce(%rip), %rax       # 0x1820
movq %rax, 0x53b4f(%rip)     # 0x550a8
leaq 0x50ad7(%rip), %rsi     # 0x52037
callq 0x10c0
jmp 0x1567
movq -0x48(%rbp), %rdi
leaq 0x364ee(%rip), %rax     # 0x37a60
movq %rax, 0x53b47(%rip)     # 0x550c0
leaq 0x50ac2(%rip), %rsi     # 0x52042
callq 0x10a0
jmp 0x1587
jmp 0x1589
testb $0x1, -0x20(%rbp)
je 0x15bd
testb $0x1, -0x1f(%rbp)
je 0x15bd
testb $0x1, -0x22(%rbp)
je 0x15bd
movq -0x48(%rbp), %rdi
leaq 0x965a(%rip), %rax      # 0xac00
movq %rax, 0x53b1b(%rip)     # 0x550c8
leaq 0x50a9b(%rip), %rsi     # 0x5204f
callq 0x10a0
jmp 0x15bb
jmp 0x15bd
callq 0x19a0
movb %al, -0x52(%rbp)
jmp 0x15c7
movb -0x52(%rbp), %al
testb $0x1, %al
jne 0x15d0
jmp 0x15d2
jmp 0x15f1
leaq 0x50a82(%rip), %rdi     # 0x5205b
leaq 0x50a86(%rip), %rsi     # 0x52066
movl $0x272, %edx            # imm = 0x272
leaq 0x50a8c(%rip), %rcx     # 0x52078
callq 0x1080
movb $0x1, -0x9(%rbp)
testb $0x1, -0x9(%rbp)
jne 0x1604
movq -0x48(%rbp), %rdi
callq 0x1070
movq -0x50(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x10f0
nopw (%rax,%rax)