#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*/ KeccakP200_AddBytes(void *, unsigned char *, int, int);
int /*<<< orphan*/ KeccakP200_ExtractBytes(void *, unsigned char *,
                                           int /*<<< orphan*/, int);
int /*<<< orphan*/ KeccakP200_Permute_Nrounds(void *, int);
unsigned int Ket_WrapBlocks(void *state, const unsigned char *plaintext,
                            unsigned char *ciphertext, unsigned int nBlocks) {
  unsigned int ciphertext_size_on_blocks = 0;
  unsigned char keystream[(2 * 200 / 8 / 25)];
  unsigned char plaintemp[(2 * 200 / 8 / 25)];
  unsigned char frameAndPaddingBits[1];
  frameAndPaddingBits[0] = 0x08 | 0x07;
  while (nBlocks-- != 0) {
    KeccakP200_ExtractBytes(state, keystream, 0, (2 * 200 / 8 / 25));
    plaintemp[0] = plaintext[0];
    plaintemp[1] = plaintext[1];
    *(ciphertext++) = *(plaintext++) ^ keystream[0];
    *(ciphertext++) = *(plaintext++) ^ keystream[1];
    ciphertext_size_on_blocks += 2;
    KeccakP200_AddBytes(state, plaintemp, 0, (2 * 200 / 8 / 25));
    KeccakP200_AddBytes(state, frameAndPaddingBits, (2 * 200 / 8 / 25), 1);
    KeccakP200_Permute_Nrounds(state, 1);
  }
  return ciphertext_size_on_blocks;
}


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)
movl   $0x0,-0x20(%rbp)
movb   $0xf,-0x25(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     122a <Ket_WrapBlocks+0xfa>
mov    -0x8(%rbp),%rdi
lea    -0x22(%rbp),%rsi
xor    %edx,%edx
mov    $0x2,%ecx
call   1030 <KeccakP200_ExtractBytes@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x23(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
movzbl -0x22(%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 -0x21(%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    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
mov    $0x2,%ecx
call   1050 <KeccakP200_AddBytes@plt>
mov    -0x8(%rbp),%rdi
lea    -0x25(%rbp),%rsi
mov    $0x2,%edx
mov    $0x1,%ecx
call   1050 <KeccakP200_AddBytes@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1040 <KeccakP200_Permute_Nrounds@plt>
jmp    1152 <Ket_WrapBlocks+0x22>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Ket_WrapBlocks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movb   $0xf,0xf(%rsp)
test   %ecx,%ecx
je     11f6 <Ket_WrapBlocks+0xc6>
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %ecx,0x14(%rsp)
mov    %ecx,%r12d
xor    %r13d,%r13d
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
lea    0x12(%rsp),%rsi
xor    %edx,%edx
mov    $0x2,%ecx
call   1030 <KeccakP200_ExtractBytes@plt>
movzbl 0x0(%rbp,%r13,2),%eax
mov    %al,0x10(%rsp)
movzbl 0x1(%rbp,%r13,2),%ecx
mov    %cl,0x11(%rsp)
xor    0x12(%rsp),%al
mov    %al,(%r15,%r13,2)
movzbl 0x13(%rsp),%eax
xor    0x1(%rbp,%r13,2),%al
mov    %al,0x1(%r15,%r13,2)
mov    %rbx,%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
mov    $0x2,%ecx
call   1050 <KeccakP200_AddBytes@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
mov    $0x1,%ecx
call   1050 <KeccakP200_AddBytes@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <KeccakP200_Permute_Nrounds@plt>
add    $0x1,%r13
cmp    %r13d,%r12d
jne    1170 <Ket_WrapBlocks+0x40>
mov    0x14(%rsp),%eax
add    %eax,%eax
jmp    11f8 <Ket_WrapBlocks+0xc8>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @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 %38, 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 @KeccakP200_ExtractBytes(i8* %0, i8* %8, i32 0, 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 @KeccakP200_AddBytes(i8* %0, i8* %9, i32 0, i32 2)
%33 = call i32 @KeccakP200_AddBytes(i8* %0, i8* %10, i32 2, i32 1)
%34 = call i32 @KeccakP200_Permute_Nrounds(i8* %0, i32 1)
%35 = icmp eq i32 %19, 0
br i1 %35, label %36, label %15
36: ; preds = %15
%37 = shl i32 %3, 1
br label %38
38: ; preds = %36, %4
%39 = phi i32 [ 0, %4 ], [ %37, %36 ]
ret i32 %39
}