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


x86 assembly (clang, -O0):
<vigenere_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     127d <vigenere_encrypt+0x10d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1070 <isalpha@plt>
cmp    $0x0,%rax
je     1254 <vigenere_encrypt+0xe4>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <tolower@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <tolower@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
call   1090 <vigenere_encrypt_char@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1080 <isupper@plt>
cmp    $0x0,%rax
je     122b <vigenere_encrypt+0xbb>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    124f <vigenere_encrypt+0xdf>
mov    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1260 <vigenere_encrypt+0xf0>
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    11ae <vigenere_encrypt+0x3e>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vigenere_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    (%rbx),%al
test   %al,%al
je     120d <vigenere_encrypt+0x9d>
mov    %r14,%r13
mov    %r15,%rbp
jmp    11b3 <vigenere_encrypt+0x43>
mov    %cl,0x0(%rbp)
add    $0x1,%rbp
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1210 <vigenere_encrypt+0xa0>
movsbl %al,%edi
call   1070 <isalpha@plt>
movzbl (%rbx),%ecx
test   %rax,%rax
je     11a0 <vigenere_encrypt+0x30>
movsbl %cl,%edi
call   1050 <tolower@plt>
mov    %eax,%r12d
movsbl 0x0(%r13),%edi
call   1050 <tolower@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1090 <vigenere_encrypt_char@plt>
mov    %al,0x0(%rbp)
movsbl (%rbx),%edi
call   1080 <isupper@plt>
test   %rax,%rax
je     11fe <vigenere_encrypt+0x8e>
movsbl 0x0(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,0x0(%rbp)
cmpb   $0x0,0x1(%r13)
lea    0x1(%r13),%r13
cmove  %r14,%r13
jmp    11a3 <vigenere_encrypt+0x33>
mov    %r15,%rbp
movb   $0x0,0x0(%rbp)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @vigenere_encrypt(i8* nocapture %0, i8* nocapture %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 %40, label %9
9: ; preds = %2, %34
%10 = phi i8 [ %38, %34 ], [ %7, %2 ]
%11 = phi i8* [ %36, %34 ], [ %0, %2 ]
%12 = phi i8* [ %35, %34 ], [ %1, %2 ]
%13 = phi i8* [ %37, %34 ], [ %6, %2 ]
%14 = tail call i64 @isalpha(i8 signext %10)
%15 = icmp eq i64 %14, 0
%16 = load i8, i8* %11
br i1 %15, label %33, label %17
17: ; preds = %9
%18 = tail call i32 @tolower(i8 signext %16)
%19 = load i8, i8* %12
%20 = tail call i32 @tolower(i8 signext %19)
%21 = tail call signext i8 @vigenere_encrypt_char(i32 %18, i32 %20)
store i8 %21, i8* %13
%22 = load i8, i8* %11
%23 = tail call i64 @isupper(i8 signext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %17
%26 = load i8, i8* %13
%27 = tail call signext i8 @toupper(i8 signext %26)
store i8 %27, i8* %13
br label %28
28: ; preds = %25, %17
%29 = getelementptr inbounds i8, i8* %12, i64 1
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
%32 = select i1 %31, i8* %1, i8* %29
br label %34
33: ; preds = %9
store i8 %16, i8* %13
br label %34
34: ; preds = %28, %33
%35 = phi i8* [ %12, %33 ], [ %32, %28 ]
%36 = getelementptr inbounds i8, i8* %11, i64 1
%37 = getelementptr inbounds i8, i8* %13, i64 1
%38 = load i8, i8* %36
%39 = icmp eq i8 %38, 0
br i1 %39, label %40, label %9
40: ; preds = %34, %2
%41 = phi i8* [ %6, %2 ], [ %37, %34 ]
store i8 0, i8* %41
ret i8* %6
}