#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*/ strcpy(char *, char *);
size_t strlen(char *);
void pca_encrypt(char *cleartxt) {
  char passwd[128];
  int i;
  strcpy(passwd, cleartxt);
  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
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jbe    1212 <pca_encrypt+0xf2>
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   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0xa0(%rbp),%rax
cmp    %rcx,%rax
jae    11ee <pca_encrypt+0xce>
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    116e <pca_encrypt+0x4e>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
movb   $0x0,-0x90(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1030 <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
call   1030 <strcpy@plt>
cmpb   $0x0,(%r14)
je     11a1 <pca_encrypt+0x81>
mov    (%rsp),%r12b
xor    $0xab,%r12b
mov    %r12b,(%rsp)
mov    %rsp,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%rax
jb     1192 <pca_encrypt+0x72>
mov    $0x1,%ebx
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
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   1040 <strlen@plt>
mov    %ebp,%r12d
cmp    %rbx,%rax
ja     1170 <pca_encrypt+0x50>
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <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 @strcpy(i8* %5, i8* %6)
%8 = load i8*, i8** %2
%9 = call i64 @strlen(i8* %8)
%10 = icmp ugt i64 %9, 0
br i1 %10, label %11, label %54
11: ; preds = %1
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = xor i32 %14, 171
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
store i8 %16, i8* %17
store i32 1, i32* %4
br label %18
18: ; preds = %44, %11
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = icmp ult i64 %20, %22
br i1 %23, label %24, label %47
24: ; preds = %18
%25 = load i32, i32* %4
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = xor i32 %30, %35
%37 = load i32, i32* %4
%38 = sub nsw i32 %37, 1
%39 = xor i32 %36, %38
%40 = trunc i32 %39 to i8
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %42
store i8 %40, i8* %43
br label %44
44: ; preds = %24
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %18
47: ; preds = %18
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%49 = call i64 @strlen(i8* %48)
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %49
store i8 0, i8* %50
%51 = load i8*, i8** %2
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%53 = call i32 @strcpy(i8* %51, i8* %52)
br label %54
54: ; preds = %47, %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 @strcpy(i8* %3, i8* %0)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %28, label %7
7: ; preds = %1
%8 = load i8, i8* %3
%9 = xor i8 %8, -85
store i8 %9, i8* %3
%10 = call i64 @strlen(i8* %3)
%11 = icmp ugt i64 %10, 1
br i1 %11, label %12, label %24
12: ; preds = %7, %12
%13 = phi i8 [ %20, %12 ], [ %9, %7 ]
%14 = phi i64 [ %21, %12 ], [ 1, %7 ]
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = trunc i64 %14 to i8
%18 = add i8 %17, -1
%19 = xor i8 %13, %18
%20 = xor i8 %19, %16
store i8 %20, i8* %15
%21 = add nuw nsw i64 %14, 1
%22 = call i64 @strlen(i8* %3)
%23 = icmp ugt i64 %22, %21
br i1 %23, label %12, label %24
24: ; preds = %12, %7
%25 = phi i64 [ %10, %7 ], [ %22, %12 ]
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %25
store i8 0, i8* %26
%27 = call i32 @strcpy(i8* %0, i8* %3)
br label %28
28: ; preds = %24, %1
ret void
}