#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*/ add_to_first(unsigned char *, unsigned char *);
int /*<<< orphan*/ aes_128_encrypt(unsigned char *, unsigned long *);
int /*<<< orphan*/ evaluate_by_delta(unsigned char *, unsigned char *,
                                     unsigned char *, unsigned long long);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ mul_by_delta(unsigned char *, unsigned char *);
void julius_regular_involution(unsigned char *pad, unsigned long long padlen,
                               unsigned long long reg_index,
                               unsigned long expanded_key[44]) {
  int i;
  unsigned long long cur;
  unsigned char seed[16];
  unsigned char mu[16];
  unsigned char tmp_mask[16];
  unsigned char delta[16];
  for (i = 0; i < 16; i++) {
    delta[i] = 0;
  }
  aes_128_encrypt(delta, expanded_key);
  evaluate_by_delta(seed, delta, pad, padlen / 16);
  memcpy(mu, seed, 16);
  aes_128_encrypt(mu, expanded_key);
  if (((padlen - reg_index) / 16) % 2 == 0) {
    cur = reg_index;
    memcpy(tmp_mask, mu, 16);
    for (cur = reg_index; cur < padlen; cur = cur + 16) {
      add_to_first(&pad[cur], tmp_mask);
      mul_by_delta(tmp_mask, delta);
    }
  } else {
    cur = reg_index;
    memcpy(tmp_mask, mu, 16);
    add_to_first(&pad[cur], tmp_mask);
    cur = cur + 16;
    if (cur < padlen) {
      mul_by_delta(tmp_mask, delta);
      add_to_first(&pad[cur], tmp_mask);
      add_to_first(&pad[cur], mu);
      cur = cur + 16;
    }
    for (; cur < padlen; cur = cur + 16) {
      add_to_first(&pad[cur], tmp_mask);
      mul_by_delta(tmp_mask, delta);
    }
  }
}


x86 assembly (clang, -O0):
<julius_regular_involution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jge    1190 <julius_regular_involution+0x40>
movslq -0x24(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116f <julius_regular_involution+0x1f>
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <aes_128_encrypt@plt>
lea    -0x40(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
shr    $0x4,%rcx
call   1050 <evaluate_by_delta@plt>
lea    -0x50(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <aes_128_encrypt@plt>
mov    -0x10(%rbp),%rax
sub    -0x18(%rbp),%rax
shr    $0x4,%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    1253 <julius_regular_involution+0x103>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    124e <julius_regular_involution+0xfe>
mov    -0x8(%rbp),%rdi
add    -0x30(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <add_to_first@plt>
lea    -0x60(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1070 <mul_by_delta@plt>
mov    -0x30(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x30(%rbp)
jmp    1211 <julius_regular_involution+0xc1>
jmp    131a <julius_regular_involution+0x1ca>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    -0x30(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <add_to_first@plt>
mov    -0x30(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    12d3 <julius_regular_involution+0x183>
lea    -0x60(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1070 <mul_by_delta@plt>
mov    -0x8(%rbp),%rdi
add    -0x30(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <add_to_first@plt>
mov    -0x8(%rbp),%rdi
add    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <add_to_first@plt>
mov    -0x30(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x30(%rbp)
jmp    12d8 <julius_regular_involution+0x188>
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1315 <julius_regular_involution+0x1c5>
mov    -0x8(%rbp),%rdi
add    -0x30(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <add_to_first@plt>
lea    -0x60(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1070 <mul_by_delta@plt>
mov    -0x30(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x30(%rbp)
jmp    12d8 <julius_regular_involution+0x188>
jmp    131a <julius_regular_involution+0x1ca>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<julius_regular_involution>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r13
mov    %r13,%rdi
mov    %rcx,%rsi
call   1060 <aes_128_encrypt@plt>
mov    %r15,%rcx
shr    $0x4,%rcx
lea    0x30(%rsp),%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1050 <evaluate_by_delta@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
lea    0x30(%rsp),%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <aes_128_encrypt@plt>
mov    %r15d,%ebx
sub    %r12d,%ebx
lea    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
test   $0x10,%bl
jne    1212 <julius_regular_involution+0xc2>
cmp    %r12,%r15
jbe    1290 <julius_regular_involution+0x140>
lea    0x10(%rsp),%rbx
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
lea    (%r14,%r12,1),%rdi
mov    %rbx,%rsi
call   1040 <add_to_first@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <mul_by_delta@plt>
add    $0x10,%r12
cmp    %r15,%r12
jb     11f0 <julius_regular_involution+0xa0>
jmp    1290 <julius_regular_involution+0x140>
lea    (%r14,%r12,1),%rdi
lea    0x10(%rsp),%rsi
call   1040 <add_to_first@plt>
lea    0x10(%r12),%rbx
cmp    %r15,%rbx
jae    125c <julius_regular_involution+0x10c>
lea    0x10(%rsp),%rbp
mov    %rsp,%rsi
mov    %rbp,%rdi
call   1070 <mul_by_delta@plt>
add    %r14,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <add_to_first@plt>
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <add_to_first@plt>
add    $0x20,%r12
mov    %r12,%rbx
cmp    %r15,%rbx
jae    1290 <julius_regular_involution+0x140>
lea    0x10(%rsp),%r12
mov    %rsp,%r13
nopl   0x0(%rax)
lea    (%r14,%rbx,1),%rdi
mov    %r12,%rsi
call   1040 <add_to_first@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <mul_by_delta@plt>
add    $0x10,%rbx
cmp    %r15,%rbx
jb     1270 <julius_regular_involution+0x120>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @julius_regular_involution(i8* %0, i64 %1, i64 %2, i64* %3) {
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = alloca [16 x i8]
%8 = alloca [16 x i8]
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%14 = call i32 @aes_128_encrypt(i8* %13, i64* %3)
%15 = lshr i64 %1, 4
%16 = call i32 @evaluate_by_delta(i8* %10, i8* %13, i8* %0, i64 %15)
%17 = call i32 @memcpy(i8* %11, i8* %10, i32 16)
%18 = call i32 @aes_128_encrypt(i8* %11, i64* %3)
%19 = sub i64 %1, %2
%20 = and i64 %19, 16
%21 = icmp eq i64 %20, 0
%22 = call i32 @memcpy(i8* %12, i8* %11, i32 16)
br i1 %21, label %23, label %32
23: ; preds = %4
%24 = icmp ugt i64 %1, %2
br i1 %24, label %25, label %53
25: ; preds = %23, %25
%26 = phi i64 [ %30, %25 ], [ %2, %23 ]
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = call i32 @add_to_first(i8* %27, i8* %12)
%29 = call i32 @mul_by_delta(i8* %12, i8* %13)
%30 = add i64 %26, 16
%31 = icmp ult i64 %30, %1
br i1 %31, label %25, label %53
32: ; preds = %4
%33 = getelementptr inbounds i8, i8* %0, i64 %2
%34 = call i32 @add_to_first(i8* %33, i8* %12)
%35 = add i64 %2, 16
%36 = icmp ult i64 %35, %1
br i1 %36, label %37, label %43
37: ; preds = %32
%38 = call i32 @mul_by_delta(i8* %12, i8* %13)
%39 = getelementptr inbounds i8, i8* %0, i64 %35
%40 = call i32 @add_to_first(i8* %39, i8* %12)
%41 = call i32 @add_to_first(i8* %39, i8* %11)
%42 = add i64 %2, 32
br label %43
43: ; preds = %37, %32
%44 = phi i64 [ %42, %37 ], [ %35, %32 ]
%45 = icmp ult i64 %44, %1
br i1 %45, label %46, label %53
46: ; preds = %43, %46
%47 = phi i64 [ %51, %46 ], [ %44, %43 ]
%48 = getelementptr inbounds i8, i8* %0, i64 %47
%49 = call i32 @add_to_first(i8* %48, i8* %12)
%50 = call i32 @mul_by_delta(i8* %12, i8* %13)
%51 = add i64 %47, 16
%52 = icmp ult i64 %51, %1
br i1 %52, label %46, label %53
53: ; preds = %46, %25, %43, %23
ret void
}