#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*/ raw2hex(char *, unsigned char *, size_t);
int /*<<< orphan*/ rc4(unsigned char *, unsigned char *, size_t,
                       unsigned char *, int /*<<< orphan*/);
int strcmp(char *, char const *);
int /*<<< orphan*/ strlen(char const *);
int test(unsigned char *buf, size_t len, const char *key,
         const char *expected) {
  unsigned char out[2048];
  rc4(out, buf, len, (unsigned char *)key, strlen(key));
  char hex[4096 + 1];
  raw2hex(hex, out, len);
  return strcmp(hex, expected);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1850,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x820(%rbp),%rax
mov    %rax,-0x1850(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x1848(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1840(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x1838(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1850(%rbp),%rdi
mov    -0x1848(%rbp),%rsi
mov    -0x1840(%rbp),%rdx
mov    -0x1838(%rbp),%rcx
mov    %eax,%r8d
call   1050 <rc4@plt>
lea    -0x1830(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <raw2hex@plt>
lea    -0x1830(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcmp@plt>
add    $0x1850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1810,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    %rsp,%r13
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
call   1050 <rc4@plt>
lea    0x800(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1030 <raw2hex@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
add    $0x1810,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @test(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [2048 x i8]
%10 = alloca [4097 x i8]
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = load i8*, i8** %7
%15 = load i8*, i8** %7
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @rc4(i8* %11, i8* %12, i64 %13, i8* %14, i32 %16)
%18 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%20 = load i64, i64* %6
%21 = call i32 @raw2hex(i8* %18, i8* %19, i64 %20)
%22 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%23 = load i8*, i8** %8
%24 = call i32 @strcmp(i8* %22, i8* %23)
ret i32 %24
}

LLVM IR (-O2):
define i32 @test(i8* %0, i64 %1, i8* %2, i8* nocapture %3) {
%5 = alloca [2048 x i8]
%6 = alloca [4097 x i8]
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%8 = tail call i32 @strlen(i8* %2)
%9 = call i32 @rc4(i8* %7, i8* %0, i64 %1, i8* %2, i32 %8)
%10 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 0
%11 = call i32 @raw2hex(i8* %10, i8* %7, i64 %1)
%12 = call i32 @strcmp(i8* %10, i8* dereferenceable(1) %3)
ret i32 %12
}