#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*/ isspace(char);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int toupper(char);
int pencrypt(const char *plain, const char *k) {
  int length = strlen(plain);
  int keylength = strlen(k);
  char cipher[length];
  char key[keylength];
  strncpy(cipher, plain, length + 1);
  strncpy(key, k, keylength + 1);
  int i, j;
  for (i = j = 0; i < length; i++, j++) {
    if (!isspace(cipher[i])) {
      char c =
          ((toupper(cipher[i]) - 65) + (toupper(key[(j % keylength)]) - 65));
      cipher[j] = (c < 0 ? c + 26 : c) % 26 + 65;
    } else
      j--;
  }
  cipher[j] = '\0';
  printf("%s\n", cipher);
  return 0;
}


x86 assembly (clang, -O0):
<pencrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12b4 <pencrypt+0x164>
mov    -0x50(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <isspace@plt>
cmp    $0x0,%eax
jne    128f <pencrypt+0x13f>
mov    -0x50(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <toupper@plt>
sub    $0x41,%eax
mov    %eax,-0x54(%rbp)
mov    -0x38(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    -0x48(%rbp),%rax
movslq %edx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <toupper@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
sub    $0x41,%ecx
add    %ecx,%eax
mov    %al,-0x39(%rbp)
movsbl -0x39(%rbp),%eax
cmp    $0x0,%eax
jge    126a <pencrypt+0x11a>
movsbl -0x39(%rbp),%eax
add    $0x1a,%eax
mov    %eax,-0x58(%rbp)
jmp    1271 <pencrypt+0x121>
movsbl -0x39(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    -0x50(%rbp),%rax
add    $0x41,%edx
movslq -0x38(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1298 <pencrypt+0x148>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    129d <pencrypt+0x14d>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11ed <pencrypt+0x9d>
mov    -0x50(%rbp),%rsi
movslq -0x38(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
lea    0xd39(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pencrypt>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rsi,-0x38(%rbp)
mov    %rdi,-0x30(%rbp)
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r13d,%r14d
mov    %rsp,%r12
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %ebx,%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0x1(%r13),%edx
mov    %r12,%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strncpy@plt>
mov    %rbx,-0x30(%rbp)
lea    0x1(%rbx),%edx
mov    %r15,-0x40(%rbp)
mov    %r15,%rdi
mov    -0x38(%rbp),%rsi
call   1030 <strncpy@plt>
xor    %ebx,%ebx
test   %r13d,%r13d
jle    1261 <pencrypt+0x111>
xor    %r15d,%r15d
jmp    11ef <pencrypt+0x9f>
nopl   0x0(%rax)
add    $0xffffffff,%ebx
add    $0x1,%r15
add    $0x1,%ebx
cmp    %r15,%r14
je     125e <pencrypt+0x10e>
movsbl (%r12,%r15,1),%edi
call   1070 <isspace@plt>
test   %eax,%eax
jne    11e0 <pencrypt+0x90>
movsbl (%r12,%r15,1),%edi
call   1040 <toupper@plt>
mov    %eax,%r13d
mov    %ebx,%eax
cltd
idivl  -0x30(%rbp)
movslq %edx,%rax
mov    -0x40(%rbp),%rcx
movsbl (%rcx,%rax,1),%edi
call   1040 <toupper@plt>
add    %r13d,%eax
shl    $0x18,%eax
add    $0x7e000000,%eax
mov    %eax,%ecx
sar    $0x18,%ecx
lea    0x1a(%rcx),%edx
test   %eax,%eax
cmovns %ecx,%edx
imul   $0x4ec5,%edx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
shr    $0x13,%eax
add    %ecx,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rcx,%rcx,4),%ecx
add    %eax,%ecx
sub    %ecx,%edx
add    $0x41,%dl
movslq %ebx,%rax
mov    %dl,(%r12,%rax,1)
jmp    11e3 <pencrypt+0x93>
movslq %ebx,%rbx
movb   $0x0,(%r12,%rbx,1)
lea    0xd93(%rip),%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define i32 @pencrypt(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %5
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %5
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %7
%20 = alloca i8, i64 %18
store i64 %18, i64* %8
%21 = load i32, i32* %6
%22 = zext i32 %21 to i64
%23 = alloca i8, i64 %22
store i64 %22, i64* %9
%24 = load i8*, i8** %3
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
%27 = call i32 @strncpy(i8* %20, i8* %24, i32 %26)
%28 = load i8*, i8** %4
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
%31 = call i32 @strncpy(i8* %23, i8* %28, i32 %30)
store i32 0, i32* %11
store i32 0, i32* %10
br label %32
32: ; preds = %82, %2
%33 = load i32, i32* %10
%34 = load i32, i32* %5
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %87
36: ; preds = %32
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %20, i64 %38
%40 = load i8, i8* %39
%41 = call i32 @isspace(i8 signext %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %78, label %43
43: ; preds = %36
%44 = load i32, i32* %10
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %20, i64 %45
%47 = load i8, i8* %46
%48 = call i32 @toupper(i8 signext %47)
%49 = sub nsw i32 %48, 65
%50 = load i32, i32* %11
%51 = load i32, i32* %6
%52 = srem i32 %50, %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %23, i64 %53
%55 = load i8, i8* %54
%56 = call i32 @toupper(i8 signext %55)
%57 = sub nsw i32 %56, 65
%58 = add nsw i32 %49, %57
%59 = trunc i32 %58 to i8
store i8 %59, i8* %12
%60 = load i8, i8* %12
%61 = sext i8 %60 to i32
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %43
%64 = load i8, i8* %12
%65 = sext i8 %64 to i32
%66 = add nsw i32 %65, 26
br label %70
67: ; preds = %43
%68 = load i8, i8* %12
%69 = sext i8 %68 to i32
br label %70
70: ; preds = %67, %63
%71 = phi i32 [ %66, %63 ], [ %69, %67 ]
%72 = srem i32 %71, 26
%73 = add nsw i32 %72, 65
%74 = trunc i32 %73 to i8
%75 = load i32, i32* %11
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %20, i64 %76
store i8 %74, i8* %77
br label %81
78: ; preds = %36
%79 = load i32, i32* %11
%80 = add nsw i32 %79, -1
store i32 %80, i32* %11
br label %81
81: ; preds = %78, %70
br label %82
82: ; preds = %81
%83 = load i32, i32* %10
%84 = add nsw i32 %83, 1
store i32 %84, i32* %10
%85 = load i32, i32* %11
%86 = add nsw i32 %85, 1
store i32 %86, i32* %11
br label %32
87: ; preds = %32
%88 = load i32, i32* %11
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %20, i64 %89
store i8 0, i8* %90
%91 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %20)
%92 = load i8*, i8** %7
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i32 @pencrypt(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = zext i32 %3 to i64
%6 = alloca i8, i64 %5
%7 = zext i32 %4 to i64
%8 = alloca i8, i64 %7
%9 = add nsw i32 %3, 1
%10 = call i32 @strncpy(i8* %6, i8* %0, i32 %9)
%11 = add nsw i32 %4, 1
%12 = call i32 @strncpy(i8* %8, i8* %1, i32 %11)
%13 = icmp sgt i32 %3, 0
br i1 %13, label %14, label %51
14: ; preds = %2, %44
%15 = phi i64 [ %46, %44 ], [ 0, %2 ]
%16 = phi i32 [ %47, %44 ], [ 0, %2 ]
%17 = getelementptr inbounds i8, i8* %6, i64 %15
%18 = load i8, i8* %17
%19 = call i32 @isspace(i8 signext %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %42
21: ; preds = %14
%22 = load i8, i8* %17
%23 = call i32 @toupper(i8 signext %22)
%24 = srem i32 %16, %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %8, i64 %25
%27 = load i8, i8* %26
%28 = call i32 @toupper(i8 signext %27)
%29 = add i32 %28, %23
%30 = shl i32 %29, 24
%31 = add i32 %30, 2113929216
%32 = ashr exact i32 %31, 24
%33 = icmp slt i32 %31, 0
%34 = add nsw i32 %32, 26
%35 = select i1 %33, i32 %34, i32 %32
%36 = trunc i32 %35 to i16
%37 = srem i16 %36, 26
%38 = trunc i16 %37 to i8
%39 = add nsw i8 %38, 65
%40 = sext i32 %16 to i64
%41 = getelementptr inbounds i8, i8* %6, i64 %40
store i8 %39, i8* %41
br label %44
42: ; preds = %14
%43 = add nsw i32 %16, -1
br label %44
44: ; preds = %21, %42
%45 = phi i32 [ %43, %42 ], [ %16, %21 ]
%46 = add nuw nsw i64 %15, 1
%47 = add nsw i32 %45, 1
%48 = icmp eq i64 %46, %5
br i1 %48, label %49, label %14
49: ; preds = %44
%50 = sext i32 %47 to i64
br label %51
51: ; preds = %49, %2
%52 = phi i64 [ 0, %2 ], [ %50, %49 ]
%53 = getelementptr inbounds i8, i8* %6, i64 %52
store i8 0, i8* %53
%54 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
ret i32 0
}