#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*/ Encrypt_StateUpdate128(unsigned char *, unsigned char,
                                          unsigned char *, unsigned char *, int,
                                          int);
void acorn128_initialization(const unsigned char *key, const unsigned char *iv,
                             unsigned char *state) {
  int i, j;
  unsigned char m[1536], ks, tem;
  for (j = 0; j <= 292; j++)
    state[j] = 0;
  for (j = 0; j <= 127; j++)
    m[j] = (key[j / 8] >> (j & 7)) & 1;
  for (j = 0; j <= 127; j++)
    m[j + 128] = (iv[j / 8] >> (j & 7)) & 1;
  m[256] = 1;
  for (j = 257; j <= 1535; j++)
    m[j] = 0;
  for (i = 0; i < 1536; i++) {
    Encrypt_StateUpdate128(state, m[i], &tem, &ks, 1, 1);
  }
}


x86 assembly (clang, -O0):
<acorn128_initialization>:
push   %rbp
mov    %rsp,%rbp
sub    $0x640,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x124,-0x20(%rbp)
jg     1155 <acorn128_initialization+0x45>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112e <acorn128_initialization+0x1e>
movl   $0x0,-0x20(%rbp)
cmpl   $0x7f,-0x20(%rbp)
jg     11b2 <acorn128_initialization+0xa2>
mov    -0x8(%rbp),%rax
mov    %rax,-0x630(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x630(%rbp),%rax
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x20(%rbp),%ecx
and    $0x7,%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    %al,%cl
movslq -0x20(%rbp),%rax
mov    %cl,-0x620(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115c <acorn128_initialization+0x4c>
movl   $0x0,-0x20(%rbp)
cmpl   $0x7f,-0x20(%rbp)
jg     1215 <acorn128_initialization+0x105>
mov    -0x10(%rbp),%rax
mov    %rax,-0x638(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x638(%rbp),%rax
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x20(%rbp),%ecx
and    $0x7,%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    %al,%cl
mov    -0x20(%rbp),%eax
add    $0x80,%eax
cltq
mov    %cl,-0x620(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b9 <acorn128_initialization+0xa9>
movb   $0x1,-0x520(%rbp)
movl   $0x101,-0x20(%rbp)
cmpl   $0x5ff,-0x20(%rbp)
jg     124a <acorn128_initialization+0x13a>
movslq -0x20(%rbp),%rax
movb   $0x0,-0x620(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1223 <acorn128_initialization+0x113>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x600,-0x1c(%rbp)
jge    1298 <acorn128_initialization+0x188>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
lea    -0x622(%rbp),%rdx
lea    -0x621(%rbp),%rcx
mov    $0x1,%r9d
movzbl -0x620(%rbp,%rax,1),%esi
ff
mov    %r9d,%r8d
call   1030 <Encrypt_StateUpdate128@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1251 <acorn128_initialization+0x141>
add    $0x640,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<acorn128_initialization>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x618,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebx,%ebx
mov    $0x125,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
shr    $0x3,%eax
movzbl (%r12,%rax,1),%edx
mov    %ebx,%ecx
and    $0x6,%cl
shr    %cl,%dl
and    $0x1,%dl
mov    %dl,0x10(%rsp,%rbx,1)
movzbl (%r12,%rax,1),%eax
lea    0x1(%rbx),%ecx
and    $0x7,%cl
shr    %cl,%al
and    $0x1,%al
mov    %al,0x11(%rsp,%rbx,1)
add    $0x2,%rbx
cmp    $0x80,%rbx
jne    1150 <acorn128_initialization+0x30>
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
mov    %eax,%edx
shr    $0x3,%edx
movzbl (%r15,%rdx,1),%ebx
mov    %eax,%ecx
and    $0x6,%cl
shr    %cl,%bl
and    $0x1,%bl
mov    %bl,0x90(%rsp,%rax,1)
movzbl (%r15,%rdx,1),%edx
or     $0x1,%cl
shr    %cl,%dl
and    $0x1,%dl
mov    %dl,0x91(%rsp,%rax,1)
add    $0x2,%rax
cmp    $0x80,%rax
jne    1190 <acorn128_initialization+0x70>
movb   $0x1,0x110(%rsp)
01
lea    0x111(%rsp),%rdi
xor    %ebx,%ebx
mov    $0x4ff,%edx
xor    %esi,%esi
call   1040 <memset@plt>
lea    0xe(%rsp),%r15
lea    0xf(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x10(%rsp,%rbx,1),%esi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    $0x1,%r8d
mov    $0x1,%r9d
call   1030 <Encrypt_StateUpdate128@plt>
add    $0x1,%rbx
cmp    $0x600,%rbx
jne    1200 <acorn128_initialization+0xe0>
add    $0x618,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @acorn128_initialization(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1536 x i8]
%10 = alloca i8
%11 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %8
br label %12
12: ; preds = %20, %3
%13 = load i32, i32* %8
%14 = icmp sle i32 %13, 292
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i8*, i8** %6
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %15
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
br label %12
23: ; preds = %12
store i32 0, i32* %8
br label %24
24: ; preds = %43, %23
%25 = load i32, i32* %8
%26 = icmp sle i32 %25, 127
br i1 %26, label %27, label %46
27: ; preds = %24
%28 = load i8*, i8** %4
%29 = load i32, i32* %8
%30 = sdiv i32 %29, 8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = load i32, i32* %8
%36 = and i32 %35, 7
%37 = ashr i32 %34, %36
%38 = and i32 %37, 1
%39 = trunc i32 %38 to i8
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [1536 x i8], [1536 x i8]* %9, i64 0, i64 %41
store i8 %39, i8* %42
br label %43
43: ; preds = %27
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %24
46: ; preds = %24
store i32 0, i32* %8
br label %47
47: ; preds = %67, %46
%48 = load i32, i32* %8
%49 = icmp sle i32 %48, 127
br i1 %49, label %50, label %70
50: ; preds = %47
%51 = load i8*, i8** %5
%52 = load i32, i32* %8
%53 = sdiv i32 %52, 8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = load i32, i32* %8
%59 = and i32 %58, 7
%60 = ashr i32 %57, %59
%61 = and i32 %60, 1
%62 = trunc i32 %61 to i8
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 128
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [1536 x i8], [1536 x i8]* %9, i64 0, i64 %65
store i8 %62, i8* %66
br label %67
67: ; preds = %50
%68 = load i32, i32* %8
%69 = add nsw i32 %68, 1
store i32 %69, i32* %8
br label %47
70: ; preds = %47
%71 = getelementptr inbounds [1536 x i8], [1536 x i8]* %9, i64 0, i64 256
store i8 1, i8* %71
store i32 257, i32* %8
br label %72
72: ; preds = %79, %70
%73 = load i32, i32* %8
%74 = icmp sle i32 %73, 1535
br i1 %74, label %75, label %82
75: ; preds = %72
%76 = load i32, i32* %8
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [1536 x i8], [1536 x i8]* %9, i64 0, i64 %77
store i8 0, i8* %78
br label %79
79: ; preds = %75
%80 = load i32, i32* %8
%81 = add nsw i32 %80, 1
store i32 %81, i32* %8
br label %72
82: ; preds = %72
store i32 0, i32* %7
br label %83
83: ; preds = %93, %82
%84 = load i32, i32* %7
%85 = icmp slt i32 %84, 1536
br i1 %85, label %86, label %96
86: ; preds = %83
%87 = load i8*, i8** %6
%88 = load i32, i32* %7
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [1536 x i8], [1536 x i8]* %9, i64 0, i64 %89
%91 = load i8, i8* %90
%92 = call i32 @Encrypt_StateUpdate128(i8* %87, i8 zeroext %91, i8* %11, i8* %10, i32 1, i32 1)
br label %93
93: ; preds = %86
%94 = load i32, i32* %7
%95 = add nsw i32 %94, 1
store i32 %95, i32* %7
br label %83
96: ; preds = %83
ret void
}

LLVM IR (-O2):
define void @acorn128_initialization(i8* nocapture %0, i8* nocapture %1, i8* %2) {
%4 = alloca [1536 x i8]
%5 = alloca i8
%6 = alloca i8
%7 = getelementptr inbounds [1536 x i8], [1536 x i8]* %4, i64 0, i64 0
br label %8
8: ; preds = %8, %3
%9 = phi i64 [ 0, %3 ], [ %29, %8 ]
%10 = trunc i64 %9 to i8
%11 = lshr i64 %9, 3
%12 = and i64 %11, 536870911
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = and i8 %10, 6
%16 = lshr i8 %14, %15
%17 = and i8 %16, 1
%18 = getelementptr inbounds [1536 x i8], [1536 x i8]* %4, i64 0, i64 %9
store i8 %17, i8* %18
%19 = or i64 %9, 1
%20 = trunc i64 %19 to i8
%21 = lshr i64 %9, 3
%22 = and i64 %21, 536870911
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = and i8 %20, 7
%26 = lshr i8 %24, %25
%27 = and i8 %26, 1
%28 = getelementptr inbounds [1536 x i8], [1536 x i8]* %4, i64 0, i64 %19
store i8 %27, i8* %28
%29 = add nuw nsw i64 %9, 2
%30 = icmp eq i64 %29, 128
br i1 %30, label %31, label %8
31: ; preds = %8, %31
%32 = phi i64 [ %54, %31 ], [ 0, %8 ]
%33 = trunc i64 %32 to i8
%34 = lshr i64 %32, 3
%35 = and i64 %34, 536870911
%36 = getelementptr inbounds i8, i8* %1, i64 %35
%37 = load i8, i8* %36
%38 = and i8 %33, 6
%39 = lshr i8 %37, %38
%40 = and i8 %39, 1
%41 = add nuw nsw i64 %32, 128
%42 = getelementptr inbounds [1536 x i8], [1536 x i8]* %4, i64 0, i64 %41
store i8 %40, i8* %42
%43 = trunc i64 %32 to i8
%44 = lshr i64 %32, 3
%45 = and i64 %44, 536870911
%46 = getelementptr inbounds i8, i8* %1, i64 %45
%47 = load i8, i8* %46
%48 = and i8 %43, 6
%49 = or i8 %48, 1
%50 = lshr i8 %47, %49
%51 = and i8 %50, 1
%52 = add nuw nsw i64 %32, 129
%53 = getelementptr inbounds [1536 x i8], [1536 x i8]* %4, i64 0, i64 %52
store i8 %51, i8* %53
%54 = add nuw nsw i64 %32, 2
%55 = icmp eq i64 %54, 128
br i1 %55, label %56, label %31
56: ; preds = %31
%57 = getelementptr inbounds [1536 x i8], [1536 x i8]* %4, i64 0, i64 256
store i8 1, i8* %57
%58 = getelementptr inbounds [1536 x i8], [1536 x i8]* %4, i64 0, i64 257
br label %59
59: ; preds = %56, %59
%60 = phi i64 [ 0, %56 ], [ %64, %59 ]
%61 = getelementptr inbounds [1536 x i8], [1536 x i8]* %4, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = call i32 @Encrypt_StateUpdate128(i8* %2, i8 zeroext %62, i8* %6, i8* %5, i32 1, i32 1)
%64 = add nuw nsw i64 %60, 1
%65 = icmp eq i64 %64, 1536
br i1 %65, label %66, label %59
66: ; preds = %59
ret void
}