#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*/ clefiaf0xor(unsigned char *, unsigned char *,
                               unsigned char const *);
int /*<<< orphan*/ clefiaf1xor(unsigned char *, unsigned char *,
                               unsigned char const *);
void clefiagfn4(unsigned char *y, const unsigned char *x,
                const unsigned char *rk, int r) {
  unsigned char fin[16];
  unsigned char fout[16];
  bytecpy(fin, x, 16);
  while (r-- > 0) {
    clefiaf0xor(fout + 0, fin + 0, rk + 0);
    clefiaf1xor(fout + 8, fin + 8, rk + 4);
    rk += 8;
    if (r) {
      bytecpy(fin + 0, fout + 4, 12);
      bytecpy(fin + 12, fout + 0, 4);
    }
  }
  bytecpy(y, fout, 16);
}


x86 assembly (clang, -O0):
<clefiagfn4>:
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>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11e2 <clefiagfn4+0xb2>
lea    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <clefiaf0xor@plt>
lea    -0x40(%rbp),%rdi
add    $0x8,%rdi
lea    -0x30(%rbp),%rsi
add    $0x8,%rsi
mov    -0x18(%rbp),%rdx
add    $0x4,%rdx
call   1030 <clefiaf1xor@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11dd <clefiagfn4+0xad>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
add    $0x4,%rsi
mov    $0xc,%edx
call   1050 <bytecpy@plt>
lea    -0x30(%rbp),%rdi
add    $0xc,%rdi
lea    -0x40(%rbp),%rsi
mov    $0x4,%edx
call   1050 <bytecpy@plt>
jmp    1159 <clefiagfn4+0x29>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1050 <bytecpy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clefiagfn4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rdi,0x20(%rsp)
mov    %rsp,%rdi
mov    $0x10,%edx
call   1050 <bytecpy@plt>
test   %r14d,%r14d
jle    11f3 <clefiagfn4+0xc3>
lea    0x18(%rsp),%rbp
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
mov    %rbx,%rdx
call   1040 <clefiaf0xor@plt>
lea    0x4(%rbx),%rdx
mov    %rbp,%rdi
mov    %r15,%rsi
call   1030 <clefiaf1xor@plt>
add    $0xffffffff,%r14d
je     11f3 <clefiagfn4+0xc3>
add    $0xc,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x4(%rbx),%r13
mov    %rsp,%rdi
lea    0x14(%rsp),%rsi
mov    $0xc,%edx
call   1050 <bytecpy@plt>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%r12
mov    %r12,%rsi
mov    $0x4,%edx
call   1050 <bytecpy@plt>
mov    %r12,%rdi
mov    %rsp,%rsi
mov    %r13,%rdx
call   1040 <clefiaf0xor@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <clefiaf1xor@plt>
add    $0x8,%rbx
add    $0xffffffff,%r14d
jne    11a0 <clefiagfn4+0x70>
lea    0x10(%rsp),%rsi
mov    0x20(%rsp),%rdi
mov    $0x10,%edx
call   1050 <bytecpy@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @clefiagfn4(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)
br label %14
14: ; preds = %48, %4
%15 = load i32, i32* %8
%16 = add nsw i32 %15, -1
store i32 %16, i32* %8
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %49
18: ; preds = %14
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = call i32 @clefiaf0xor(i8* %20, i8* %22, i8* %24)
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%27 = getelementptr inbounds i8, i8* %26, i64 8
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%29 = getelementptr inbounds i8, i8* %28, i64 8
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i64 4
%32 = call i32 @clefiaf1xor(i8* %27, i8* %29, i8* %31)
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i64 8
store i8* %34, i8** %7
%35 = load i32, i32* %8
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %48
37: ; preds = %18
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%39 = getelementptr inbounds i8, i8* %38, i64 0
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%41 = getelementptr inbounds i8, i8* %40, i64 4
%42 = call i32 @bytecpy(i8* %39, i8* %41, i32 12)
%43 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%44 = getelementptr inbounds i8, i8* %43, i64 12
%45 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = call i32 @bytecpy(i8* %44, i8* %46, i32 4)
br label %48
48: ; preds = %37, %18
br label %14
49: ; preds = %14
%50 = load i8*, i8** %5
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%52 = call i32 @bytecpy(i8* %50, i8* %51, i32 16)
ret void
}

LLVM IR (-O2):
define void @clefiagfn4(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 = icmp sgt i32 %3, 0
br i1 %10, label %11, label %32
11: ; preds = %4
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 8
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 8
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 4
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 12
%16 = add nsw i32 %3, -1
%17 = call i32 @clefiaf0xor(i8* %8, i8* %7, i8* %2)
%18 = getelementptr inbounds i8, i8* %2, i64 4
%19 = call i32 @clefiaf1xor(i8* %12, i8* %13, i8* %18)
%20 = icmp eq i32 %16, 0
br i1 %20, label %32, label %21
21: ; preds = %11, %21
%22 = phi i32 [ %27, %21 ], [ %16, %11 ]
%23 = phi i8* [ %24, %21 ], [ %2, %11 ]
%24 = getelementptr inbounds i8, i8* %23, i64 8
%25 = call i32 @bytecpy(i8* %7, i8* %14, i32 12)
%26 = call i32 @bytecpy(i8* %15, i8* %8, i32 4)
%27 = add nsw i32 %22, -1
%28 = call i32 @clefiaf0xor(i8* %8, i8* %7, i8* %24)
%29 = getelementptr inbounds i8, i8* %23, i64 12
%30 = call i32 @clefiaf1xor(i8* %12, i8* %13, i8* %29)
%31 = icmp eq i32 %27, 0
br i1 %31, label %32, label %21
32: ; preds = %21, %11, %4
%33 = call i32 @bytecpy(i8* %0, i8* %8, i32 16)
ret void
}