#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*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ read(int /*<<< orphan*/, unsigned char *, int);
size_t strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, unsigned char *, int);
int main(int argc, char *argv[]) {
  char *key;
  unsigned char decrypted, encrypted;
  size_t key_idx = 0, key_len;
  if (argc < 2)
    return 1;
  key = argv[1];
  key_len = strlen(key);
  while (read(STDIN_FILENO, &decrypted, 1)) {
    encrypted = decrypted ^ key[key_idx];
    write(STDOUT_FILENO, &encrypted, 1);
    key_idx = (key_idx + 1) % key_len;
  }
  return 0x00;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1164 <main+0x34>
movl   $0x1,-0x4(%rbp)
jmp    11ea <main+0xba>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
je     11e3 <main+0xb3>
movzbl -0x19(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
xor    %ecx,%eax
mov    %al,-0x1a(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    -0x1a(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x30(%rbp)
mov    %rdx,-0x28(%rbp)
jmp    117d <main+0x4d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
cmp    $0x2,%edi
jl     11f0 <main+0xc0>
mov    0x8(%rsi),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0x6(%rsp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11f0 <main+0xc0>
mov    0x2e72(%rip),%rbp
lea    0x7(%rsp),%r12
lea    0x6(%rsp),%r13
jmp    11b6 <main+0x86>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rax
xor    %edx,%edx
div    %r15
mov    %rdx,%rbx
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %rax,%rax
je     11ee <main+0xbe>
movzbl (%r14,%rbx,1),%eax
xor    0x6(%rsp),%al
mov    %al,0x7(%rsp)
mov    0x0(%rbp),%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x1,%rbx
mov    %rbx,%rax
or     %r15,%rax
shr    $0x20,%rax
jne    1190 <main+0x60>
mov    %ebx,%eax
xor    %edx,%edx
div    %r15d
mov    %edx,%ebx
jmp    119b <main+0x6b>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %9
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %41
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %10
br label %20
20: ; preds = %24, %14
%21 = load i32, i32* @STDIN_FILENO
%22 = call i64 @read(i32 %21, i8* %7, i32 1)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = load i8, i8* %7
%26 = zext i8 %25 to i32
%27 = load i8*, i8** %6
%28 = load i64, i64* %9
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = xor i32 %26, %31
%33 = trunc i32 %32 to i8
store i8 %33, i8* %8
%34 = load i32, i32* @STDOUT_FILENO
%35 = call i32 @write(i32 %34, i8* %8, i32 1)
%36 = load i64, i64* %9
%37 = add i64 %36, 1
%38 = load i64, i64* %10
%39 = urem i64 %37, %38
store i64 %39, i64* %9
br label %20
40: ; preds = %20
store i32 0, i32* %3
br label %41
41: ; preds = %40, %13
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca i8
%5 = icmp slt i32 %0, 2
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%10 = load i32, i32* @STDIN_FILENO
%11 = call i64 @read(i32 %10, i8* %3, i32 1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %6, %13
%14 = phi i64 [ %22, %13 ], [ 0, %6 ]
%15 = load i8, i8* %3
%16 = getelementptr inbounds i8, i8* %8, i64 %14
%17 = load i8, i8* %16
%18 = xor i8 %17, %15
store i8 %18, i8* %4
%19 = load i32, i32* @STDOUT_FILENO
%20 = call i32 @write(i32 %19, i8* %4, i32 1)
%21 = add i64 %14, 1
%22 = urem i64 %21, %9
%23 = load i32, i32* @STDIN_FILENO
%24 = call i64 @read(i32 %23, i8* %3, i32 1)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %13
26: ; preds = %13, %6, %2
%27 = phi i32 [ 1, %2 ], [ 0, %6 ], [ 0, %13 ]
ret i32 %27
}