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


x86 assembly (clang, -O0):
<caesar_encipher>:
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    11d7 <caesar_encipher+0xa7>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%eax
jne    1197 <caesar_encipher+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    11c4 <caesar_encipher+0x94>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
add    -0x4(%rbp),%eax
sub    $0x61,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11c9 <caesar_encipher+0x99>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <caesar_encipher+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_encipher>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11af <caesar_encipher+0x7f>
add    $0xffffff9f,%r15d
mov    %eax,%r12d
xor    %ebp,%ebp
jmp    116d <caesar_encipher+0x3d>
nopl   0x0(%rax,%rax,1)
mov    %cl,(%r14,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r12
je     11b2 <caesar_encipher+0x82>
movsbl (%rbx,%rbp,1),%edi
call   1050 <isalpha@plt>
movzbl (%rbx,%rbp,1),%ecx
test   %eax,%eax
je     1160 <caesar_encipher+0x30>
movsbl %cl,%edi
call   1040 <tolower@plt>
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_encipher+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_encipher(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 = %51, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %54
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 %50
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 i32 @tolower(i8 signext %38)
%40 = load i32, i32* %4
%41 = add nsw i32 %39, %40
%42 = sub nsw i32 %41, 97
%43 = srem i32 %42, 26
%44 = add nsw i32 %43, 97
%45 = trunc i32 %44 to i8
%46 = load i8*, i8** %6
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 %45, i8* %49
br label %50
50: ; preds = %33, %23
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %11
54: ; preds = %11
%55 = load i8*, i8** %6
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 0, i8* %58
ret void
}

LLVM IR (-O2):
define void @caesar_encipher(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 %29
6: ; preds = %3
%7 = add i32 %0, -97
%8 = zext i32 %4 to i64
br label %9
9: ; preds = %6, %22
%10 = phi i64 [ 0, %6 ], [ %25, %22 ]
%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 %22, label %16
16: ; preds = %9
%17 = tail call i32 @tolower(i8 signext %15)
%18 = add i32 %7, %17
%19 = srem i32 %18, 26
%20 = trunc i32 %19 to i8
%21 = add nsw i8 %20, 97
br label %22
22: ; preds = %9, %16
%23 = phi i8 [ %21, %16 ], [ %15, %9 ]
%24 = getelementptr inbounds i8, i8* %2, i64 %10
store i8 %23, i8* %24
%25 = add nuw nsw i64 %10, 1
%26 = icmp eq i64 %25, %8
br i1 %26, label %27, label %9
27: ; preds = %22
%28 = zext i32 %4 to i64
br label %29
29: ; preds = %3, %27
%30 = phi i64 [ %28, %27 ], [ 0, %3 ]
%31 = getelementptr inbounds i8, i8* %2, i64 %30
store i8 0, i8* %31
ret void
}