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

/* Variables and functions */
int /*<<< orphan*/ decrypt_with_keys(int /*<<< orphan*/ const *,
                                     int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ **);
int /*<<< orphan*/ next_key(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
void decrypt(const uint16_t input[3], uint16_t output[3],
             const uint16_t k0[3]) {
  uint16_t ks[6 + 1][3] = {};
  ks[0][0] = k0[0];
  ks[0][1] = k0[1];
  ks[0][2] = k0[2];
  for (int i = 1; i <= 6; ++i)
    next_key(ks[i - 1], ks[i], i);
  decrypt_with_keys(input, output, ks);
}


x86 assembly (clang, -O0):
<decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x54,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x68(%rbp)
movl   $0x1,-0x74(%rbp)
cmpl   $0x6,-0x74(%rbp)
jg     11bd <decrypt+0x8d>
mov    -0x74(%rbp),%eax
sub    $0x1,%eax
cltq
lea    -0x70(%rbp),%rdi
imul   $0xc,%rax,%rax
add    %rax,%rdi
movslq -0x74(%rbp),%rax
lea    -0x70(%rbp),%rsi
imul   $0xc,%rax,%rax
add    %rax,%rsi
mov    -0x74(%rbp),%edx
call   1030 <next_key@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    117b <decrypt+0x4b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   1050 <decrypt_with_keys@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %rdi,%r13
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x50(%rsp)
lea    0x30(%rsp),%r12
mov    (%rdx),%eax
mov    %eax,(%rsp)
mov    0x4(%rdx),%eax
mov    %eax,0x4(%rsp)
mov    0x8(%rdx),%eax
mov    %eax,0x8(%rsp)
lea    0xc(%rsp),%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <next_key@plt>
lea    0x18(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1030 <next_key@plt>
lea    0x24(%rsp),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1030 <next_key@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <next_key@plt>
lea    0x3c(%rsp),%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1030 <next_key@plt>
lea    0x48(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x6,%edx
call   1030 <next_key@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <decrypt_with_keys@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @decrypt(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [7 x [3 x i32]]
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%9 = bitcast [7 x [3 x i32]]* %7 to i8*
%10 = load i32*, i32** %6
%11 = getelementptr inbounds i32, i32* %10, i64 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 0
%14 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 0
store i32 %12, i32* %14
%15 = load i32*, i32** %6
%16 = getelementptr inbounds i32, i32* %15, i64 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 0
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %18, i64 0, i64 1
store i32 %17, i32* %19
%20 = load i32*, i32** %6
%21 = getelementptr inbounds i32, i32* %20, i64 2
%22 = load i32, i32* %21
%23 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 0
%24 = getelementptr inbounds [3 x i32], [3 x i32]* %23, i64 0, i64 2
store i32 %22, i32* %24
store i32 1, i32* %8
br label %25
25: ; preds = %40, %3
%26 = load i32, i32* %8
%27 = icmp sle i32 %26, 6
br i1 %27, label %28, label %43
28: ; preds = %25
%29 = load i32, i32* %8
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 %31
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %32, i64 0, i64 0
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 %35
%37 = getelementptr inbounds [3 x i32], [3 x i32]* %36, i64 0, i64 0
%38 = load i32, i32* %8
%39 = call i32 @next_key(i32* %33, i32* %37, i32 %38)
br label %40
40: ; preds = %28
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %25
43: ; preds = %25
%44 = load i32*, i32** %4
%45 = load i32*, i32** %5
%46 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 0
%47 = bitcast [3 x i32]* %46 to i32**
%48 = call i32 @decrypt_with_keys(i32* %44, i32* %45, i32** %47)
ret void
}

LLVM IR (-O2):
define void @decrypt(i32* %0, i32* %1, i32* nocapture %2) {
%4 = alloca [7 x [3 x i32]]
%5 = bitcast [7 x [3 x i32]]* %4 to i8*
%6 = load i32, i32* %2
%7 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 0, i64 0
store i32 %6, i32* %7
%8 = getelementptr inbounds i32, i32* %2, i64 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 0, i64 1
store i32 %9, i32* %10
%11 = getelementptr inbounds i32, i32* %2, i64 2
%12 = load i32, i32* %11
%13 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 0, i64 2
store i32 %12, i32* %13
%14 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 1, i64 0
%15 = call i32 @next_key(i32* %7, i32* %14, i32 1)
%16 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 2, i64 0
%17 = call i32 @next_key(i32* %14, i32* %16, i32 2)
%18 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 3, i64 0
%19 = call i32 @next_key(i32* %16, i32* %18, i32 3)
%20 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 4, i64 0
%21 = call i32 @next_key(i32* %18, i32* %20, i32 4)
%22 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 5, i64 0
%23 = call i32 @next_key(i32* %20, i32* %22, i32 5)
%24 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 6, i64 0
%25 = call i32 @next_key(i32* %22, i32* %24, i32 6)
%26 = bitcast [7 x [3 x i32]]* %4 to i32**
%27 = call i32 @decrypt_with_keys(i32* %0, i32* %1, i32** %26)
ret void
}