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

/* Variables and functions */
int /*<<< orphan*/ encrypt_with_keys(int const *, int *, int **);
int /*<<< orphan*/ next_key(int *, int *, int);
int /*<<< orphan*/ printf(char *, int, int, int, int);
void encrypt(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);
  for (int i = 0; i <= 6; ++i)
    printf("%d %04x%04x%04x\n", i, ks[i][0], ks[i][1], ks[i][2]);
  encrypt_with_keys(input, output, ks);
}


x86 assembly (clang, -O0):
<encrypt>:
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   1050 <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     11cd <encrypt+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    118b <encrypt+0x4b>
movl   $0x0,-0x78(%rbp)
cmpl   $0x6,-0x78(%rbp)
jg     1231 <encrypt+0xf1>
mov    -0x78(%rbp),%esi
movslq -0x78(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edx
movslq -0x78(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x4(%rax),%ecx
movslq -0x78(%rbp),%rdi
lea    -0x70(%rbp),%rax
imul   $0xc,%rdi,%rdi
add    %rdi,%rax
mov    0x8(%rax),%r8d
lea    0xde2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    11d4 <encrypt+0x94>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   1060 <encrypt_with_keys@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
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),%r13
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    %r13,%rsi
mov    $0x4,%edx
call   1030 <next_key@plt>
lea    0x3c(%rsp),%rbx
mov    %r13,%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    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%r8d
lea    0xdf5(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <printf@plt>
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
mov    0x18(%rsp),%edx
mov    0x1c(%rsp),%ecx
mov    0x20(%rsp),%r8d
mov    %rbx,%rdi
mov    $0x2,%esi
call   1040 <printf@plt>
mov    0x24(%rsp),%edx
mov    0x28(%rsp),%ecx
mov    0x2c(%rsp),%r8d
mov    %rbx,%rdi
mov    $0x3,%esi
call   1040 <printf@plt>
mov    0x30(%rsp),%edx
mov    0x34(%rsp),%ecx
mov    0x38(%rsp),%r8d
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <printf@plt>
mov    0x3c(%rsp),%edx
mov    0x40(%rsp),%ecx
mov    0x44(%rsp),%r8d
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <printf@plt>
mov    0x48(%rsp),%edx
mov    0x4c(%rsp),%ecx
mov    0x50(%rsp),%r8d
mov    %rbx,%rdi
mov    $0x6,%esi
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <encrypt_with_keys@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"%d %04x%04x%04x\0A\00"
define void @encrypt(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
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%10 = bitcast [7 x [3 x i32]]* %7 to i8*
%11 = load i32*, i32** %6
%12 = getelementptr inbounds i32, i32* %11, i64 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 0
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %14, i64 0, i64 0
store i32 %13, i32* %15
%16 = load i32*, i32** %6
%17 = getelementptr inbounds i32, i32* %16, i64 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 0
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %19, i64 0, i64 1
store i32 %18, i32* %20
%21 = load i32*, i32** %6
%22 = getelementptr inbounds i32, i32* %21, i64 2
%23 = load i32, i32* %22
%24 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 0
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %24, i64 0, i64 2
store i32 %23, i32* %25
store i32 1, i32* %8
br label %26
26: ; preds = %41, %3
%27 = load i32, i32* %8
%28 = icmp sle i32 %27, 6
br i1 %28, label %29, label %44
29: ; preds = %26
%30 = load i32, i32* %8
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 %32
%34 = getelementptr inbounds [3 x i32], [3 x i32]* %33, i64 0, i64 0
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 %36
%38 = getelementptr inbounds [3 x i32], [3 x i32]* %37, i64 0, i64 0
%39 = load i32, i32* %8
%40 = call i32 @next_key(i32* %34, i32* %38, i32 %39)
br label %41
41: ; preds = %29
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %26
44: ; preds = %26
store i32 0, i32* %9
br label %45
45: ; preds = %66, %44
%46 = load i32, i32* %9
%47 = icmp sle i32 %46, 6
br i1 %47, label %48, label %69
48: ; preds = %45
%49 = load i32, i32* %9
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 %51
%53 = getelementptr inbounds [3 x i32], [3 x i32]* %52, i64 0, i64 0
%54 = load i32, i32* %53
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 %56
%58 = getelementptr inbounds [3 x i32], [3 x i32]* %57, i64 0, i64 1
%59 = load i32, i32* %58
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 %61
%63 = getelementptr inbounds [3 x i32], [3 x i32]* %62, i64 0, i64 2
%64 = load i32, i32* %63
%65 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %49, i32 %54, i32 %59, i32 %64)
br label %66
66: ; preds = %48
%67 = load i32, i32* %9
%68 = add nsw i32 %67, 1
store i32 %68, i32* %9
br label %45
69: ; preds = %45
%70 = load i32*, i32** %4
%71 = load i32*, i32** %5
%72 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %7, i64 0, i64 0
%73 = bitcast [3 x i32]* %72 to i32**
%74 = call i32 @encrypt_with_keys(i32* %70, i32* %71, i32** %73)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"%d %04x%04x%04x\0A\00"
define void @encrypt(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 = load i32, i32* %7
%27 = load i32, i32* %10
%28 = load i32, i32* %13
%29 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 0, i32 %26, i32 %27, i32 %28)
%30 = load i32, i32* %14
%31 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 1, i64 1
%32 = load i32, i32* %31
%33 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 1, i64 2
%34 = load i32, i32* %33
%35 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 1, i32 %30, i32 %32, i32 %34)
%36 = load i32, i32* %16
%37 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 2, i64 1
%38 = load i32, i32* %37
%39 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 2, i64 2
%40 = load i32, i32* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 2, i32 %36, i32 %38, i32 %40)
%42 = load i32, i32* %18
%43 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 3, i64 1
%44 = load i32, i32* %43
%45 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 3, i64 2
%46 = load i32, i32* %45
%47 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 3, i32 %42, i32 %44, i32 %46)
%48 = load i32, i32* %20
%49 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 4, i64 1
%50 = load i32, i32* %49
%51 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 4, i64 2
%52 = load i32, i32* %51
%53 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 4, i32 %48, i32 %50, i32 %52)
%54 = load i32, i32* %22
%55 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 5, i64 1
%56 = load i32, i32* %55
%57 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 5, i64 2
%58 = load i32, i32* %57
%59 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 5, i32 %54, i32 %56, i32 %58)
%60 = load i32, i32* %24
%61 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 6, i64 1
%62 = load i32, i32* %61
%63 = getelementptr inbounds [7 x [3 x i32]], [7 x [3 x i32]]* %4, i64 0, i64 6, i64 2
%64 = load i32, i32* %63
%65 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 6, i32 %60, i32 %62, i32 %64)
%66 = bitcast [7 x [3 x i32]]* %4 to i32**
%67 = call i32 @encrypt_with_keys(i32* %0, i32* %1, i32** %66)
ret void
}