#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 */
struct rc4_context {
  int dummy;
};

/* Variables and functions */
unsigned char const rc4_byte(struct rc4_context *);
void rc4_cipher(struct rc4_context *rc4, unsigned char *out,
                const unsigned char *in, unsigned int length) {
  unsigned int i;
  for (i = 0; i < length; i++)
    out[i] = in[i] ^ rc4_byte(rc4);
}


x86 assembly (clang, -O0):
<rc4_cipher>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1175 <rc4_cipher+0x65>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rc4_byte@plt>
mov    %al,%cl
mov    -0x24(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112e <rc4_cipher+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc4_cipher>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
je     114d <rc4_cipher+0x3d>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %ecx,%r13d
xor    %ebx,%ebx
nopl   (%rax)
movzbl (%r14,%rbx,1),%ebp
mov    %r12,%rdi
call   1030 <rc4_byte@plt>
xor    %bpl,%al
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1130 <rc4_cipher+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rc4_context = type { i32 }
define void @rc4_cipher(%struct.rc4_context* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca %struct.rc4_context*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store %struct.rc4_context* %0, %struct.rc4_context** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %30, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %8
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %33
14: ; preds = %10
%15 = load i8*, i8** %7
%16 = load i32, i32* %9
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = load %struct.rc4_context*, %struct.rc4_context** %5
%22 = call zeroext i8 @rc4_byte(%struct.rc4_context* %21)
%23 = zext i8 %22 to i32
%24 = xor i32 %20, %23
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %6
%27 = load i32, i32* %9
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
br label %30
30: ; preds = %14
%31 = load i32, i32* %9
%32 = add i32 %31, 1
store i32 %32, i32* %9
br label %10
33: ; preds = %10
ret void
}

LLVM IR (-O2):
%struct.rc4_context = type { i32 }
define void @rc4_cipher(%struct.rc4_context* %0, i8* nocapture writeonly %1, i8* nocapture %2, i32 %3) {
%5 = icmp eq i32 %3, 0
br i1 %5, label %17, label %6
6: ; preds = %4
%7 = zext i32 %3 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %15, %8 ]
%10 = getelementptr inbounds i8, i8* %2, i64 %9
%11 = load i8, i8* %10
%12 = tail call zeroext i8 @rc4_byte(%struct.rc4_context* %0)
%13 = xor i8 %12, %11
%14 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %13, i8* %14
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, %7
br i1 %16, label %17, label %8
17: ; preds = %8, %4
ret void
}