#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*/ KeccakF200_StateExtractLanes(void *, unsigned char *, int);
int /*<<< orphan*/ KeccakF200_StateXORBytesInLane(void *, int, unsigned char *,
                                                  int /*<<< orphan*/, int);
int /*<<< orphan*/ KeccakF200_StateXORLanes(void *, unsigned char *, int);
int /*<<< orphan*/ KeccakP200_StatePermute(void *, int);
void Ket_WrapBlocks(void *state, const unsigned char *plaintext,
                    unsigned char *ciphertext, unsigned int nBlocks) {
  unsigned char keystream[(2 * 1)];
  unsigned char plaintemp[(2 * 1)];
  unsigned char frameAndPaddingBits[1];
  frameAndPaddingBits[0] = 0x08 | 0x07;
  while (nBlocks-- != 0) {
    KeccakF200_StateExtractLanes(state, keystream, (2 * 1) / 1);
    plaintemp[0] = plaintext[0];
    plaintemp[1] = plaintext[1];
    *(ciphertext++) = *(plaintext++) ^ keystream[0];
    *(ciphertext++) = *(plaintext++) ^ keystream[1];
    KeccakF200_StateXORLanes(state, plaintemp, (2 * 1) / 1);
    KeccakF200_StateXORBytesInLane(state, (2 * 1) / 1, frameAndPaddingBits, 0,
                                   1);
    KeccakP200_StatePermute(state, 1);
  }
}


x86 assembly (clang, -O0):
<Ket_WrapBlocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movb   $0xf,-0x21(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     1229 <Ket_WrapBlocks+0xe9>
mov    -0x8(%rbp),%rdi
lea    -0x1e(%rbp),%rsi
mov    $0x2,%edx
call   1050 <KeccakF200_StateExtractLanes@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x1f(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
movzbl -0x1e(%rbp),%ecx
xor    %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
movzbl -0x1d(%rbp),%ecx
xor    %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x2,%edx
call   1040 <KeccakF200_StateXORLanes@plt>
mov    -0x8(%rbp),%rdi
lea    -0x21(%rbp),%rdx
mov    $0x2,%esi
xor    %ecx,%ecx
mov    $0x1,%r8d
call   1030 <KeccakF200_StateXORBytesInLane@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1060 <KeccakP200_StatePermute@plt>
jmp    115b <Ket_WrapBlocks+0x1b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Ket_WrapBlocks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0xf,0x3(%rsp)
test   %ecx,%ecx
je     11ec <Ket_WrapBlocks+0xac>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %ecx,%r12d
xor    %r13d,%r13d
lea    0x3(%rsp),%rbp
nopl   0x0(%rax)
mov    %rbx,%rdi
lea    0x6(%rsp),%rsi
mov    $0x2,%edx
call   1050 <KeccakF200_StateExtractLanes@plt>
movzbl (%r15,%r13,2),%eax
mov    %al,0x4(%rsp)
movzbl 0x1(%r15,%r13,2),%ecx
mov    %cl,0x5(%rsp)
xor    0x6(%rsp),%al
mov    %al,(%r14,%r13,2)
movzbl 0x7(%rsp),%eax
xor    0x1(%r15,%r13,2),%al
mov    %al,0x1(%r14,%r13,2)
mov    %rbx,%rdi
lea    0x4(%rsp),%rsi
mov    $0x2,%edx
call   1040 <KeccakF200_StateXORLanes@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %rbp,%rdx
xor    %ecx,%ecx
mov    $0x1,%r8d
call   1030 <KeccakF200_StateXORBytesInLane@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <KeccakP200_StatePermute@plt>
add    $0x1,%r13
cmp    %r13d,%r12d
jne    1170 <Ket_WrapBlocks+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @Ket_WrapBlocks(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [2 x i8]
%10 = alloca [2 x i8]
%11 = alloca [1 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %11, i64 0, i64 0
store i8 15, i8* %12
br label %13
13: ; preds = %17, %4
%14 = load i32, i32* %8
%15 = add i32 %14, -1
store i32 %15, i32* %8
%16 = icmp ne i32 %14, 0
br i1 %16, label %17, label %59
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%20 = call i32 @KeccakF200_StateExtractLanes(i8* %18, i8* %19, i32 2)
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
store i8 %23, i8* %24
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 1
store i8 %27, i8* %28
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %6
%31 = load i8, i8* %29
%32 = zext i8 %31 to i32
%33 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = xor i32 %32, %35
%37 = trunc i32 %36 to i8
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %7
store i8 %37, i8* %38
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %6
%42 = load i8, i8* %40
%43 = zext i8 %42 to i32
%44 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 1
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = xor i32 %43, %46
%48 = trunc i32 %47 to i8
%49 = load i8*, i8** %7
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %7
store i8 %48, i8* %49
%51 = load i8*, i8** %5
%52 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%53 = call i32 @KeccakF200_StateXORLanes(i8* %51, i8* %52, i32 2)
%54 = load i8*, i8** %5
%55 = getelementptr inbounds [1 x i8], [1 x i8]* %11, i64 0, i64 0
%56 = call i32 @KeccakF200_StateXORBytesInLane(i8* %54, i32 2, i8* %55, i32 0, i32 1)
%57 = load i8*, i8** %5
%58 = call i32 @KeccakP200_StatePermute(i8* %57, i32 1)
br label %13
59: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @Ket_WrapBlocks(i8* %0, i8* nocapture %1, i8* nocapture writeonly %2, i32 %3) {
%5 = alloca [2 x i8]
%6 = alloca [2 x i8]
%7 = alloca [1 x i8]
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
store i8 15, i8* %10
%11 = icmp eq i32 %3, 0
br i1 %11, label %36, label %12
12: ; preds = %4
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
br label %15
15: ; preds = %12, %15
%16 = phi i32 [ %3, %12 ], [ %19, %15 ]
%17 = phi i8* [ %2, %12 ], [ %31, %15 ]
%18 = phi i8* [ %1, %12 ], [ %27, %15 ]
%19 = add i32 %16, -1
%20 = call i32 @KeccakF200_StateExtractLanes(i8* %0, i8* %8, i32 2)
%21 = load i8, i8* %18
store i8 %21, i8* %9
%22 = getelementptr inbounds i8, i8* %18, i64 1
%23 = load i8, i8* %22
store i8 %23, i8* %13
%24 = load i8, i8* %8
%25 = xor i8 %24, %21
%26 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %25, i8* %17
%27 = getelementptr inbounds i8, i8* %18, i64 2
%28 = load i8, i8* %22
%29 = load i8, i8* %14
%30 = xor i8 %29, %28
%31 = getelementptr inbounds i8, i8* %17, i64 2
store i8 %30, i8* %26
%32 = call i32 @KeccakF200_StateXORLanes(i8* %0, i8* %9, i32 2)
%33 = call i32 @KeccakF200_StateXORBytesInLane(i8* %0, i32 2, i8* %10, i32 0, i32 1)
%34 = call i32 @KeccakP200_StatePermute(i8* %0, i32 1)
%35 = icmp eq i32 %19, 0
br i1 %35, label %36, label %15
36: ; preds = %15, %4
ret void
}