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

/* Variables and functions */
int computeDecryptionRound(int, int, int);
int finalPermutation(int);
int generateCD(int);
int generatePerRoundKey(int);
int initialPermutation(int);
int rotateCD(int, int);
uint64_t DESDecrypt(uint64_t input, uint64_t key) {
  input = initialPermutation(input);
  input = (input >> 32) | (input << 32);
  uint64_t keys[16];
  uint64_t CD = generateCD(key);
  for (int i = 0; i < 16; i++) {
    CD = rotateCD(i, CD);
    keys[i] = generatePerRoundKey(CD);
  }
  for (int round_num = 15; round_num >= 0; round_num--) {
    input = computeDecryptionRound(round_num, input, keys[round_num]);
  }
  return finalPermutation(input);
}


x86 assembly (clang, -O0):
<DESDecrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <initialPermutation@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    -0x4(%rbp),%edx
mov    $0x20,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <generateCD@plt>
mov    %eax,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
cmpl   $0x10,-0x58(%rbp)
jge    11de <DESDecrypt+0x7e>
mov    -0x58(%rbp),%edi
mov    -0x54(%rbp),%esi
call   1080 <rotateCD@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
call   1030 <generatePerRoundKey@plt>
mov    %eax,%ecx
movslq -0x58(%rbp),%rax
mov    %ecx,-0x50(%rbp,%rax,4)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11a6 <DESDecrypt+0x46>
movl   $0xf,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jl     1213 <DESDecrypt+0xb3>
mov    -0x5c(%rbp),%edi
mov    -0x4(%rbp),%esi
movslq -0x5c(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%edx
call   1040 <computeDecryptionRound@plt>
mov    %eax,-0x4(%rbp)
mov    -0x5c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x5c(%rbp)
jmp    11e5 <DESDecrypt+0x85>
mov    -0x4(%rbp),%edi
call   1070 <finalPermutation@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DESDecrypt>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
call   1040 <initialPermutation@plt>
mov    %ebx,%edi
call   1050 <generateCD@plt>
mov    %eax,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %ebp,%esi
call   1060 <rotateCD@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <generatePerRoundKey@plt>
add    $0x1,%ebx
jmp    1160 <DESDecrypt+0x20>

LLVM IR (-O0):
define i32 @DESDecrypt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [16 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %3
%10 = call i32 @initialPermutation(i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = ashr i32 %11, 32
%13 = load i32, i32* %3
%14 = shl i32 %13, 32
%15 = or i32 %12, %14
store i32 %15, i32* %3
%16 = load i32, i32* %4
%17 = call i32 @generateCD(i32 %16)
store i32 %17, i32* %6
store i32 0, i32* %7
br label %18
18: ; preds = %30, %2
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 16
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = call i32 @rotateCD(i32 %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = call i32 @generatePerRoundKey(i32 %25)
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 %28
store i32 %26, i32* %29
br label %30
30: ; preds = %21
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %18
33: ; preds = %18
store i32 15, i32* %8
br label %34
34: ; preds = %45, %33
%35 = load i32, i32* %8
%36 = icmp sge i32 %35, 0
br i1 %36, label %37, label %48
37: ; preds = %34
%38 = load i32, i32* %8
%39 = load i32, i32* %3
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = call i32 @computeDecryptionRound(i32 %38, i32 %39, i32 %43)
store i32 %44, i32* %3
br label %45
45: ; preds = %37
%46 = load i32, i32* %8
%47 = add nsw i32 %46, -1
store i32 %47, i32* %8
br label %34
48: ; preds = %34
%49 = load i32, i32* %3
%50 = call i32 @finalPermutation(i32 %49)
ret i32 %50
}

LLVM IR (-O2):
define i32 @DESDecrypt(i32 %0, i32 %1) {
%3 = tail call i32 @initialPermutation(i32 %0)
%4 = tail call i32 @generateCD(i32 %1)
br label %5
5: ; preds = %5, %2
%6 = phi i32 [ 0, %2 ], [ %10, %5 ]
%7 = phi i32 [ %4, %2 ], [ %8, %5 ]
%8 = tail call i32 @rotateCD(i32 %6, i32 %7)
%9 = tail call i32 @generatePerRoundKey(i32 %8)
%10 = add nuw nsw i32 %6, 1
%11 = icmp ult i32 %6, 15
br label %5
}