#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 */
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(unsigned int);
int /*<<< orphan*/ memcpy(unsigned char *, ...);
int mix_hashed_num(unsigned char *, unsigned char *, unsigned int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sha256(unsigned char *, ...);
void dcrypt_hash(const char *input, char *hash, unsigned int len) {
  unsigned char *instr = malloc(len);
  memcpy(instr, input, len);
  unsigned char *hashed = malloc(128);
  unsigned char *mixedHash = malloc(1048576 + 1024);
  unsigned char *finalToHash;
  unsigned int lenMixedHash = 0;
  sha256(instr, hashed, len);
  if (mix_hashed_num(hashed, mixedHash, &lenMixedHash) == 1) {
    finalToHash = malloc(lenMixedHash + len + 64);
    memcpy(finalToHash, mixedHash, lenMixedHash);
    memcpy(&(finalToHash[lenMixedHash]), instr, len);
    sha256(finalToHash, hash, len + lenMixedHash);
    free(finalToHash);
  } else {
    printf("Buffer limit exceeded.\n");
  }
  free(mixedHash);
}


x86 assembly (clang, -O0):
<dcrypt_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x100400,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1050 <sha256@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   1060 <mix_hashed_num@plt>
cmp    $0x1,%eax
jne    123f <dcrypt_hash+0xdf>
mov    -0x3c(%rbp),%edi
add    -0x14(%rbp),%edi
add    $0x40,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x3c(%rbp),%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%eax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    -0x3c(%rbp),%edx
mov    $0x0,%al
call   1050 <sha256@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    124b <dcrypt_hash+0xeb>
lea    0xdba(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dcrypt_hash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    $0x100400,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
movl   $0x0,0x4(%rsp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <sha256@plt>
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <mix_hashed_num@plt>
cmp    $0x1,%eax
jne    1223 <dcrypt_hash+0xc3>
mov    0x4(%rsp),%ebx
lea    (%rbx,%rbp,1),%edi
add    $0x40,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
mov    0x4(%rsp),%edi
add    %r13,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
add    0x4(%rsp),%ebp
mov    %r13,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <sha256@plt>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    122f <dcrypt_hash+0xcf>
lea    0xdd6(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Buffer limit exceeded.\0A\00"
define void @dcrypt_hash(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i32, i32* %6
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = load i8*, i8** %4
%16 = load i32, i32* %6
%17 = call i32 (i8*, ...) @memcpy(i8* %14, i8* %15, i32 %16)
%18 = call i8* @malloc(i32 128)
store i8* %18, i8** %8
%19 = call i8* @malloc(i32 1049600)
store i8* %19, i8** %9
store i32 0, i32* %11
%20 = load i8*, i8** %7
%21 = load i8*, i8** %8
%22 = load i32, i32* %6
%23 = call i32 (i8*, ...) @sha256(i8* %20, i8* %21, i32 %22)
%24 = load i8*, i8** %8
%25 = load i8*, i8** %9
%26 = call i32 @mix_hashed_num(i8* %24, i8* %25, i32* %11)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %53
28: ; preds = %3
%29 = load i32, i32* %11
%30 = load i32, i32* %6
%31 = add i32 %29, %30
%32 = add i32 %31, 64
%33 = call i8* @malloc(i32 %32)
store i8* %33, i8** %10
%34 = load i8*, i8** %10
%35 = load i8*, i8** %9
%36 = load i32, i32* %11
%37 = call i32 (i8*, ...) @memcpy(i8* %34, i8* %35, i32 %36)
%38 = load i8*, i8** %10
%39 = load i32, i32* %11
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8*, i8** %7
%43 = load i32, i32* %6
%44 = call i32 (i8*, ...) @memcpy(i8* %41, i8* %42, i32 %43)
%45 = load i8*, i8** %10
%46 = load i8*, i8** %5
%47 = load i32, i32* %6
%48 = load i32, i32* %11
%49 = add i32 %47, %48
%50 = call i32 (i8*, ...) @sha256(i8* %45, i8* %46, i32 %49)
%51 = load i8*, i8** %10
%52 = call i32 @free(i8* %51)
br label %55
53: ; preds = %3
%54 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %55
55: ; preds = %53, %28
%56 = load i8*, i8** %9
%57 = call i32 @free(i8* %56)
ret void
}

LLVM IR (-O2):
@str = [23 x i8] c"Buffer limit exceeded.\00"
define void @dcrypt_hash(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = tail call i8* @malloc(i32 %2)
%6 = tail call i32 (i8*, ...) @memcpy(i8* %5, i8* %0, i32 %2)
%7 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%8 = tail call dereferenceable_or_null(1049600) i8* @malloc(i32 1049600)
%9 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%10 = tail call i32 (i8*, ...) @sha256(i8* %5, i8* %7, i32 %2)
%11 = call i32 @mix_hashed_num(i8* %7, i8* %8, i32* %4)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %27
13: ; preds = %3
%14 = load i32, i32* %4
%15 = add i32 %2, 64
%16 = add i32 %15, %14
%17 = call i8* @malloc(i32 %16)
%18 = call i32 (i8*, ...) @memcpy(i8* %17, i8* %8, i32 %14)
%19 = load i32, i32* %4
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = call i32 (i8*, ...) @memcpy(i8* %21, i8* %5, i32 %2)
%23 = load i32, i32* %4
%24 = add i32 %23, %2
%25 = call i32 (i8*, ...) @sha256(i8* %17, i8* %1, i32 %24)
%26 = call i32 @free(i8* %17)
br label %29
27: ; preds = %3
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %29
29: ; preds = %27, %13
%30 = call i32 @free(i8* %8)
ret void
}