#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ memcmp(char *, char const *, int);
char *sha512crypt(char const *, char const *, char *);
char *__crypt_sha512(const char *key, const char *setting, char *output) {
  static const char testkey[] = "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !";
  static const char testsetting[] = "$6$rounds=1234$abc0123456789$";
  static const char testhash[] = "$6$rounds=1234$abc0123456789$BCpt8zLrc/"
                                 "RcyuXmCDOE1ALqMXB2MH6n1g891HhFj8.w7LxGv."
                                 "FTkqq6Vxc/km3Y0jE0j24jY5PIv/oOu6reg1";
  char testbuf[128];
  char *p, *q;
  p = sha512crypt(key, setting, output);
  q = sha512crypt(testkey, testsetting, testbuf);
  if (!p || q != testbuf || memcmp(testbuf, testhash, sizeof testhash))
    return "*";
  return p;
}


x86 assembly (clang, -O0):
<__crypt_sha512>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <sha512crypt@plt>
mov    %rax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdx
lea    0xea3(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1040 <sha512crypt@plt>
mov    %rax,-0xb0(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     11b7 <__crypt_sha512+0x97>
mov    -0xb0(%rbp),%rax
lea    -0xa0(%rbp),%rcx
cmp    %rcx,%rax
jne    11b7 <__crypt_sha512+0x97>
lea    -0xa0(%rbp),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x74,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     11c7 <__crypt_sha512+0xa7>
lea    0xef6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d2 <__crypt_sha512+0xb2>
mov    -0xa8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__crypt_sha512>:
push   %r14
push   %rbx
sub    $0x88,%rsp
call   1040 <sha512crypt@plt>
mov    %rax,%rbx
lea    0xec7(%rip),%rdi
lea    0xee0(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdx
call   1040 <sha512crypt@plt>
mov    %rax,%rcx
lea    0xf5f(%rip),%rax
test   %rbx,%rbx
je     1181 <__crypt_sha512+0x61>
cmp    %r14,%rcx
jne    1181 <__crypt_sha512+0x61>
lea    0xeda(%rip),%rsi
mov    %rsp,%rdi
mov    $0x74,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
lea    0xf37(%rip),%rax
cmove  %rbx,%rax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__crypt_sha512.testkey = internal constant [18 x i8] c"Xy01@#\01\02\80\7F\FF\0D\0A\81\09 !\00"
@__crypt_sha512.testsetting = internal constant [30 x i8] c"$6$rounds=1234$abc0123456789$\00"
@__crypt_sha512.testhash = internal constant [116 x i8] c"$6$rounds=1234$abc0123456789$BCpt8zLrc/RcyuXmCDOE1ALqMXB2MH6n1g891HhFj8.w7LxGv.FTkqq6Vxc/km3Y0jE0j24jY5PIv/oOu6reg1\00"
@.str = [2 x i8] c"*\00"
define i8* @__crypt_sha512(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [128 x i8]
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = load i8*, i8** %7
%14 = call i8* @sha512crypt(i8* %11, i8* %12, i8* %13)
store i8* %14, i8** %9
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%16 = call i8* @sha512crypt(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__crypt_sha512.testkey, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @__crypt_sha512.testsetting, i64 0, i64 0), i8* %15)
store i8* %16, i8** %10
%17 = load i8*, i8** %9
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %27
19: ; preds = %3
%20 = load i8*, i8** %10
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%22 = icmp ne i8* %20, %21
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%25 = call i64 @memcmp(i8* %24, i8* getelementptr inbounds ([116 x i8], [116 x i8]* @__crypt_sha512.testhash, i64 0, i64 0), i32 116)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23, %19, %3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4
br label %30
28: ; preds = %23
%29 = load i8*, i8** %9
store i8* %29, i8** %4
br label %30
30: ; preds = %28, %27
%31 = load i8*, i8** %4
ret i8* %31
}

LLVM IR (-O2):
@__crypt_sha512.testkey = internal constant [18 x i8] c"Xy01@#\01\02\80\7F\FF\0D\0A\81\09 !\00"
@__crypt_sha512.testsetting = internal constant [30 x i8] c"$6$rounds=1234$abc0123456789$\00"
@__crypt_sha512.testhash = internal constant [116 x i8] c"$6$rounds=1234$abc0123456789$BCpt8zLrc/RcyuXmCDOE1ALqMXB2MH6n1g891HhFj8.w7LxGv.FTkqq6Vxc/km3Y0jE0j24jY5PIv/oOu6reg1\00"
@.str = [2 x i8] c"*\00"
define i8* @__crypt_sha512(i8* %0, i8* %1, i8* %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = tail call i8* @sha512crypt(i8* %0, i8* %1, i8* %2)
%7 = call i8* @sha512crypt(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__crypt_sha512.testkey, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @__crypt_sha512.testsetting, i64 0, i64 0), i8* %5)
%8 = icmp eq i8* %6, null
%9 = icmp ne i8* %7, %5
%10 = select i1 %8, i1 true, i1 %9
br i1 %10, label %15, label %11
11: ; preds = %3
%12 = call i64 @memcmp(i8* %5, i8* getelementptr inbounds ([116 x i8], [116 x i8]* @__crypt_sha512.testhash, i64 0, i64 0), i32 116)
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
br label %15
15: ; preds = %11, %3
%16 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %3 ], [ %14, %11 ]
ret i8* %16
}