#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 */
unsigned int strlen(char *);
int /*<<< orphan*/ writeError(int, char *, char *);
void pcaEncrypt(char *plaintext, char *ciphertext, int key, int offset) {
  unsigned int i;
  writeError(10, "pcaEncrypt [plaintext]: %s", plaintext);
  if (strlen(plaintext) > 0) {
    ciphertext[0] = plaintext[0] ^ key;
    for (i = 1; i < strlen(plaintext); i++)
      ciphertext[i] = ciphertext[i - 1] ^ plaintext[i] ^ (i - offset);
  }
  writeError(10, "pcaEncrypt [ciphertext]: %s", ciphertext);
}


x86 assembly (clang, -O0):
<pcaEncrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdx
mov    $0xa,%edi
lea    0xeba(%rip),%rsi
call   1040 <writeError@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jbe    11d6 <pcaEncrypt+0xb6>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
xor    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jae    11d1 <pcaEncrypt+0xb1>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x8(%rbp),%rcx
mov    -0x1c(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
xor    %ecx,%eax
mov    -0x1c(%rbp),%ecx
sub    -0x18(%rbp),%ecx
xor    %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1176 <pcaEncrypt+0x56>
jmp    11d6 <pcaEncrypt+0xb6>
mov    -0x10(%rbp),%rdx
mov    $0xa,%edi
lea    0xe35(%rip),%rsi
call   1040 <writeError@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pcaEncrypt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xec7(%rip),%rsi
mov    $0xa,%edi
mov    %rbx,%rdx
call   1040 <writeError@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11a3 <pcaEncrypt+0x83>
xor    (%rbx),%bpl
mov    %bpl,(%r14)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jb     11a3 <pcaEncrypt+0x83>
neg    %r15b
movzbl %r15b,%r15d
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r15,%rbp,1),%eax
xor    -0x1(%r14,%rbp,1),%al
xor    (%rbx,%rbp,1),%al
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbp
jb     1180 <pcaEncrypt+0x60>
lea    0xe71(%rip),%rsi
mov    $0xa,%edi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <writeError@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"pcaEncrypt [plaintext]: %s\00"
@.str.1 = [28 x i8] c"pcaEncrypt [ciphertext]: %s\00"
define void @pcaEncrypt(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i8*, i8** %5
%11 = call i32 @writeError(i32 10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = icmp ugt i32 %13, 0
br i1 %14, label %15, label %58
15: ; preds = %4
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = load i32, i32* %7
%21 = xor i32 %19, %20
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 %22, i8* %24
store i32 1, i32* %9
br label %25
25: ; preds = %54, %15
%26 = load i32, i32* %9
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
%29 = icmp ult i32 %26, %28
br i1 %29, label %30, label %57
30: ; preds = %25
%31 = load i8*, i8** %6
%32 = load i32, i32* %9
%33 = sub i32 %32, 1
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = load i8*, i8** %5
%39 = load i32, i32* %9
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = xor i32 %37, %43
%45 = load i32, i32* %9
%46 = load i32, i32* %8
%47 = sub i32 %45, %46
%48 = xor i32 %44, %47
%49 = trunc i32 %48 to i8
%50 = load i8*, i8** %6
%51 = load i32, i32* %9
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 %49, i8* %53
br label %54
54: ; preds = %30
%55 = load i32, i32* %9
%56 = add i32 %55, 1
store i32 %56, i32* %9
br label %25
57: ; preds = %25
br label %58
58: ; preds = %57, %4
%59 = load i8*, i8** %6
%60 = call i32 @writeError(i32 10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %59)
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"pcaEncrypt [plaintext]: %s\00"
@.str.1 = [28 x i8] c"pcaEncrypt [ciphertext]: %s\00"
define void @pcaEncrypt(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i32 @writeError(i32 10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %31, label %8
8: ; preds = %4
%9 = load i8, i8* %0
%10 = trunc i32 %2 to i8
%11 = xor i8 %9, %10
store i8 %11, i8* %1
%12 = tail call i32 @strlen(i8* %0)
%13 = icmp ugt i32 %12, 1
br i1 %13, label %14, label %31
14: ; preds = %8, %14
%15 = phi i64 [ %27, %14 ], [ 1, %8 ]
%16 = add nsw i64 %15, -1
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %0, i64 %15
%20 = load i8, i8* %19
%21 = trunc i64 %15 to i32
%22 = sub i32 %21, %3
%23 = trunc i32 %22 to i8
%24 = xor i8 %18, %23
%25 = xor i8 %24, %20
%26 = getelementptr inbounds i8, i8* %1, i64 %15
store i8 %25, i8* %26
%27 = add nuw nsw i64 %15, 1
%28 = tail call i32 @strlen(i8* %0)
%29 = zext i32 %28 to i64
%30 = icmp ult i64 %27, %29
br i1 %30, label %14, label %31
31: ; preds = %14, %8, %4
%32 = tail call i32 @writeError(i32 10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %1)
ret void
}