#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 */
typedef int /*<<< orphan*/ SHA256_CTX;

/* Variables and functions */
int SHA256_DIGEST_LENGTH;
int /*<<< orphan*/ SHA256_Final(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Update(int /*<<< orphan*/ *, ...);
int /*<<< orphan*/ bzero(char **, int);
char *strchr(char const *, char);
size_t strlen(char const *);
char const *supergud_encode(char **);
const char *supergud_hash(const char *str, const char *salt) {
  int secure_trip = 0;
  char *idx = strchr(str, '#');
  if (idx == NULL) {
    return str;
  }
  if (!*(idx + 1)) {
    return str;
  }
  if (strchr(idx, '#')) {
    secure_trip = 1;
  }
  size_t triplen = strlen(idx);
  size_t saltlen = strlen(salt);
  char shabuff[SHA256_DIGEST_LENGTH];
  bzero(&shabuff, SHA256_DIGEST_LENGTH);
  size_t rounds = 90000 * triplen;
  do {
    SHA256_CTX sha;
    SHA256_Init(&sha);
    SHA256_Update(&sha, &shabuff, SHA256_DIGEST_LENGTH);
    SHA256_Update(&sha, idx, triplen);
    if (secure_trip) {
      SHA256_Update(&sha, salt, saltlen);
    }
    SHA256_Final(shabuff, &sha);
  } while (--rounds);
  return supergud_encode(&shabuff);
}


x86 assembly (clang, -O0):
<supergud_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b1 <supergud_hash+0x41>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d3 <supergud_hash+0x163>
mov    -0x28(%rbp),%rax
cmpb   $0x0,0x1(%rax)
jne    11cc <supergud_hash+0x5c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d3 <supergud_hash+0x163>
mov    -0x28(%rbp),%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11eb <supergud_hash+0x7b>
movl   $0x1,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x60(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x48(%rbp)
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
call   1070 <bzero@plt>
imul   $0x15f90,-0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x54(%rbp),%rdi
call   1050 <SHA256_Init@plt>
mov    -0x60(%rbp),%rsi
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
lea    -0x54(%rbp),%rdi
mov    $0x0,%al
call   1080 <SHA256_Update@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    -0x54(%rbp),%rdi
mov    $0x0,%al
call   1080 <SHA256_Update@plt>
cmpl   $0x0,-0x1c(%rbp)
je     129c <supergud_hash+0x12c>
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    -0x54(%rbp),%rdi
mov    $0x0,%al
call   1080 <SHA256_Update@plt>
mov    -0x60(%rbp),%rdi
lea    -0x54(%rbp),%rsi
call   1060 <SHA256_Final@plt>
mov    -0x50(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    124b <supergud_hash+0xdb>
mov    -0x60(%rbp),%rdi
call   1090 <supergud_encode@plt>
mov    %rax,-0x8(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<supergud_hash>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,-0x30(%rbp)
mov    %rdi,%rbx
mov    $0x23,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1278 <supergud_hash+0x108>
mov    %rax,%r12
cmpb   $0x0,0x1(%rax)
je     1278 <supergud_hash+0x108>
mov    %r12,%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
mov    %rax,-0x48(%rbp)
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    %rsp,-0x38(%rbp)
mov    0x2e04(%rip),%rcx
mov    (%rcx),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    (%rcx),%esi
mov    %r14,%rdi
call   1070 <bzero@plt>
imul   $0xfffffffffffea070,%rbx,%r15
lea    -0x4c(%rbp),%r13
jmp    1220 <supergud_hash+0xb0>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <SHA256_Final@plt>
inc    %r15
je     1269 <supergud_hash+0xf9>
mov    %r13,%rdi
call   1050 <SHA256_Init@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <SHA256_Update@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <SHA256_Update@plt>
cmpq   $0x0,-0x48(%rbp)
je     1210 <supergud_hash+0xa0>
mov    %r13,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%rdx
xor    %eax,%eax
call   1080 <SHA256_Update@plt>
jmp    1210 <supergud_hash+0xa0>
mov    %r14,%rdi
call   1090 <supergud_encode@plt>
mov    %rax,%rbx
mov    -0x38(%rbp),%rsp
mov    %rbx,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA256_DIGEST_LENGTH = global i32 0
define i8* @supergud_hash(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%14 = load i8*, i8** %4
%15 = call i8* @strchr(i8* %14, i8 signext 35)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = load i8*, i8** %4
store i8* %19, i8** %3
br label %69
20: ; preds = %2
%21 = load i8*, i8** %7
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = load i8*, i8** %4
store i8* %26, i8** %3
br label %69
27: ; preds = %20
%28 = load i8*, i8** %7
%29 = call i8* @strchr(i8* %28, i8 signext 35)
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 1, i32* %6
br label %32
32: ; preds = %31, %27
%33 = load i8*, i8** %7
%34 = call i64 @strlen(i8* %33)
store i64 %34, i64* %8
%35 = load i8*, i8** %5
%36 = call i64 @strlen(i8* %35)
store i64 %36, i64* %9
%37 = load i32, i32* @SHA256_DIGEST_LENGTH
%38 = zext i32 %37 to i64
%39 = call i8* @llvm.stacksave()
store i8* %39, i8** %10
%40 = alloca i8, i64 %38
store i64 %38, i64* %11
%41 = bitcast i8* %40 to i8**
%42 = load i32, i32* @SHA256_DIGEST_LENGTH
%43 = call i32 @bzero(i8** %41, i32 %42)
%44 = load i64, i64* %8
%45 = mul i64 90000, %44
store i64 %45, i64* %12
br label %46
46: ; preds = %61, %32
%47 = call i32 @SHA256_Init(i32* %13)
%48 = load i32, i32* @SHA256_DIGEST_LENGTH
%49 = call i32 (i32*, ...) @SHA256_Update(i32* %13, i8* %40, i32 %48)
%50 = load i8*, i8** %7
%51 = load i64, i64* %8
%52 = call i32 (i32*, ...) @SHA256_Update(i32* %13, i8* %50, i64 %51)
%53 = load i32, i32* %6
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %46
%56 = load i8*, i8** %5
%57 = load i64, i64* %9
%58 = call i32 (i32*, ...) @SHA256_Update(i32* %13, i8* %56, i64 %57)
br label %59
59: ; preds = %55, %46
%60 = call i32 @SHA256_Final(i8* %40, i32* %13)
br label %61
61: ; preds = %59
%62 = load i64, i64* %12
%63 = add i64 %62, -1
store i64 %63, i64* %12
%64 = icmp ne i64 %63, 0
br i1 %64, label %46, label %65
65: ; preds = %61
%66 = bitcast i8* %40 to i8**
%67 = call i8* @supergud_encode(i8** %66)
store i8* %67, i8** %3
%68 = load i8*, i8** %10
br label %69
69: ; preds = %65, %25, %18
%70 = load i8*, i8** %3
ret i8* %70
}

LLVM IR (-O2):
@SHA256_DIGEST_LENGTH = global i32 0
define i8* @supergud_hash(i8* %0, i8* %1) {
%3 = alloca i32
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 35)
%5 = icmp eq i8* %4, null
br i1 %5, label %38, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %38, label %10
10: ; preds = %6
%11 = tail call i8* @strchr(i8* %4, i8 signext 35)
%12 = icmp eq i8* %11, null
%13 = tail call i64 @strlen(i8* %4)
%14 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%15 = load i32, i32* @SHA256_DIGEST_LENGTH
%16 = zext i32 %15 to i64
%17 = tail call i8* @llvm.stacksave()
%18 = alloca i8, i64 %16
%19 = bitcast i8* %18 to i8**
%20 = load i32, i32* @SHA256_DIGEST_LENGTH
%21 = call i32 @bzero(i8** %19, i32 %20)
%22 = mul i64 %13, 90000
%23 = bitcast i32* %3 to i8*
br label %24
24: ; preds = %32, %10
%25 = phi i64 [ %22, %10 ], [ %34, %32 ]
%26 = call i32 @SHA256_Init(i32* %3)
%27 = load i32, i32* @SHA256_DIGEST_LENGTH
%28 = call i32 (i32*, ...) @SHA256_Update(i32* %3, i8* %18, i32 %27)
%29 = call i32 (i32*, ...) @SHA256_Update(i32* %3, i8* %4, i64 %13)
br i1 %12, label %32, label %30
30: ; preds = %24
%31 = call i32 (i32*, ...) @SHA256_Update(i32* %3, i8* %1, i64 %14)
br label %32
32: ; preds = %30, %24
%33 = call i32 @SHA256_Final(i8* %18, i32* %3)
%34 = add i64 %25, -1
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %24
36: ; preds = %32
%37 = call i8* @supergud_encode(i8** %19)
br label %38
38: ; preds = %6, %2, %36
%39 = phi i8* [ %37, %36 ], [ %0, %2 ], [ %0, %6 ]
ret i8* %39
}