#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 *);
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,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    1175 <rc4_cipher+0x65>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <rc4_byte@plt>
mov    %al,%cl
mov    -0x2c(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    112e <rc4_cipher+0x1e>
mov    -0x4(%rbp),%eax
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 i32 @rc4_cipher(%struct.rc4_context* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.rc4_context*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store %struct.rc4_context* %0, %struct.rc4_context** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 0, i32* %10
br label %11
11: ; preds = %31, %4
%12 = load i32, i32* %10
%13 = load i32, i32* %9
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load i8*, i8** %8
%17 = load i32, i32* %10
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = load %struct.rc4_context*, %struct.rc4_context** %6
%23 = call zeroext i8 @rc4_byte(%struct.rc4_context* %22)
%24 = zext i8 %23 to i32
%25 = xor i32 %21, %24
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %7
%28 = load i32, i32* %10
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
br label %31
31: ; preds = %15
%32 = load i32, i32* %10
%33 = add i32 %32, 1
store i32 %33, i32* %10
br label %11
34: ; preds = %11
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
%struct.rc4_context = type { i32 }
define i32 @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 i32 undef
}