#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 */
typedef int uint8_t;
typedef int uint64_t;
typedef scalar_t__ int8_t;

/* Variables and functions */
void Simon_Decrypt_128(const uint8_t round_limit, const uint8_t *key_schedule,
                       const uint8_t *ciphertext, uint8_t *plaintext) {
  const uint8_t word_size = 64;
  uint64_t *x_word = (uint64_t *)plaintext;
  uint64_t *y_word = ((uint64_t *)plaintext) + 1;
  uint64_t *round_key_ptr = (uint64_t *)key_schedule;
  *x_word = *(uint64_t *)ciphertext;
  *y_word = *(((uint64_t *)ciphertext) + 1);
  for (int8_t i = round_limit - 1; i >= 0; i--) {
    uint64_t temp = ((((*x_word) << 1) | ((*x_word) >> (word_size - 1))) &
                     (((*x_word) << 8) | ((*x_word) >> (word_size - 8)))) ^
                    *y_word ^
                    (((*x_word) << 2) | ((*x_word) >> (word_size - 2)));
    *y_word = *x_word;
    *x_word = temp ^ *(round_key_ptr + i);
  }
}


x86 assembly (clang, -O0):
<Simon_Decrypt_128>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x40,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jl     11fa <Simon_Decrypt_128+0xfa>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
shl    $0x1,%eax
mov    -0x30(%rbp),%rcx
mov    (%rcx),%edx
mov    $0x3f,%ecx
sar    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    -0x30(%rbp),%rcx
mov    (%rcx),%ecx
shl    $0x8,%ecx
mov    %ecx,-0x54(%rbp)
mov    -0x30(%rbp),%rcx
mov    (%rcx),%edx
mov    $0x38,%ecx
sar    %cl,%edx
mov    -0x54(%rbp),%ecx
or     %edx,%ecx
and    %ecx,%eax
mov    -0x38(%rbp),%rcx
xor    (%rcx),%eax
mov    -0x30(%rbp),%rcx
mov    (%rcx),%ecx
shl    $0x2,%ecx
mov    %ecx,-0x50(%rbp)
mov    -0x30(%rbp),%rcx
mov    (%rcx),%edx
mov    $0x3e,%ecx
sar    %cl,%edx
mov    -0x50(%rbp),%ecx
or     %edx,%ecx
xor    %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4c(%rbp),%ecx
mov    -0x40(%rbp),%rax
mov    -0x48(%rbp),%rdx
xor    (%rax,%rdx,4),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x48(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x48(%rbp)
jmp    115b <Simon_Decrypt_128+0x5b>
pop    %rbp
ret

x86 assembly (clang, -O2):
<Simon_Decrypt_128>:
mov    (%rdx),%eax
mov    %eax,(%rcx)
test   %edi,%edi
jg     110b <Simon_Decrypt_128+0xb>
mov    0x4(%rdx),%eax
mov    %eax,0x4(%rcx)
ret

LLVM IR (-O0):
define void @Simon_Decrypt_128(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i64
%14 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 64, i32* %9
%15 = load i32*, i32** %8
store i32* %15, i32** %10
%16 = load i32*, i32** %8
%17 = getelementptr inbounds i32, i32* %16, i64 1
store i32* %17, i32** %11
%18 = load i32*, i32** %6
store i32* %18, i32** %12
%19 = load i32*, i32** %7
%20 = load i32, i32* %19
%21 = load i32*, i32** %10
store i32 %20, i32* %21
%22 = load i32*, i32** %7
%23 = getelementptr inbounds i32, i32* %22, i64 1
%24 = load i32, i32* %23
%25 = load i32*, i32** %11
store i32 %24, i32* %25
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
store i64 %28, i64* %13
br label %29
29: ; preds = %69, %4
%30 = load i64, i64* %13
%31 = icmp sge i64 %30, 0
br i1 %31, label %32, label %72
32: ; preds = %29
%33 = load i32*, i32** %10
%34 = load i32, i32* %33
%35 = shl i32 %34, 1
%36 = load i32*, i32** %10
%37 = load i32, i32* %36
%38 = ashr i32 %37, 63
%39 = or i32 %35, %38
%40 = load i32*, i32** %10
%41 = load i32, i32* %40
%42 = shl i32 %41, 8
%43 = load i32*, i32** %10
%44 = load i32, i32* %43
%45 = ashr i32 %44, 56
%46 = or i32 %42, %45
%47 = and i32 %39, %46
%48 = load i32*, i32** %11
%49 = load i32, i32* %48
%50 = xor i32 %47, %49
%51 = load i32*, i32** %10
%52 = load i32, i32* %51
%53 = shl i32 %52, 2
%54 = load i32*, i32** %10
%55 = load i32, i32* %54
%56 = ashr i32 %55, 62
%57 = or i32 %53, %56
%58 = xor i32 %50, %57
store i32 %58, i32* %14
%59 = load i32*, i32** %10
%60 = load i32, i32* %59
%61 = load i32*, i32** %11
store i32 %60, i32* %61
%62 = load i32, i32* %14
%63 = load i32*, i32** %12
%64 = load i64, i64* %13
%65 = getelementptr inbounds i32, i32* %63, i64 %64
%66 = load i32, i32* %65
%67 = xor i32 %62, %66
%68 = load i32*, i32** %10
store i32 %67, i32* %68
br label %69
69: ; preds = %32
%70 = load i64, i64* %13
%71 = add nsw i64 %70, -1
store i64 %71, i64* %13
br label %29
72: ; preds = %29
ret void
}

LLVM IR (-O2):
define void @Simon_Decrypt_128(i32 %0, i32* nocapture readnone %1, i32* nocapture %2, i32* nocapture %3) {
%5 = load i32, i32* %2
store i32 %5, i32* %3
%6 = getelementptr inbounds i32, i32* %2, i64 1
%7 = load i32, i32* %6
%8 = icmp sgt i32 %0, 0
%9 = select i1 %8, i32 %5, i32 %7
%10 = getelementptr inbounds i32, i32* %3, i64 1
store i32 %9, i32* %10
ret void
}