#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;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ memxor(void *, int *, int);
int /*<<< orphan*/ present_p(void *, int *);
int present_sbox_inv(int);
void present_generic_dec(void *buffer, uint8_t *ctx, uint8_t ksize_B,
                         void (*update)(uint8_t *, uint8_t)) {
  uint8_t j, tmp[8], k[ksize_B];
  uint8_t i;
  memcpy(k, ctx + ksize_B, ksize_B);
  memxor(buffer, k, 8);
  i = 31;
  do {
    present_p(tmp, buffer);
    present_p(buffer, tmp);
    j = 7;
    do {
      ((uint8_t *)buffer)[j] = present_sbox_inv(((uint8_t *)buffer)[j]);
    } while (j--);
    update(k, i);
    memxor(buffer, k, 8);
  } while (--i);
}


x86 assembly (clang, -O0):
<present_generic_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x70(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x70(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    $0x8,%edx
call   1030 <memxor@plt>
movl   $0x1f,-0x64(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <present_p@plt>
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <present_p@plt>
movl   $0x7,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <present_sbox_inv@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x0,%eax
jne    11cf <present_generic_dec+0x8f>
mov    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x64(%rbp),%esi
call   *%rax
mov    -0x70(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    $0x8,%edx
call   1030 <memxor@plt>
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jne    11ae <present_generic_dec+0x6e>
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<present_generic_dec>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %rdi,%rbx
mov    %rsp,-0x30(%rbp)
mov    %edx,%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
movslq %edx,%rdx
lea    (%rsi,%rdx,4),%rsi
mov    %r15,%rdi
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <memxor@plt>
mov    $0x1f,%r12d
lea    -0x50(%rbp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
call   1040 <present_p@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <present_p@plt>
mov    0x1c(%rbx),%edi
call   1060 <present_sbox_inv@plt>
mov    %eax,0x1c(%rbx)
mov    0x18(%rbx),%edi
call   1060 <present_sbox_inv@plt>
mov    %eax,0x18(%rbx)
mov    0x14(%rbx),%edi
call   1060 <present_sbox_inv@plt>
mov    %eax,0x14(%rbx)
mov    0x10(%rbx),%edi
call   1060 <present_sbox_inv@plt>
mov    %eax,0x10(%rbx)
mov    0xc(%rbx),%edi
call   1060 <present_sbox_inv@plt>
mov    %eax,0xc(%rbx)
mov    0x8(%rbx),%edi
call   1060 <present_sbox_inv@plt>
mov    %eax,0x8(%rbx)
mov    0x4(%rbx),%edi
call   1060 <present_sbox_inv@plt>
mov    %eax,0x4(%rbx)
mov    (%rbx),%edi
call   1060 <present_sbox_inv@plt>
mov    %eax,(%rbx)
mov    %r15,%rdi
mov    %r12d,%esi
call   *%r14
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <memxor@plt>
add    $0xffffffff,%r12d
jne    11a0 <present_generic_dec+0x60>
mov    -0x30(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @present_generic_dec(i8* %0, i32* %1, i32 %2, void (i32*, i32)* nocapture %3) {
%5 = alloca [8 x i32]
%6 = bitcast [8 x i32]* %5 to i8*
%7 = zext i32 %2 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i32, i64 %7
%10 = sext i32 %2 to i64
%11 = getelementptr inbounds i32, i32* %1, i64 %10
%12 = call i32 @memcpy(i32* %9, i32* %11, i32 %2)
%13 = call i32 @memxor(i8* %0, i32* %9, i32 8)
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%15 = bitcast i8* %0 to i32*
%16 = getelementptr inbounds i8, i8* %0, i64 28
%17 = bitcast i8* %16 to i32*
%18 = getelementptr inbounds i8, i8* %0, i64 24
%19 = bitcast i8* %18 to i32*
%20 = getelementptr inbounds i8, i8* %0, i64 20
%21 = bitcast i8* %20 to i32*
%22 = getelementptr inbounds i8, i8* %0, i64 16
%23 = bitcast i8* %22 to i32*
%24 = getelementptr inbounds i8, i8* %0, i64 12
%25 = bitcast i8* %24 to i32*
%26 = getelementptr inbounds i8, i8* %0, i64 8
%27 = bitcast i8* %26 to i32*
%28 = getelementptr inbounds i8, i8* %0, i64 4
%29 = bitcast i8* %28 to i32*
br label %30
30: ; preds = %30, %4
%31 = phi i32 [ 31, %4 ], [ %51, %30 ]
%32 = call i32 @present_p(i8* %6, i32* %15)
%33 = call i32 @present_p(i8* %0, i32* %14)
%34 = load i32, i32* %17
%35 = call i32 @present_sbox_inv(i32 %34)
store i32 %35, i32* %17
%36 = load i32, i32* %19
%37 = call i32 @present_sbox_inv(i32 %36)
store i32 %37, i32* %19
%38 = load i32, i32* %21
%39 = call i32 @present_sbox_inv(i32 %38)
store i32 %39, i32* %21
%40 = load i32, i32* %23
%41 = call i32 @present_sbox_inv(i32 %40)
store i32 %41, i32* %23
%42 = load i32, i32* %25
%43 = call i32 @present_sbox_inv(i32 %42)
store i32 %43, i32* %25
%44 = load i32, i32* %27
%45 = call i32 @present_sbox_inv(i32 %44)
store i32 %45, i32* %27
%46 = load i32, i32* %29
%47 = call i32 @present_sbox_inv(i32 %46)
store i32 %47, i32* %29
%48 = load i32, i32* %15
%49 = call i32 @present_sbox_inv(i32 %48)
store i32 %49, i32* %15
%50 = call i32 @memxor(i8* %0, i32* %9, i32 8)
%51 = add nsw i32 %31, -1
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %30
53: ; preds = %30
ret void
}