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


x86 assembly (clang, -O0):
<simplesub_encipher>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11db <simplesub_encipher+0xab>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%eax
jne    1198 <simplesub_encipher+0x68>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11c8 <simplesub_encipher+0x98>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
sub    $0x61,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11cd <simplesub_encipher+0x9d>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1157 <simplesub_encipher+0x27>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simplesub_encipher>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    119b <simplesub_encipher+0x6b>
mov    %eax,%r12d
xor    %ebx,%ebx
jmp    1171 <simplesub_encipher+0x41>
nopw   0x0(%rax,%rax,1)
movzbl 0x0(%rbp),%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
je     119e <simplesub_encipher+0x6e>
lea    (%rbx,%r13,1),%rbp
movsbl 0x0(%r13,%rbx,1),%edi
call   1050 <isalpha@plt>
test   %eax,%eax
je     1160 <simplesub_encipher+0x30>
movsbl 0x0(%rbp),%edi
call   1040 <tolower@plt>
movsbq %al,%rax
lea    (%rax,%r15,1),%rbp
add    $0xffffffffffffff9f,%rbp
jmp    1160 <simplesub_encipher+0x30>
xor    %r12d,%r12d
movb   $0x0,(%r14,%r12,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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