#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*/ AES128_encrypt(unsigned char *, unsigned char *,
                                  unsigned char *);
int /*<<< orphan*/ exclusive(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ hashExpansion(unsigned char *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ phex(unsigned char *, int);
void hash(unsigned long len, unsigned char *input, unsigned char *key) {
  unsigned long i, numb, numc, temp;
  numb = len / 16;
  numc = len % 16;
  unsigned char output[20];
  memset(output, 0, 20 * sizeof(unsigned char));
  if (numc == 0) {
    AES128_encrypt(input, key, output);
    exclusive(output, input, 16);
    for (i = 1; i < numb; ++i) {
      AES128_encrypt(input + 16 * i, output, output);
      exclusive(output, input + 16 * i, 16);
    }
  } else {
    temp = 16 - numc;
    for (i = 16; i > numc; --i) {
      input[16 * numb + i - 1] = temp;
    }
    numb++;
    AES128_encrypt(input, key, output);
    exclusive(output, input, 16);
    for (i = 1; i < numb; ++i) {
      AES128_encrypt(input + 16 * i, output, output);
      exclusive(output, input + 16 * i, 16);
    }
  }
  hashExpansion(output);
  phex(output, 20);
  return;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
and    $0xf,%rax
mov    %rax,-0x30(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
cmpq   $0x0,-0x30(%rbp)
jne    121f <hash+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1030 <AES128_encrypt@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1070 <exclusive@plt>
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    121a <hash+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x4,%rax
add    %rax,%rdi
lea    -0x50(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1030 <AES128_encrypt@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
shl    $0x4,%rax
add    %rax,%rsi
mov    $0x10,%edx
call   1070 <exclusive@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11c2 <hash+0x72>
jmp    1304 <hash+0x1b4>
mov    $0x10,%eax
sub    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x10,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jbe    1270 <hash+0x120>
mov    -0x38(%rbp),%rax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x4,%rcx
add    -0x20(%rbp),%rcx
sub    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1234 <hash+0xe4>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1030 <AES128_encrypt@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1070 <exclusive@plt>
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    12ff <hash+0x1af>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x4,%rax
add    %rax,%rdi
lea    -0x50(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1030 <AES128_encrypt@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
shl    $0x4,%rax
add    %rax,%rsi
mov    $0x10,%edx
call   1070 <exclusive@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12a7 <hash+0x157>
jmp    1304 <hash+0x1b4>
lea    -0x50(%rbp),%rdi
call   1060 <hashExpansion@plt>
lea    -0x50(%rbp),%rdi
mov    $0x14,%esi
call   1050 <phex@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %rdi,%r13
shr    $0x4,%r13
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    %r14,%rax
and    $0xf,%rax
je     121a <hash+0xca>
mov    $0x10,%cl
sub    %al,%cl
lea    (%r14,%rbp,1),%rdi
mov    $0x10,%edx
sub    %rax,%rdx
movzbl %cl,%esi
call   1040 <memset@plt>
mov    %rsp,%r12
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <AES128_encrypt@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1070 <exclusive@plt>
cmp    $0x10,%r14
jb     1288 <hash+0x138>
cmp    $0x2,%r13
mov    $0x1,%ebx
cmovae %r13,%rbx
add    $0x10,%rbp
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r14,%rdx
call   1030 <AES128_encrypt@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1070 <exclusive@plt>
add    $0x10,%rbp
add    $0xffffffffffffffff,%rbx
jne    11f0 <hash+0xa0>
jmp    1288 <hash+0x138>
mov    %rsp,%r12
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <AES128_encrypt@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1070 <exclusive@plt>
cmp    $0x20,%r14
jb     1288 <hash+0x138>
cmp    $0x3,%r13
mov    $0x2,%r15d
cmovae %r13,%r15
add    $0xffffffffffffffff,%r15
add    $0x10,%rbp
mov    %rsp,%r14
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r14,%rdx
call   1030 <AES128_encrypt@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1070 <exclusive@plt>
add    $0x10,%rbp
add    $0xffffffffffffffff,%r15
jne    1260 <hash+0x110>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <hashExpansion@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
call   1050 <phex@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @hash(i64 %0, i8* %1, i8* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca [20 x i8]
store i64 %0, i64* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = load i64, i64* %4
%13 = udiv i64 %12, 16
store i64 %13, i64* %8
%14 = load i64, i64* %4
%15 = urem i64 %14, 16
store i64 %15, i64* %9
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%17 = call i32 @memset(i8* %16, i32 0, i32 20)
%18 = load i64, i64* %9
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %50
20: ; preds = %3
%21 = load i8*, i8** %5
%22 = load i8*, i8** %6
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%24 = call i32 @AES128_encrypt(i8* %21, i8* %22, i8* %23)
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = call i32 @exclusive(i8* %25, i8* %26, i32 16)
store i64 1, i64* %7
br label %28
28: ; preds = %46, %20
%29 = load i64, i64* %7
%30 = load i64, i64* %8
%31 = icmp ult i64 %29, %30
br i1 %31, label %32, label %49
32: ; preds = %28
%33 = load i8*, i8** %5
%34 = load i64, i64* %7
%35 = mul i64 16, %34
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%39 = call i32 @AES128_encrypt(i8* %36, i8* %37, i8* %38)
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%41 = load i8*, i8** %5
%42 = load i64, i64* %7
%43 = mul i64 16, %42
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = call i32 @exclusive(i8* %40, i8* %44, i32 16)
br label %46
46: ; preds = %32
%47 = load i64, i64* %7
%48 = add i64 %47, 1
store i64 %48, i64* %7
br label %28
49: ; preds = %28
br label %102
50: ; preds = %3
%51 = load i64, i64* %9
%52 = sub i64 16, %51
store i64 %52, i64* %10
store i64 16, i64* %7
br label %53
53: ; preds = %67, %50
%54 = load i64, i64* %7
%55 = load i64, i64* %9
%56 = icmp ugt i64 %54, %55
br i1 %56, label %57, label %70
57: ; preds = %53
%58 = load i64, i64* %10
%59 = trunc i64 %58 to i8
%60 = load i8*, i8** %5
%61 = load i64, i64* %8
%62 = mul i64 16, %61
%63 = load i64, i64* %7
%64 = add i64 %62, %63
%65 = sub i64 %64, 1
%66 = getelementptr inbounds i8, i8* %60, i64 %65
store i8 %59, i8* %66
br label %67
67: ; preds = %57
%68 = load i64, i64* %7
%69 = add i64 %68, -1
store i64 %69, i64* %7
br label %53
70: ; preds = %53
%71 = load i64, i64* %8
%72 = add i64 %71, 1
store i64 %72, i64* %8
%73 = load i8*, i8** %5
%74 = load i8*, i8** %6
%75 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%76 = call i32 @AES128_encrypt(i8* %73, i8* %74, i8* %75)
%77 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%78 = load i8*, i8** %5
%79 = call i32 @exclusive(i8* %77, i8* %78, i32 16)
store i64 1, i64* %7
br label %80
80: ; preds = %98, %70
%81 = load i64, i64* %7
%82 = load i64, i64* %8
%83 = icmp ult i64 %81, %82
br i1 %83, label %84, label %101
84: ; preds = %80
%85 = load i8*, i8** %5
%86 = load i64, i64* %7
%87 = mul i64 16, %86
%88 = getelementptr inbounds i8, i8* %85, i64 %87
%89 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%90 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%91 = call i32 @AES128_encrypt(i8* %88, i8* %89, i8* %90)
%92 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%93 = load i8*, i8** %5
%94 = load i64, i64* %7
%95 = mul i64 16, %94
%96 = getelementptr inbounds i8, i8* %93, i64 %95
%97 = call i32 @exclusive(i8* %92, i8* %96, i32 16)
br label %98
98: ; preds = %84
%99 = load i64, i64* %7
%100 = add i64 %99, 1
store i64 %100, i64* %7
br label %80
101: ; preds = %80
br label %102
102: ; preds = %101, %49
%103 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%104 = call i32 @hashExpansion(i8* %103)
%105 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%106 = call i32 @phex(i8* %105, i32 20)
ret void
}

LLVM IR (-O2):
define void @hash(i64 %0, i8* %1, i8* %2) {
%4 = alloca [20 x i8]
%5 = lshr i64 %0, 4
%6 = and i64 %0, 15
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 20)
%9 = icmp eq i64 %6, 0
br i1 %9, label %18, label %10
10: ; preds = %3
%11 = trunc i64 %6 to i8
%12 = sub nuw nsw i8 16, %11
%13 = getelementptr i8, i8* %1, i64 %0
%14 = sub nuw nsw i64 16, %6
%15 = call i32 @AES128_encrypt(i8* %1, i8* %2, i8* %7)
%16 = call i32 @exclusive(i8* %7, i8* %1, i32 16)
%17 = icmp ult i64 %0, 16
br i1 %17, label %42, label %32
18: ; preds = %3
%19 = call i32 @AES128_encrypt(i8* %1, i8* %2, i8* %7)
%20 = call i32 @exclusive(i8* %7, i8* %1, i32 16)
%21 = icmp ugt i64 %0, 31
br i1 %21, label %22, label %42
22: ; preds = %18
%23 = call i64 @llvm.umax.i64(i64 %5, i64 2)
br label %24
24: ; preds = %22, %24
%25 = phi i64 [ %30, %24 ], [ 1, %22 ]
%26 = shl i64 %25, 4
%27 = getelementptr inbounds i8, i8* %1, i64 %26
%28 = call i32 @AES128_encrypt(i8* %27, i8* %7, i8* %7)
%29 = call i32 @exclusive(i8* %7, i8* %27, i32 16)
%30 = add nuw nsw i64 %25, 1
%31 = icmp eq i64 %30, %23
br i1 %31, label %42, label %24
32: ; preds = %10
%33 = call i64 @llvm.umax.i64(i64 %5, i64 1)
br label %34
34: ; preds = %32, %34
%35 = phi i64 [ %40, %34 ], [ 1, %32 ]
%36 = shl i64 %35, 4
%37 = getelementptr inbounds i8, i8* %1, i64 %36
%38 = call i32 @AES128_encrypt(i8* %37, i8* %7, i8* %7)
%39 = call i32 @exclusive(i8* %7, i8* %37, i32 16)
%40 = add nuw nsw i64 %35, 1
%41 = icmp eq i64 %35, %33
br i1 %41, label %42, label %34
42: ; preds = %34, %24, %10, %18
%43 = call i32 @hashExpansion(i8* %7)
%44 = call i32 @phex(i8* %7, i32 20)
ret void
}