#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*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ SHA256(unsigned char *, int, unsigned char *);
int /*<<< orphan*/ addr_to_bytes(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ mgf1(unsigned char *, unsigned int, unsigned char *, int);
void thash(unsigned char *out, const unsigned char *in, unsigned int inblocks,
           const unsigned char *pub_seed, uint32_t addr[8]) {
  unsigned char buf[16 + 32 + inblocks * 16];
  unsigned char outbuf[32];
  unsigned char bitmask[inblocks * 16];
  unsigned int i;
  memcpy(buf, pub_seed, 16);
  addr_to_bytes(buf + 16, addr);
  mgf1(bitmask, inblocks * 16, buf, 16 + 32);
  for (i = 0; i < inblocks * 16; i++) {
    buf[16 + 32 + i] = in[i] ^ bitmask[i];
  }
  SHA256(buf, 16 + 32 + inblocks * 16, outbuf);
  memcpy(out, outbuf, 16);
}


x86 assembly (clang, -O0):
<thash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x14(%rbp),%edx
shl    $0x4,%edx
mov    %edx,%eax
add    $0x30,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
add    $0x3f,%edx
mov    %edx,%ecx
and    $0xfffffff0,%ecx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x78(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x78(%rbp),%rdi
add    $0x10,%rdi
mov    -0x28(%rbp),%rsi
call   1040 <addr_to_bytes@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    -0x14(%rbp),%esi
shl    $0x4,%esi
mov    $0x30,%ecx
call   1060 <mgf1@plt>
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x4,%ecx
cmp    %ecx,%eax
jae    1226 <thash+0xe6>
mov    -0x78(%rbp),%rax
mov    -0x80(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x6c(%rbp),%esi
movzbl (%rcx,%rsi,1),%ecx
mov    -0x6c(%rbp),%esi
movzbl (%rdx,%rsi,1),%edx
xor    %edx,%ecx
mov    %cl,%dl
mov    -0x6c(%rbp),%ecx
add    $0x30,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11de <thash+0x9e>
mov    -0x78(%rbp),%rdi
mov    -0x14(%rbp),%esi
shl    $0x4,%esi
add    $0x30,%esi
lea    -0x60(%rbp),%rdx
call   1030 <SHA256@plt>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thash>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,-0x40(%rbp)
mov    %edx,%r15d
mov    %rsi,%r13
mov    %rdi,-0x48(%rbp)
shl    $0x4,%r15d
lea    0x30(%r15),%eax
mov    %eax,-0x2c(%rbp)
lea    0x3f(%r15),%r12d
and    $0xfffffff0,%r12d
mov    %rsp,%rbx
mov    %rbx,-0x38(%rbp)
sub    %r12,%rbx
mov    %rbx,%rsp
mov    %rsp,%r14
sub    %r15,%r14
mov    %r14,%rsp
mov    %rbx,%rdi
mov    %rcx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
neg    %r12
mov    -0x38(%rbp),%rax
lea    (%rax,%r12,1),%rdi
add    $0x10,%rdi
mov    -0x40(%rbp),%rsi
call   1040 <addr_to_bytes@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    $0x30,%ecx
call   1060 <mgf1@plt>
test   %r15d,%r15d
je     1336 <thash+0x1f6>
lea    -0x1(%r15),%rcx
xor    %eax,%eax
cmp    $0xffffffcf,%ecx
ja     12f1 <thash+0x1b1>
shr    $0x20,%rcx
jne    12f1 <thash+0x1b1>
cmp    $0x20,%r15d
jae    122a <thash+0xea>
xor    %eax,%eax
add    $0x30,%rax
neg    %r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    -0x30(%r14,%rax,1),%rcx
xor    -0x30(%r13,%rax,1),%rcx
mov    %eax,%edx
and    $0xfffffff8,%edx
mov    %rcx,(%rbx,%rdx,1)
lea    (%r15,%rax,1),%rcx
add    $0x8,%rcx
add    $0x8,%rax
cmp    $0x30,%rcx
jne    1200 <thash+0xc0>
jmp    1336 <thash+0x1f6>
mov    %r15d,%eax
and    $0xffffffe0,%eax
lea    -0x20(%rax),%rcx
mov    %rcx,%rdx
shr    $0x5,%rdx
add    $0x1,%rdx
test   %rcx,%rcx
je     1368 <thash+0x228>
mov    %rdx,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movups 0x0(%r13,%rcx,1),%xmm0
movups 0x10(%r13,%rcx,1),%xmm1
xorps  (%r14,%rcx,1),%xmm0
xorps  0x10(%r14,%rcx,1),%xmm1
mov    %ecx,%edi
and    $0xffffffc0,%edi
movaps %xmm0,0x30(%rbx,%rdi,1)
movaps %xmm1,0x40(%rbx,%rdi,1)
movups 0x20(%r13,%rcx,1),%xmm0
movups 0x30(%r13,%rcx,1),%xmm1
xorps  0x20(%r14,%rcx,1),%xmm0
xorps  0x30(%r14,%rcx,1),%xmm1
lea    0x50(%rcx),%edi
and    $0xffffffd0,%edi
movaps %xmm0,(%rbx,%rdi,1)
movaps %xmm1,0x10(%rbx,%rdi,1)
add    $0x40,%rcx
add    $0xfffffffffffffffe,%rsi
jne    1260 <thash+0x120>
test   $0x1,%dl
je     12e2 <thash+0x1a2>
movups 0x0(%r13,%rcx,1),%xmm0
movups 0x10(%r13,%rcx,1),%xmm1
xorps  (%r14,%rcx,1),%xmm0
xorps  0x10(%r14,%rcx,1),%xmm1
add    $0x30,%ecx
and    $0xfffffff0,%ecx
movaps %xmm0,(%rbx,%rcx,1)
movaps %xmm1,0x10(%rbx,%rcx,1)
cmp    %r15,%rax
je     1336 <thash+0x1f6>
test   $0x10,%r15b
jne    11ed <thash+0xad>
add    $0x30,%rax
neg    %r15
nopl   0x0(%rax,%rax,1)
movzbl -0x30(%r14,%rax,1),%ecx
xor    -0x30(%r13,%rax,1),%cl
mov    %eax,%edx
and    $0xfffffffe,%edx
mov    %cl,(%rbx,%rdx,1)
movzbl -0x2f(%r14,%rax,1),%ecx
xor    -0x2f(%r13,%rax,1),%cl
lea    0x1(%rax),%edx
mov    %cl,(%rbx,%rdx,1)
lea    (%r15,%rax,1),%rcx
add    $0x2,%rcx
add    $0x2,%rax
cmp    $0x30,%rcx
jne    1300 <thash+0x1c0>
lea    -0x70(%rbp),%r14
mov    %rbx,%rdi
mov    -0x2c(%rbp),%esi
mov    %r14,%rdx
call   1030 <SHA256@plt>
mov    -0x48(%rbp),%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ecx,%ecx
test   $0x1,%dl
jne    12bc <thash+0x17c>
jmp    12e2 <thash+0x1a2>

LLVM IR (-O0):
define void @thash(i8* %0, i8* %1, i32 %2, i8* %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca [32 x i8]
%14 = alloca i64
%15 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32* %4, i32** %10
%16 = load i32, i32* %8
%17 = mul i32 %16, 16
%18 = add i32 48, %17
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %11
%21 = alloca i8, i64 %19
store i64 %19, i64* %12
%22 = load i32, i32* %8
%23 = mul i32 %22, 16
%24 = zext i32 %23 to i64
%25 = alloca i8, i64 %24
store i64 %24, i64* %14
%26 = load i8*, i8** %9
%27 = call i32 @memcpy(i8* %21, i8* %26, i32 16)
%28 = getelementptr inbounds i8, i8* %21, i64 16
%29 = load i32*, i32** %10
%30 = call i32 @addr_to_bytes(i8* %28, i32* %29)
%31 = load i32, i32* %8
%32 = mul i32 %31, 16
%33 = call i32 @mgf1(i8* %25, i32 %32, i8* %21, i32 48)
store i32 0, i32* %15
br label %34
34: ; preds = %57, %5
%35 = load i32, i32* %15
%36 = load i32, i32* %8
%37 = mul i32 %36, 16
%38 = icmp ult i32 %35, %37
br i1 %38, label %39, label %60
39: ; preds = %34
%40 = load i8*, i8** %7
%41 = load i32, i32* %15
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = load i32, i32* %15
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %25, i64 %47
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = xor i32 %45, %50
%52 = trunc i32 %51 to i8
%53 = load i32, i32* %15
%54 = add i32 48, %53
%55 = zext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %21, i64 %55
store i8 %52, i8* %56
br label %57
57: ; preds = %39
%58 = load i32, i32* %15
%59 = add i32 %58, 1
store i32 %59, i32* %15
br label %34
60: ; preds = %34
%61 = load i32, i32* %8
%62 = mul i32 %61, 16
%63 = add i32 48, %62
%64 = getelementptr inbounds [32 x i8], [32 x i8]* %13, i64 0, i64 0
%65 = call i32 @SHA256(i8* %21, i32 %63, i8* %64)
%66 = load i8*, i8** %6
%67 = getelementptr inbounds [32 x i8], [32 x i8]* %13, i64 0, i64 0
%68 = call i32 @memcpy(i8* %66, i8* %67, i32 16)
%69 = load i8*, i8** %11
ret void
}

LLVM IR (-O2):
define void @thash(i8* %0, i8* nocapture %1, i32 %2, i8* %3, i32* %4) {
%6 = alloca [32 x i8]
%7 = shl i32 %2, 4
%8 = add i32 %7, 48
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%12 = zext i32 %7 to i64
%13 = alloca i8, i64 %12
%14 = call i32 @memcpy(i8* %10, i8* %3, i32 16)
%15 = getelementptr inbounds i8, i8* %10, i64 16
%16 = call i32 @addr_to_bytes(i8* %15, i32* %4)
%17 = call i32 @mgf1(i8* %13, i32 %7, i8* %10, i32 48)
%18 = icmp eq i32 %7, 0
br i1 %18, label %152, label %19
19: ; preds = %5
%20 = add nsw i64 %12, -1
%21 = trunc i64 %20 to i32
%22 = icmp ugt i32 %21, -49
%23 = icmp ugt i64 %20, 4294967295
%24 = or i1 %22, %23
br i1 %24, label %114, label %25
25: ; preds = %19
%26 = icmp ult i32 %7, 32
br i1 %26, label %112, label %27
27: ; preds = %25
%28 = and i64 %12, 4294967264
%29 = add nsw i64 %28, -32
%30 = lshr exact i64 %29, 5
%31 = add nuw nsw i64 %30, 1
%32 = and i64 %31, 1
%33 = icmp eq i64 %29, 0
br i1 %33, label %83, label %34
34: ; preds = %27
%35 = and i64 %31, 1152921504606846974
br label %36
36: ; preds = %36, %34
%37 = phi i64 [ 0, %34 ], [ %80, %36 ]
%38 = phi i64 [ 0, %34 ], [ %81, %36 ]
%39 = getelementptr inbounds i8, i8* %1, i64 %37
%40 = bitcast i8* %39 to <16 x i8>*
%41 = load <16 x i8>, <16 x i8>* %40
%42 = getelementptr inbounds i8, i8* %39, i64 16
%43 = bitcast i8* %42 to <16 x i8>*
%44 = load <16 x i8>, <16 x i8>* %43
%45 = getelementptr inbounds i8, i8* %13, i64 %37
%46 = bitcast i8* %45 to <16 x i8>*
%47 = load <16 x i8>, <16 x i8>* %46
%48 = getelementptr inbounds i8, i8* %45, i64 16
%49 = bitcast i8* %48 to <16 x i8>*
%50 = load <16 x i8>, <16 x i8>* %49
%51 = xor <16 x i8> %47, %41
%52 = xor <16 x i8> %50, %44
%53 = and i64 %37, 4294967232
%54 = or i64 %53, 48
%55 = getelementptr inbounds i8, i8* %10, i64 %54
%56 = bitcast i8* %55 to <16 x i8>*
store <16 x i8> %51, <16 x i8>* %56
%57 = getelementptr inbounds i8, i8* %55, i64 16
%58 = bitcast i8* %57 to <16 x i8>*
store <16 x i8> %52, <16 x i8>* %58
%59 = or i64 %37, 32
%60 = getelementptr inbounds i8, i8* %1, i64 %59
%61 = bitcast i8* %60 to <16 x i8>*
%62 = load <16 x i8>, <16 x i8>* %61
%63 = getelementptr inbounds i8, i8* %60, i64 16
%64 = bitcast i8* %63 to <16 x i8>*
%65 = load <16 x i8>, <16 x i8>* %64
%66 = getelementptr inbounds i8, i8* %13, i64 %59
%67 = bitcast i8* %66 to <16 x i8>*
%68 = load <16 x i8>, <16 x i8>* %67
%69 = getelementptr inbounds i8, i8* %66, i64 16
%70 = bitcast i8* %69 to <16 x i8>*
%71 = load <16 x i8>, <16 x i8>* %70
%72 = xor <16 x i8> %68, %62
%73 = xor <16 x i8> %71, %65
%74 = add nuw i64 %37, 80
%75 = and i64 %74, 4294967248
%76 = getelementptr inbounds i8, i8* %10, i64 %75
%77 = bitcast i8* %76 to <16 x i8>*
store <16 x i8> %72, <16 x i8>* %77
%78 = getelementptr inbounds i8, i8* %76, i64 16
%79 = bitcast i8* %78 to <16 x i8>*
store <16 x i8> %73, <16 x i8>* %79
%80 = add nuw i64 %37, 64
%81 = add i64 %38, 2
%82 = icmp eq i64 %81, %35
br i1 %82, label %83, label %36
83: ; preds = %36, %27
%84 = phi i64 [ 0, %27 ], [ %80, %36 ]
%85 = icmp eq i64 %32, 0
br i1 %85, label %107, label %86
86: ; preds = %83
%87 = getelementptr inbounds i8, i8* %1, i64 %84
%88 = bitcast i8* %87 to <16 x i8>*
%89 = load <16 x i8>, <16 x i8>* %88
%90 = getelementptr inbounds i8, i8* %87, i64 16
%91 = bitcast i8* %90 to <16 x i8>*
%92 = load <16 x i8>, <16 x i8>* %91
%93 = getelementptr inbounds i8, i8* %13, i64 %84
%94 = bitcast i8* %93 to <16 x i8>*
%95 = load <16 x i8>, <16 x i8>* %94
%96 = getelementptr inbounds i8, i8* %93, i64 16
%97 = bitcast i8* %96 to <16 x i8>*
%98 = load <16 x i8>, <16 x i8>* %97
%99 = xor <16 x i8> %95, %89
%100 = xor <16 x i8> %98, %92
%101 = add nuw i64 %84, 48
%102 = and i64 %101, 4294967280
%103 = getelementptr inbounds i8, i8* %10, i64 %102
%104 = bitcast i8* %103 to <16 x i8>*
store <16 x i8> %99, <16 x i8>* %104
%105 = getelementptr inbounds i8, i8* %103, i64 16
%106 = bitcast i8* %105 to <16 x i8>*
store <16 x i8> %100, <16 x i8>* %106
br label %107
107: ; preds = %83, %86
%108 = icmp eq i64 %28, %12
br i1 %108, label %152, label %109
109: ; preds = %107
%110 = and i64 %12, 16
%111 = icmp eq i64 %110, 0
br i1 %111, label %114, label %112
112: ; preds = %25, %109
%113 = phi i64 [ 0, %25 ], [ %28, %109 ]
br label %116
114: ; preds = %19, %109
%115 = phi i64 [ 0, %19 ], [ %28, %109 ]
br label %131
116: ; preds = %112, %116
%117 = phi i64 [ %129, %116 ], [ %113, %112 ]
%118 = getelementptr inbounds i8, i8* %1, i64 %117
%119 = bitcast i8* %118 to <8 x i8>*
%120 = load <8 x i8>, <8 x i8>* %119
%121 = getelementptr inbounds i8, i8* %13, i64 %117
%122 = bitcast i8* %121 to <8 x i8>*
%123 = load <8 x i8>, <8 x i8>* %122
%124 = xor <8 x i8> %123, %120
%125 = add nuw i64 %117, 48
%126 = and i64 %125, 4294967288
%127 = getelementptr inbounds i8, i8* %10, i64 %126
%128 = bitcast i8* %127 to <8 x i8>*
store <8 x i8> %124, <8 x i8>* %128
%129 = add nuw i64 %117, 8
%130 = icmp eq i64 %129, %12
br i1 %130, label %152, label %116
131: ; preds = %131, %114
%132 = phi i64 [ %115, %114 ], [ %150, %131 ]
%133 = getelementptr inbounds i8, i8* %1, i64 %132
%134 = load i8, i8* %133
%135 = getelementptr inbounds i8, i8* %13, i64 %132
%136 = load i8, i8* %135
%137 = xor i8 %136, %134
%138 = add nuw i64 %132, 48
%139 = and i64 %138, 4294967294
%140 = getelementptr inbounds i8, i8* %10, i64 %139
store i8 %137, i8* %140
%141 = or i64 %132, 1
%142 = getelementptr inbounds i8, i8* %1, i64 %141
%143 = load i8, i8* %142
%144 = getelementptr inbounds i8, i8* %13, i64 %141
%145 = load i8, i8* %144
%146 = xor i8 %145, %143
%147 = add nuw i64 %132, 49
%148 = and i64 %147, 4294967295
%149 = getelementptr inbounds i8, i8* %10, i64 %148
store i8 %146, i8* %149
%150 = add nuw nsw i64 %132, 2
%151 = icmp eq i64 %150, %12
br i1 %151, label %152, label %131
152: ; preds = %116, %131, %107, %5
%153 = call i32 @SHA256(i8* %10, i32 %8, i8* %11)
%154 = call i32 @memcpy(i8* %0, i8* %11, i32 16)
ret void
}