#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 */
char caesar_encrypt_char(int /*<<< orphan*/, int);
scalar_t__ isalpha(char const);
scalar_t__ isupper(char const);
scalar_t__ malloc(size_t);
size_t strlen(char const *);
int /*<<< orphan*/ tolower(char const);
char toupper(char);
char *caesar_encrypt(const char *plaintext, int key) {
  size_t plaintext_size = strlen(plaintext);
  char *ciphertext = (char *)malloc(plaintext_size + 1);
  char *ciphertext_start = ciphertext;
  while (*plaintext != '\0') {
    if (isalpha(*plaintext)) {
      *ciphertext = caesar_encrypt_char(tolower(*plaintext), key);
      if (isupper(*plaintext)) {
        *ciphertext = toupper(*ciphertext);
      }
    } else {
      *ciphertext = *plaintext;
    }
    ++plaintext;
    ++ciphertext;
  }
  *ciphertext = '\0';
  return ciphertext_start;
}


x86 assembly (clang, -O0):
<caesar_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1241 <caesar_encrypt+0xd1>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1080 <isalpha@plt>
cmp    $0x0,%rax
je     1218 <caesar_encrypt+0xa8>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1060 <tolower@plt>
mov    %eax,%edi
mov    -0xc(%rbp),%esi
call   1040 <caesar_encrypt_char@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1090 <isupper@plt>
cmp    $0x0,%rax
je     1213 <caesar_encrypt+0xa3>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
jmp    1224 <caesar_encrypt+0xb4>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a5 <caesar_encrypt+0x35>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<caesar_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    (%rbx),%al
mov    %r14,%rbp
jmp    11af <caesar_encrypt+0x3f>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %al,0x0(%rbp)
add    $0x1,%rbp
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11f3 <caesar_encrypt+0x83>
movsbl %al,%edi
call   1080 <isalpha@plt>
mov    %rax,%rcx
movzbl (%rbx),%eax
test   %rcx,%rcx
je     11a0 <caesar_encrypt+0x30>
movsbl %al,%edi
call   1060 <tolower@plt>
mov    %eax,%edi
mov    %r15d,%esi
call   1040 <caesar_encrypt_char@plt>
mov    %al,0x0(%rbp)
movsbl (%rbx),%edi
call   1090 <isupper@plt>
test   %rax,%rax
je     11a3 <caesar_encrypt+0x33>
movsbl 0x0(%rbp),%edi
call   1030 <toupper@plt>
jmp    11a0 <caesar_encrypt+0x30>
movb   $0x0,0x0(%rbp)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @caesar_encrypt(i8* nocapture %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add i64 %3, 1
%5 = tail call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %32, label %9
9: ; preds = %2, %27
%10 = phi i8 [ %30, %27 ], [ %7, %2 ]
%11 = phi i8* [ %28, %27 ], [ %0, %2 ]
%12 = phi i8* [ %29, %27 ], [ %6, %2 ]
%13 = tail call i64 @isalpha(i8 signext %10)
%14 = icmp eq i64 %13, 0
%15 = load i8, i8* %11
br i1 %14, label %25, label %16
16: ; preds = %9
%17 = tail call i32 @tolower(i8 signext %15)
%18 = tail call signext i8 @caesar_encrypt_char(i32 %17, i32 %1)
store i8 %18, i8* %12
%19 = load i8, i8* %11
%20 = tail call i64 @isupper(i8 signext %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %16
%23 = load i8, i8* %12
%24 = tail call signext i8 @toupper(i8 signext %23)
br label %25
25: ; preds = %9, %22
%26 = phi i8 [ %24, %22 ], [ %15, %9 ]
store i8 %26, i8* %12
br label %27
27: ; preds = %25, %16
%28 = getelementptr inbounds i8, i8* %11, i64 1
%29 = getelementptr inbounds i8, i8* %12, i64 1
%30 = load i8, i8* %28
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %9
32: ; preds = %27, %2
%33 = phi i8* [ %6, %2 ], [ %29, %27 ]
store i8 0, i8* %33
ret i8* %6
}