#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 */
typedef int /*<<< orphan*/ passwd;

/* Variables and functions */
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void pca_encrypt(char *cleartxt) {
  char passwd[128];
  int i;
  strncpy(passwd, cleartxt, sizeof(passwd) - 1);
  passwd[sizeof(passwd) - 1] = 0;
  if (strlen(cleartxt) > 0) {
    passwd[0] = (passwd[0] ^ 0xab);
    for (i = 1; i < strlen(passwd); i++)
      passwd[i] = passwd[i - 1] ^ passwd[i] ^ (i - 1);
    passwd[strlen(passwd)] = '\0';
    strcpy(cleartxt, passwd);
  }
}


x86 assembly (clang, -O0):
<pca_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x7f,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jbe    122b <pca_encrypt+0xfb>
movsbl -0x90(%rbp),%eax
xor    $0xab,%eax
mov    %al,-0x90(%rbp)
movl   $0x1,-0x94(%rbp)
movslq -0x94(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0xa0(%rbp),%rax
cmp    %rcx,%rax
jae    1207 <pca_encrypt+0xd7>
mov    -0x94(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x90(%rbp,%rax,1),%eax
ff
movslq -0x94(%rbp),%rcx
movsbl -0x90(%rbp,%rcx,1),%ecx
ff
xor    %ecx,%eax
mov    -0x94(%rbp),%ecx
sub    $0x1,%ecx
xor    %ecx,%eax
mov    %al,%cl
movslq -0x94(%rbp),%rax
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1187 <pca_encrypt+0x57>
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
movb   $0x0,-0x90(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1040 <strcpy@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pca_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    %r14,%rsi
mov    $0x7f,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x7f(%rsp)
cmpb   $0x0,(%r14)
je     11b1 <pca_encrypt+0x81>
mov    (%rsp),%r12b
xor    $0xab,%r12b
mov    %r12b,(%rsp)
mov    %rsp,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%rax
jb     11a2 <pca_encrypt+0x72>
mov    $0x1,%ebx
mov    %rsp,%r15
nop
lea    -0x1(%rbx),%ebp
xor    %r12b,%bpl
xor    (%rsp,%rbx,1),%bpl
mov    %bpl,(%rsp,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebp,%r12d
cmp    %rbx,%rax
ja     1180 <pca_encrypt+0x50>
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @pca_encrypt(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = call i32 @strncpy(i8* %3, i8* %0, i32 127)
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 127
store i8 0, i8* %5
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %29, label %8
8: ; preds = %1
%9 = load i8, i8* %3
%10 = xor i8 %9, -85
store i8 %10, i8* %3
%11 = call i64 @strlen(i8* %3)
%12 = icmp ugt i64 %11, 1
br i1 %12, label %13, label %25
13: ; preds = %8, %13
%14 = phi i8 [ %21, %13 ], [ %10, %8 ]
%15 = phi i64 [ %22, %13 ], [ 1, %8 ]
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = trunc i64 %15 to i8
%19 = add i8 %18, -1
%20 = xor i8 %14, %19
%21 = xor i8 %20, %17
store i8 %21, i8* %16
%22 = add nuw nsw i64 %15, 1
%23 = call i64 @strlen(i8* %3)
%24 = icmp ugt i64 %23, %22
br i1 %24, label %13, label %25
25: ; preds = %13, %8
%26 = phi i64 [ %11, %8 ], [ %23, %13 ]
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i32 @strcpy(i8* %0, i8* %3)
br label %29
29: ; preds = %25, %1
ret void
}