#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*/ isalpha(char const);
int strlen(char const *);
char tolower(char const);
void caesar_decipher(int key, const char *ciphertext, char *plaintext) {
  int i, length = strlen(ciphertext);
  for (i = 0; i < length; i++) {
    if (!isalpha(ciphertext[i])) {
      plaintext[i] = ciphertext[i];
    } else {
      plaintext[i] = (tolower(ciphertext[i]) - 'a' - key + 26) % 26 + 'a';
    }
  }
  plaintext[i] = '\0';
}


x86 assembly (clang, -O0):
<caesar_decipher>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11dd <caesar_decipher+0xad>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%eax
jne    1197 <caesar_decipher+0x67>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11ca <caesar_decipher+0x9a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
sub    $0x61,%eax
sub    -0x4(%rbp),%eax
add    $0x1a,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11cf <caesar_decipher+0x9f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <caesar_decipher+0x26>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<caesar_decipher>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11b2 <caesar_decipher+0x82>
mov    $0xffffffb9,%r15d
sub    %ebp,%r15d
mov    %eax,%r12d
xor    %ebp,%ebp
jmp    116d <caesar_decipher+0x3d>
nopl   0x0(%rax)
mov    %cl,(%r14,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r12
je     11b5 <caesar_decipher+0x85>
movsbl (%rbx,%rbp,1),%edi
call   1050 <isalpha@plt>
movzbl (%rbx,%rbp,1),%ecx
test   %eax,%eax
je     1160 <caesar_decipher+0x30>
movsbl %cl,%edi
call   1040 <tolower@plt>
movsbl %al,%eax
add    %r15d,%eax
movslq %eax,%rcx
imul   $0x4ec4ec4f,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
shr    $0x23,%rax
add    %edx,%eax
lea    (%rax,%rax,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %eax,%edx
sub    %edx,%ecx
add    $0x61,%cl
jmp    1160 <caesar_decipher+0x30>
xor    %r12d,%r12d
movb   $0x0,(%r14,%r12,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @caesar_decipher(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
store i32 0, i32* %7
br label %11
11: ; preds = %53, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %56
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = call i32 @isalpha(i8 signext %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %33, label %23
23: ; preds = %15
%24 = load i8*, i8** %5
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = load i8*, i8** %6
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 %28, i8* %32
br label %52
33: ; preds = %15
%34 = load i8*, i8** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = call signext i8 @tolower(i8 signext %38)
%40 = sext i8 %39 to i32
%41 = sub nsw i32 %40, 97
%42 = load i32, i32* %4
%43 = sub nsw i32 %41, %42
%44 = add nsw i32 %43, 26
%45 = srem i32 %44, 26
%46 = add nsw i32 %45, 97
%47 = trunc i32 %46 to i8
%48 = load i8*, i8** %6
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 %47, i8* %51
br label %52
52: ; preds = %33, %23
br label %53
53: ; preds = %52
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %11
56: ; preds = %11
%57 = load i8*, i8** %6
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 0, i8* %60
ret void
}

LLVM IR (-O2):
define void @caesar_decipher(i32 %0, i8* %1, i8* nocapture writeonly %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %30
6: ; preds = %3
%7 = sub i32 -71, %0
%8 = zext i32 %4 to i64
br label %9
9: ; preds = %6, %23
%10 = phi i64 [ 0, %6 ], [ %26, %23 ]
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = load i8, i8* %11
%13 = tail call i32 @isalpha(i8 signext %12)
%14 = icmp eq i32 %13, 0
%15 = load i8, i8* %11
br i1 %14, label %23, label %16
16: ; preds = %9
%17 = tail call signext i8 @tolower(i8 signext %15)
%18 = sext i8 %17 to i32
%19 = add i32 %7, %18
%20 = srem i32 %19, 26
%21 = trunc i32 %20 to i8
%22 = add nsw i8 %21, 97
br label %23
23: ; preds = %9, %16
%24 = phi i8 [ %22, %16 ], [ %15, %9 ]
%25 = getelementptr inbounds i8, i8* %2, i64 %10
store i8 %24, i8* %25
%26 = add nuw nsw i64 %10, 1
%27 = icmp eq i64 %26, %8
br i1 %27, label %28, label %9
28: ; preds = %23
%29 = zext i32 %4 to i64
br label %30
30: ; preds = %3, %28
%31 = phi i64 [ %29, %28 ], [ 0, %3 ]
%32 = getelementptr inbounds i8, i8* %2, i64 %31
store i8 0, i8* %32
ret void
}