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

/* Variables and functions */
int /*<<< orphan*/ add_key(int /*<<< orphan*/ const *,
                           int /*<<< orphan*/ const *,
                           int /*<<< orphan*/ const *);
int /*<<< orphan*/ encrypt_last_r(int /*<<< orphan*/ const *,
                                  int /*<<< orphan*/ const *);
int /*<<< orphan*/ encrypt_r(int /*<<< orphan*/ const *,
                             int /*<<< orphan*/ const *);
void encrypt_with_keys(const uint16_t input[3], uint16_t output[3],
                       const uint16_t ks[3][3]) {
  add_key(input, output, ks[0]);
  for (int i = 1; i < 6; ++i) {
    encrypt_r(output, output);
    add_key(output, output, ks[i]);
  }
  encrypt_last_r(output, output);
  add_key(output, output, ks[6]);
}


x86 assembly (clang, -O0):
<encrypt_with_keys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <add_key@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x6,-0x1c(%rbp)
jge    119d <encrypt_with_keys+0x6d>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <encrypt_r@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
movslq -0x1c(%rbp),%rax
imul   $0xc,%rax,%rax
add    %rax,%rdx
call   1030 <add_key@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115c <encrypt_with_keys+0x2c>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <encrypt_last_r@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x48,%rdx
call   1030 <add_key@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encrypt_with_keys>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
call   1030 <add_key@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1040 <encrypt_r@plt>
lea    0xc(%r14),%rdx
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <add_key@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1040 <encrypt_r@plt>
lea    0x18(%r14),%rdx
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <add_key@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1040 <encrypt_r@plt>
lea    0x24(%r14),%rdx
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <add_key@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1040 <encrypt_r@plt>
lea    0x30(%r14),%rdx
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <add_key@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1040 <encrypt_r@plt>
lea    0x3c(%r14),%rdx
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <add_key@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1050 <encrypt_last_r@plt>
add    $0x48,%r14
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <add_key@plt>

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

LLVM IR (-O2):
define void @encrypt_with_keys(i32* %0, i32* %1, [3 x i32]* %2) {
%4 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%5 = tail call i32 @add_key(i32* %0, i32* %1, i32* %4)
%6 = tail call i32 @encrypt_r(i32* %1, i32* %1)
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 1, i64 0
%8 = tail call i32 @add_key(i32* %1, i32* %1, i32* %7)
%9 = tail call i32 @encrypt_r(i32* %1, i32* %1)
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 2, i64 0
%11 = tail call i32 @add_key(i32* %1, i32* %1, i32* %10)
%12 = tail call i32 @encrypt_r(i32* %1, i32* %1)
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 3, i64 0
%14 = tail call i32 @add_key(i32* %1, i32* %1, i32* %13)
%15 = tail call i32 @encrypt_r(i32* %1, i32* %1)
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 4, i64 0
%17 = tail call i32 @add_key(i32* %1, i32* %1, i32* %16)
%18 = tail call i32 @encrypt_r(i32* %1, i32* %1)
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 5, i64 0
%20 = tail call i32 @add_key(i32* %1, i32* %1, i32* %19)
%21 = tail call i32 @encrypt_last_r(i32* %1, i32* %1)
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 6, i64 0
%23 = tail call i32 @add_key(i32* %1, i32* %1, i32* %22)
ret void
}