#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*/ printf(char *, ...);
int strlen(char *);
int /*<<< orphan*/ xor_encrypt(char *, char *, int);
int main(void) {
  char plain[] = "This is plain text";
  char key[] = "Abcdabcdabciabcdabcd";
  int n = strlen(plain);
  xor_encrypt(key, plain, n);
  printf("encrypted string: \n");
  for (int ii = 0; ii < n; ii++) {
    if (plain[ii] > 0x32 && plain[ii] < 0x7F)
      printf("%c", plain[ii]);
    else
      printf(" 0x%02x ", plain[ii]);
  }
  printf("\n");
  xor_encrypt(key, plain, n);
  printf("after round trip, plain string is '%s'\n", plain);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb4(%rip),%ax
mov    %ax,-0x10(%rbp)
mov    0xeac(%rip),%al
mov    %al,-0xe(%rbp)
mov    0xeb0(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xead(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xeab(%rip),%eax
mov    %eax,-0x30(%rbp)
mov    0xea6(%rip),%al
mov    %al,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x44(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1050 <xor_encrypt@plt>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1238 <main+0x108>
movslq -0x48(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x32,%eax
jle    120e <main+0xde>
movslq -0x48(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x7f,%eax
jge    120e <main+0xde>
movslq -0x48(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1225 <main+0xf5>
movslq -0x48(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122a <main+0xfa>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11c2 <main+0x92>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1050 <xor_encrypt@plt>
lea    -0x20(%rbp),%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
movaps 0xe9f(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x747865,0xf(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movabs $0x64636261646362,%rax
mov    %rax,0x2d(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
lea    0x20(%rsp),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <xor_encrypt@plt>
lea    0xeba(%rip),%rdi
call   1040 <puts@plt>
test   %r14d,%r14d
jle    11f7 <main+0xa7>
mov    %r14d,%ebp
lea    0xe75(%rip),%r15
xor    %ebx,%ebx
jmp    11e3 <main+0x93>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11f7 <main+0xa7>
movsbl (%rsp,%rbx,1),%esi
lea    -0x7f(%rsi),%eax
cmp    $0xb4,%al
jb     11d0 <main+0x80>
mov    %esi,%edi
call   1030 <putchar@plt>
jmp    11da <main+0x8a>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x20(%rsp),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
mov    %r14d,%edx
call   1070 <xor_encrypt@plt>
lea    0xe23(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.plain = [19 x i8] c"This is plain text\00"
@__const.main.key = [21 x i8] c"Abcdabcdabciabcdabcd\00"
@.str = [20 x i8] c"encrypted string: \0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [9 x i8] c" 0x%02x \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [40 x i8] c"after round trip, plain string is '%s'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [19 x i8]
%3 = alloca [21 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [19 x i8]* %2 to i8*
%7 = bitcast [21 x i8]* %3 to i8*
%8 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %4
%10 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%12 = load i32, i32* %4
%13 = call i32 @xor_encrypt(i8* %10, i8* %11, i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %15
15: ; preds = %48, %0
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %51
19: ; preds = %15
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp sgt i32 %24, 50
br i1 %25, label %26, label %40
26: ; preds = %19
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp slt i32 %31, 127
br i1 %32, label %33, label %40
33: ; preds = %26
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %47
40: ; preds = %26, %19
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %40, %33
br label %48
48: ; preds = %47
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %15
51: ; preds = %15
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%53 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%54 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%55 = load i32, i32* %4
%56 = call i32 @xor_encrypt(i8* %53, i8* %54, i32 %55)
%57 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %57)
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@__const.main.plain = [19 x i8] c"This is plain text\00"
@__const.main.key = [21 x i8] c"Abcdabcdabciabcdabcd\00"
@.str.2 = [9 x i8] c" 0x%02x \00"
@.str.4 = [40 x i8] c"after round trip, plain string is '%s'\0A\00"
@str = [19 x i8] c"encrypted string: \00"
define i32 @main() {
%1 = alloca [19 x i8]
%2 = alloca [21 x i8]
%3 = getelementptr inbounds [19 x i8], [19 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 0
%5 = call i32 @strlen(i8* %3)
%6 = call i32 @xor_encrypt(i8* %4, i8* %3, i32 %5)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%8 = icmp sgt i32 %5, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = zext i32 %5 to i64
br label %15
11: ; preds = %26, %0
%12 = call i32 @putchar(i32 10)
%13 = call i32 @xor_encrypt(i8* %4, i8* %3, i32 %5)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %3)
ret i32 0
15: ; preds = %9, %26
%16 = phi i64 [ 0, %9 ], [ %27, %26 ]
%17 = getelementptr inbounds [19 x i8], [19 x i8]* %1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = add i8 %18, -127
%21 = icmp ult i8 %20, -76
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = call i32 @putchar(i32 %19)
br label %26
24: ; preds = %15
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %26
26: ; preds = %22, %24
%27 = add nuw nsw i64 %16, 1
%28 = icmp eq i64 %27, %10
br i1 %28, label %11, label %15
}