#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*/ bytecpy(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ bytexor(unsigned char *, unsigned char *,
                           unsigned char const *, int);
int /*<<< orphan*/ clefiagfn4(unsigned char *, unsigned char *,
                              unsigned char const *, int const);
void clefiaencrypt(unsigned char *ct, const unsigned char *pt,
                   const unsigned char *rk, const int r) {
  unsigned char rin[16];
  unsigned char rout[16];
  bytecpy(rin, pt, 16);
  bytexor(rin + 4, rin + 4, rk + 0, 4);
  bytexor(rin + 12, rin + 12, rk + 4, 4);
  rk += 8;
  clefiagfn4(rout, rin, rk, r);
  bytecpy(ct, rout, 16);
  bytexor(ct + 4, ct + 4, rk + r * 8 + 0, 4);
  bytexor(ct + 12, ct + 12, rk + r * 8 + 4, 4);
}


x86 assembly (clang, -O0):
<clefiaencrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1050 <bytecpy@plt>
lea    -0x30(%rbp),%rdi
add    $0x4,%rdi
lea    -0x30(%rbp),%rsi
add    $0x4,%rsi
mov    -0x18(%rbp),%rdx
mov    $0x4,%ecx
call   1030 <bytexor@plt>
lea    -0x30(%rbp),%rdi
add    $0xc,%rdi
lea    -0x30(%rbp),%rsi
add    $0xc,%rsi
mov    -0x18(%rbp),%rdx
add    $0x4,%rdx
mov    $0x4,%ecx
call   1030 <bytexor@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <clefiagfn4@plt>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1050 <bytecpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
mov    -0x8(%rbp),%rsi
add    $0x4,%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rdx
mov    $0x4,%ecx
call   1030 <bytexor@plt>
mov    -0x8(%rbp),%rdi
add    $0xc,%rdi
mov    -0x8(%rbp),%rsi
add    $0xc,%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rdx
add    $0x4,%rdx
mov    $0x4,%ecx
call   1030 <bytexor@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clefiaencrypt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x10,%edx
call   1050 <bytecpy@plt>
lea    0x4(%rsp),%rdi
mov    %rdi,%rsi
mov    %r14,%rdx
mov    $0x4,%ecx
call   1030 <bytexor@plt>
lea    0xc(%rsp),%rdi
lea    0x4(%r14),%rdx
mov    %rdi,%rsi
mov    $0x4,%ecx
call   1030 <bytexor@plt>
lea    0x8(%r14),%rdx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%ecx
call   1040 <clefiagfn4@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x10,%edx
call   1050 <bytecpy@plt>
lea    0x4(%rbx),%rdi
shl    $0x3,%ebp
movslq %ebp,%rbp
lea    (%r14,%rbp,1),%rdx
add    $0x8,%rdx
mov    %rdi,%rsi
mov    $0x4,%ecx
call   1030 <bytexor@plt>
add    $0xc,%rbx
lea    (%r14,%rbp,1),%rdx
add    $0xc,%rdx
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    $0x4,%ecx
call   1030 <bytexor@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @clefiaencrypt(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [16 x i8]
%10 = alloca [16 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%12 = load i8*, i8** %6
%13 = call i32 @bytecpy(i8* %11, i8* %12, i32 16)
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%15 = getelementptr inbounds i8, i8* %14, i64 4
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%17 = getelementptr inbounds i8, i8* %16, i64 4
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = call i32 @bytexor(i8* %15, i8* %17, i8* %19, i32 4)
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 12
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 12
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i64 4
%27 = call i32 @bytexor(i8* %22, i8* %24, i8* %26, i32 4)
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 8
store i8* %29, i8** %7
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%32 = load i8*, i8** %7
%33 = load i32, i32* %8
%34 = call i32 @clefiagfn4(i8* %30, i8* %31, i8* %32, i32 %33)
%35 = load i8*, i8** %5
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%37 = call i32 @bytecpy(i8* %35, i8* %36, i32 16)
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 4
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i64 4
%42 = load i8*, i8** %7
%43 = load i32, i32* %8
%44 = mul nsw i32 %43, 8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
%47 = getelementptr inbounds i8, i8* %46, i64 0
%48 = call i32 @bytexor(i8* %39, i8* %41, i8* %47, i32 4)
%49 = load i8*, i8** %5
%50 = getelementptr inbounds i8, i8* %49, i64 12
%51 = load i8*, i8** %5
%52 = getelementptr inbounds i8, i8* %51, i64 12
%53 = load i8*, i8** %7
%54 = load i32, i32* %8
%55 = mul nsw i32 %54, 8
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
%58 = getelementptr inbounds i8, i8* %57, i64 4
%59 = call i32 @bytexor(i8* %50, i8* %52, i8* %58, i32 4)
ret void
}

LLVM IR (-O2):
define void @clefiaencrypt(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%9 = call i32 @bytecpy(i8* %7, i8* %1, i32 16)
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 4
%11 = call i32 @bytexor(i8* %10, i8* %10, i8* %2, i32 4)
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 12
%13 = getelementptr inbounds i8, i8* %2, i64 4
%14 = call i32 @bytexor(i8* %12, i8* %12, i8* %13, i32 4)
%15 = getelementptr inbounds i8, i8* %2, i64 8
%16 = call i32 @clefiagfn4(i8* %8, i8* %7, i8* %15, i32 %3)
%17 = call i32 @bytecpy(i8* %0, i8* %8, i32 16)
%18 = getelementptr inbounds i8, i8* %0, i64 4
%19 = shl nsw i32 %3, 3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %15, i64 %20
%22 = call i32 @bytexor(i8* %18, i8* %18, i8* %21, i32 4)
%23 = getelementptr inbounds i8, i8* %0, i64 12
%24 = getelementptr inbounds i8, i8* %21, i64 4
%25 = call i32 @bytexor(i8* %23, i8* %23, i8* %24, i32 4)
ret void
}