#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*/ RC4(char *, char *, unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("Usage: %s <key> <plaintext>", argv[0]);
    return -1;
  }
  unsigned char *ciphertext = malloc(sizeof(int) * strlen(argv[2]));
  RC4(argv[1], argv[2], ciphertext);
  for (size_t i = 0, len = strlen(argv[2]); i < len; i++)
    printf("%02hhX", ciphertext[i]);
  return 0;
}


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)
cmpl   $0x3,-0x8(%rbp)
jge    1181 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <main+0xd3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <strlen@plt>
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <RC4@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    120c <main+0xcc>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11d3 <main+0x93>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
cmp    $0x2,%edi
jg     116a <main+0x2a>
mov    (%r14),%rsi
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
jmp    11cd <main+0x8d>
mov    0x10(%r14),%rdi
call   1030 <strlen@plt>
lea    0x0(,%rax,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    0x8(%r14),%rdi
mov    0x10(%r14),%rsi
mov    %rax,%rdx
call   1040 <RC4@plt>
mov    0x10(%r14),%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11ca <main+0x8a>
movslq %eax,%r13
xor    %r14d,%r14d
lea    0xe70(%rip),%r15
xor    %ebx,%ebx
xchg   %ax,%ax
movzbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11b0 <main+0x70>
jmp    11cd <main+0x8d>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [28 x i8] c"Usage: %s <key> <plaintext>\00"
@.str.1 = [7 x i8] c"%02hhX\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %30
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = shl i32 %10, 2
%12 = tail call i8* @malloc(i32 %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i8*, i8** %8
%16 = tail call i32 @RC4(i8* %14, i8* %15, i8* %12)
%17 = load i8*, i8** %8
%18 = tail call i32 @strlen(i8* %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %30, label %20
20: ; preds = %7
%21 = sext i32 %18 to i64
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ %28, %22 ], [ 0, %20 ]
%24 = getelementptr inbounds i8, i8* %12, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = add nuw i64 %23, 1
%29 = icmp eq i64 %28, %21
br i1 %29, label %30, label %22
30: ; preds = %22, %7, %4
%31 = phi i32 [ -1, %4 ], [ 0, %7 ], [ 0, %22 ]
ret i32 %31
}