#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);
void Ket_UnwrapBlocks(void *state, const unsigned char *ciphertext,
                      unsigned char *plaintext, unsigned int nBlocks) {
  unsigned char tempBlock[(2 * 400 / 8 / 25)];
  unsigned char frameAndPaddingBits[1];
  frameAndPaddingBits[0] = 0x08 | 0x07;
  while (nBlocks-- != 0) {
    KeccakP400_ExtractBytes(state, tempBlock, 0, (2 * 400 / 8 / 25));
    tempBlock[0] = *(plaintext++) = *(ciphertext++) ^ tempBlock[0];
    tempBlock[1] = *(plaintext++) = *(ciphertext++) ^ tempBlock[1];
    tempBlock[2] = *(plaintext++) = *(ciphertext++) ^ tempBlock[2];
    tempBlock[3] = *(plaintext++) = *(ciphertext++) ^ tempBlock[3];
    KeccakP400_AddBytes(state, tempBlock, 0, (2 * 400 / 8 / 25));
    KeccakP400_AddBytes(state, frameAndPaddingBits, (2 * 400 / 8 / 25), 1);
    keccakP400NRounds(state, 1);
  }
}


x86 assembly (clang, -O0):
<Ket_UnwrapBlocks>:
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     1261 <Ket_UnwrapBlocks+0x131>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1050 <KeccakP400_ExtractBytes@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
movzbl -0x20(%rbp),%ecx
xor    %ecx,%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %al,(%rcx)
mov    %al,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
movzbl -0x1f(%rbp),%ecx
xor    %ecx,%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %al,(%rcx)
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    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %al,(%rcx)
mov    %al,-0x1e(%rbp)
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    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %al,(%rcx)
mov    %al,-0x1d(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <KeccakP400_AddBytes@plt>
mov    -0x8(%rbp),%rdi
lea    -0x21(%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    114b <Ket_UnwrapBlocks+0x1b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Ket_UnwrapBlocks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0xf,0x7(%rsp)
test   %ecx,%ecx
je     11ff <Ket_UnwrapBlocks+0xcf>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %ecx,%ebp
xor    %r13d,%r13d
lea    0x3(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1050 <KeccakP400_ExtractBytes@plt>
movzbl 0x3(%rsp),%eax
xor    (%r15,%r13,4),%al
mov    %al,(%r14,%r13,4)
mov    %al,0x3(%rsp)
movzbl 0x4(%rsp),%eax
xor    0x1(%r15,%r13,4),%al
mov    %al,0x1(%r14,%r13,4)
mov    %al,0x4(%rsp)
movzbl 0x5(%rsp),%eax
xor    0x2(%r15,%r13,4),%al
mov    %al,0x2(%r14,%r13,4)
mov    %al,0x5(%rsp)
movzbl 0x6(%rsp),%eax
xor    0x3(%r15,%r13,4),%al
mov    %al,0x3(%r14,%r13,4)
mov    %al,0x6(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1040 <KeccakP400_AddBytes@plt>
mov    %rbx,%rdi
lea    0x7(%rsp),%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,%ebp
jne    1160 <Ket_UnwrapBlocks+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @Ket_UnwrapBlocks(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [4 x i8]
%10 = alloca [1 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 [1 x i8], [1 x i8]* %10, i64 0, i64 0
store i8 15, i8* %11
br label %12
12: ; preds = %16, %4
%13 = load i32, i32* %8
%14 = add i32 %13, -1
store i32 %14, i32* %8
%15 = icmp ne i32 %13, 0
br i1 %15, label %16, label %76
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%19 = call i32 @KeccakP400_ExtractBytes(i8* %17, i8* %18, i32 0, i32 4)
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %6
%22 = load i8, i8* %20
%23 = zext i8 %22 to i32
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = xor i32 %23, %26
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %7
store i8 %28, i8* %29
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
store i8 %28, i8* %31
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %6
%34 = load i8, i8* %32
%35 = zext i8 %34 to i32
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 1
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = xor i32 %35, %38
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %7
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %7
store i8 %40, i8* %41
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 1
store i8 %40, i8* %43
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %6
%46 = load i8, i8* %44
%47 = zext i8 %46 to i32
%48 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 2
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = xor i32 %47, %50
%52 = trunc i32 %51 to i8
%53 = load i8*, i8** %7
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %7
store i8 %52, i8* %53
%55 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 2
store i8 %52, i8* %55
%56 = load i8*, i8** %6
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %6
%58 = load i8, i8* %56
%59 = zext i8 %58 to i32
%60 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = xor i32 %59, %62
%64 = trunc i32 %63 to i8
%65 = load i8*, i8** %7
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %7
store i8 %64, i8* %65
%67 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
store i8 %64, i8* %67
%68 = load i8*, i8** %5
%69 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%70 = call i32 @KeccakP400_AddBytes(i8* %68, i8* %69, i32 0, i32 4)
%71 = load i8*, i8** %5
%72 = getelementptr inbounds [1 x i8], [1 x i8]* %10, i64 0, i64 0
%73 = call i32 @KeccakP400_AddBytes(i8* %71, i8* %72, i32 4, i32 1)
%74 = load i8*, i8** %5
%75 = call i32 @keccakP400NRounds(i8* %74, i32 1)
br label %12
76: ; preds = %12
ret void
}

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