#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);
int strlen(char *);
char tolower(char);
void prepare_for_playfair(char *originaltext, char *plaintext) {
  int i, j, length = strlen(originaltext);
  for (i = 0, j = 0; i < length; i++, j++) {
    while (!isalpha(originaltext[i]))
      i++;
    if (i >= length)
      break;
    plaintext[j] = tolower(originaltext[i]);
  }
  if (j % 2 == 0)
    plaintext[j] = '\0';
  else {
    plaintext[j] = 'x';
    plaintext[j + 1] = '\0';
  }
}


x86 assembly (clang, -O0):
<prepare_for_playfair>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e5 <prepare_for_playfair+0xb5>
jmp    116b <prepare_for_playfair+0x3b>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1191 <prepare_for_playfair+0x61>
jmp    119f <prepare_for_playfair+0x6f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116b <prepare_for_playfair+0x3b>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     11b0 <prepare_for_playfair+0x80>
jmp    11e5 <prepare_for_playfair+0xb5>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115a <prepare_for_playfair+0x2a>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    120a <prepare_for_playfair+0xda>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1227 <prepare_for_playfair+0xf7>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x78,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepare_for_playfair>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
xor    %ebp,%ebp
test   %eax,%eax
jle    11b5 <prepare_for_playfair+0x85>
mov    %eax,%r12d
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %ebp,%rbx
add    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1050 <isalpha@plt>
add    $0x1,%rbx
add    $0x1,%ebp
test   %eax,%eax
je     1170 <prepare_for_playfair+0x40>
lea    -0x1(%rbp),%eax
cmp    %eax,%r12d
jle    11a1 <prepare_for_playfair+0x71>
movsbl -0x1(%rbx),%edi
call   1040 <tolower@plt>
mov    %al,(%r14,%r13,1)
add    $0x1,%r13
cmp    %r12d,%ebp
jl     1160 <prepare_for_playfair+0x30>
test   $0x1,%r13b
je     11b8 <prepare_for_playfair+0x88>
mov    %r13d,%eax
movb   $0x78,(%r14,%rax,1)
add    $0x1,%r13
jmp    11b8 <prepare_for_playfair+0x88>
xor    %r13d,%r13d
mov    %r13d,%eax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @prepare_for_playfair(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
store i32 0, i32* %5
store i32 0, i32* %6
br label %10
10: ; preds = %43, %2
%11 = load i32, i32* %5
%12 = load i32, i32* %7
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %48
14: ; preds = %10
br label %15
15: ; preds = %24, %14
%16 = load i8*, i8** %3
%17 = load i32, i32* %5
%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
%23 = xor i1 %22, true
br i1 %23, label %24, label %27
24: ; preds = %15
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %15
27: ; preds = %15
%28 = load i32, i32* %5
%29 = load i32, i32* %7
%30 = icmp sge i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %27
br label %48
32: ; preds = %27
%33 = load i8*, i8** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = call signext i8 @tolower(i8 signext %37)
%39 = load i8*, i8** %4
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
br label %43
43: ; preds = %32
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %10
48: ; preds = %31, %10
%49 = load i32, i32* %6
%50 = srem i32 %49, 2
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = load i8*, i8** %4
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 0, i8* %56
br label %67
57: ; preds = %48
%58 = load i8*, i8** %4
%59 = load i32, i32* %6
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 120, i8* %61
%62 = load i8*, i8** %4
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
store i8 0, i8* %66
br label %67
67: ; preds = %57, %52
ret void
}

LLVM IR (-O2):
define void @prepare_for_playfair(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %35
5: ; preds = %2, %19
%6 = phi i64 [ %25, %19 ], [ 0, %2 ]
%7 = phi i32 [ %24, %19 ], [ 0, %2 ]
%8 = sext i32 %7 to i64
br label %9
9: ; preds = %9, %5
%10 = phi i64 [ %15, %9 ], [ %8, %5 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call i32 @isalpha(i8 signext %12)
%14 = icmp eq i32 %13, 0
%15 = add i64 %10, 1
br i1 %14, label %9, label %16
16: ; preds = %9
%17 = trunc i64 %10 to i32
%18 = icmp sgt i32 %3, %17
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %0, i64 %10
%21 = load i8, i8* %20
%22 = tail call signext i8 @tolower(i8 signext %21)
%23 = getelementptr inbounds i8, i8* %1, i64 %6
store i8 %22, i8* %23
%24 = add nsw i32 %17, 1
%25 = add nuw i64 %6, 1
%26 = icmp slt i32 %24, %3
br i1 %26, label %5, label %27
27: ; preds = %19, %16
%28 = phi i64 [ %25, %19 ], [ %6, %16 ]
%29 = and i64 %28, 1
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = and i64 %28, 4294967295
%33 = getelementptr inbounds i8, i8* %1, i64 %32
store i8 120, i8* %33
%34 = add i64 %28, 1
br label %35
35: ; preds = %27, %2, %31
%36 = phi i64 [ %34, %31 ], [ %28, %27 ], [ 0, %2 ]
%37 = and i64 %36, 4294967295
%38 = getelementptr inbounds i8, i8* %1, i64 %37
store i8 0, i8* %38
ret void
}