#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*/ KeccakP400_AddBytes(void *, unsigned char *, int, int);
int /*<<< orphan*/ KeccakP400_ExtractBytes(void *, unsigned char *,
                                           int /*<<< orphan*/, int);
int /*<<< orphan*/ keccakP400NRounds(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 * 400 / 8 / 25)];
  unsigned char plaintemp[(2 * 400 / 8 / 25)];
  unsigned char frameAndPaddingBits[1];
  frameAndPaddingBits[0] = 0x08 | 0x07;
  while (nBlocks-- != 0) {
    KeccakP400_ExtractBytes(state, keystream, 0, (2 * 400 / 8 / 25));
    plaintemp[0] = plaintext[0];
    plaintemp[1] = plaintext[1];
    plaintemp[2] = plaintext[2];
    plaintemp[3] = plaintext[3];
    *(ciphertext++) = *(plaintext++) ^ keystream[0];
    *(ciphertext++) = *(plaintext++) ^ keystream[1];
    ciphertext_size_on_blocks++;
    ciphertext_size_on_blocks++;
    *(ciphertext++) = *(plaintext++) ^ keystream[2];
    *(ciphertext++) = *(plaintext++) ^ keystream[3];
    ciphertext_size_on_blocks++;
    ciphertext_size_on_blocks++;
    KeccakP400_AddBytes(state, plaintemp, 0, (2 * 400 / 8 / 25));
    KeccakP400_AddBytes(state, frameAndPaddingBits, (2 * 400 / 8 / 25), 1);
    keccakP400NRounds(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,-0x29(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     12af <Ket_WrapBlocks+0x17f>
mov    -0x8(%rbp),%rdi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1050 <KeccakP400_ExtractBytes@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x27(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x26(%rbp)
mov    -0x10(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0x25(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
movzbl -0x24(%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 -0x23(%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    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%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    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <KeccakP400_AddBytes@plt>
mov    -0x8(%rbp),%rdi
lea    -0x29(%rbp),%rsi
mov    $0x4,%edx
mov    $0x1,%ecx
call   1040 <KeccakP400_AddBytes@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1030 <keccakP400NRounds@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,0xb(%rsp)
test   %ecx,%ecx
je     122d <Ket_WrapBlocks+0xfd>
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %ecx,0x14(%rsp)
mov    %ecx,%r12d
xor    %r13d,%r13d
lea    0xb(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1050 <KeccakP400_ExtractBytes@plt>
movzbl 0x0(%rbp,%r13,4),%eax
mov    %al,0xc(%rsp)
movzbl 0x1(%rbp,%r13,4),%ecx
mov    %cl,0xd(%rsp)
movzbl 0x2(%rbp,%r13,4),%ecx
mov    %cl,0xe(%rsp)
movzbl 0x3(%rbp,%r13,4),%ecx
mov    %cl,0xf(%rsp)
xor    0x10(%rsp),%al
mov    %al,(%r15,%r13,4)
movzbl 0x11(%rsp),%eax
xor    0x1(%rbp,%r13,4),%al
mov    %al,0x1(%r15,%r13,4)
movzbl 0x12(%rsp),%eax
xor    0x2(%rbp,%r13,4),%al
mov    %al,0x2(%r15,%r13,4)
movzbl 0x13(%rsp),%eax
xor    0x3(%rbp,%r13,4),%al
mov    %al,0x3(%r15,%r13,4)
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <KeccakP400_AddBytes@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
mov    $0x1,%ecx
call   1040 <KeccakP400_AddBytes@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <keccakP400NRounds@plt>
add    $0x1,%r13
cmp    %r13d,%r12d
jne    1170 <Ket_WrapBlocks+0x40>
mov    0x14(%rsp),%eax
shl    $0x2,%eax
jmp    122f <Ket_WrapBlocks+0xff>
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 [4 x i8]
%11 = alloca [4 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 %98
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%21 = call i32 @KeccakP400_ExtractBytes(i8* %19, i8* %20, i32 0, i32 4)
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = getelementptr inbounds [4 x i8], [4 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 [4 x i8], [4 x i8]* %11, i64 0, i64 1
store i8 %28, i8* %29
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = load i8, i8* %31
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 2
store i8 %32, i8* %33
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i64 3
%36 = load i8, i8* %35
%37 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 3
store i8 %36, i8* %37
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %6
%40 = load i8, i8* %38
%41 = zext i8 %40 to i32
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = xor i32 %41, %44
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %7
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %7
store i8 %46, i8* %47
%49 = load i8*, i8** %6
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %6
%51 = load i8, i8* %49
%52 = zext i8 %51 to i32
%53 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 1
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = xor i32 %52, %55
%57 = trunc i32 %56 to i8
%58 = load i8*, i8** %7
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %7
store i8 %57, i8* %58
%60 = load i32, i32* %9
%61 = add i32 %60, 1
store i32 %61, i32* %9
%62 = load i32, i32* %9
%63 = add i32 %62, 1
store i32 %63, i32* %9
%64 = load i8*, i8** %6
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %6
%66 = load i8, i8* %64
%67 = zext i8 %66 to i32
%68 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 2
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = xor i32 %67, %70
%72 = trunc i32 %71 to i8
%73 = load i8*, i8** %7
%74 = getelementptr inbounds i8, i8* %73, i32 1
store i8* %74, i8** %7
store i8 %72, i8* %73
%75 = load i8*, i8** %6
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %6
%77 = load i8, i8* %75
%78 = zext i8 %77 to i32
%79 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 3
%80 = load i8, i8* %79
%81 = zext i8 %80 to i32
%82 = xor i32 %78, %81
%83 = trunc i32 %82 to i8
%84 = load i8*, i8** %7
%85 = getelementptr inbounds i8, i8* %84, i32 1
store i8* %85, i8** %7
store i8 %83, i8* %84
%86 = load i32, i32* %9
%87 = add i32 %86, 1
store i32 %87, i32* %9
%88 = load i32, i32* %9
%89 = add i32 %88, 1
store i32 %89, i32* %9
%90 = load i8*, i8** %5
%91 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%92 = call i32 @KeccakP400_AddBytes(i8* %90, i8* %91, i32 0, i32 4)
%93 = load i8*, i8** %5
%94 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
%95 = call i32 @KeccakP400_AddBytes(i8* %93, i8* %94, i32 4, i32 1)
%96 = load i8*, i8** %5
%97 = call i32 @keccakP400NRounds(i8* %96, i32 1)
br label %14
98: ; preds = %14
%99 = load i32, i32* %9
ret i32 %99
}

LLVM IR (-O2):
define i32 @Ket_WrapBlocks(i8* %0, i8* nocapture %1, i8* nocapture writeonly %2, i32 %3) {
%5 = alloca [4 x i8]
%6 = alloca [4 x i8]
%7 = alloca [1 x i8]
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [4 x i8], [4 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 %54, label %12
12: ; preds = %4
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
br label %19
19: ; preds = %12, %19
%20 = phi i32 [ %3, %12 ], [ %23, %19 ]
%21 = phi i8* [ %2, %12 ], [ %47, %19 ]
%22 = phi i8* [ %1, %12 ], [ %43, %19 ]
%23 = add i32 %20, -1
%24 = call i32 @KeccakP400_ExtractBytes(i8* %0, i8* %8, i32 0, i32 4)
%25 = load i8, i8* %22
store i8 %25, i8* %9
%26 = getelementptr inbounds i8, i8* %22, i64 1
%27 = load i8, i8* %26
store i8 %27, i8* %13
%28 = getelementptr inbounds i8, i8* %22, i64 2
%29 = load i8, i8* %28
store i8 %29, i8* %14
%30 = getelementptr inbounds i8, i8* %22, i64 3
%31 = load i8, i8* %30
store i8 %31, i8* %15
%32 = load i8, i8* %8
%33 = xor i8 %32, %25
%34 = getelementptr inbounds i8, i8* %21, i64 1
store i8 %33, i8* %21
%35 = load i8, i8* %26
%36 = load i8, i8* %16
%37 = xor i8 %36, %35
%38 = getelementptr inbounds i8, i8* %21, i64 2
store i8 %37, i8* %34
%39 = load i8, i8* %28
%40 = load i8, i8* %17
%41 = xor i8 %40, %39
%42 = getelementptr inbounds i8, i8* %21, i64 3
store i8 %41, i8* %38
%43 = getelementptr inbounds i8, i8* %22, i64 4
%44 = load i8, i8* %30
%45 = load i8, i8* %18
%46 = xor i8 %45, %44
%47 = getelementptr inbounds i8, i8* %21, i64 4
store i8 %46, i8* %42
%48 = call i32 @KeccakP400_AddBytes(i8* %0, i8* %9, i32 0, i32 4)
%49 = call i32 @KeccakP400_AddBytes(i8* %0, i8* %10, i32 4, i32 1)
%50 = call i32 @keccakP400NRounds(i8* %0, i32 1)
%51 = icmp eq i32 %23, 0
br i1 %51, label %52, label %19
52: ; preds = %19
%53 = shl i32 %3, 2
br label %54
54: ; preds = %52, %4
%55 = phi i32 [ 0, %4 ], [ %53, %52 ]
ret i32 %55
}