void rc4_init(unsigned char *s, unsigned char *key, unsigned long len) {
  unsigned int i, j;
  unsigned char tmp;
  for (i = 0; i < 256; i++) {
    s[i] = i;
  }
  for (i = j = 0; i < 256; i++) {
    j = (j + s[i] + key[i % len]) % 256;
    tmp = s[i];
    s[i] = s[j];
    s[j] = tmp;
  }
}


x86 assembly (clang, -O0):
<rc4_init>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jae    1141 <rc4_init+0x41>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <rc4_init+0x17>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jae    11c9 <rc4_init+0xc9>
mov    -0x20(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    -0x1c(%rbp),%edx
movzbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%eax
xor    %edx,%edx
divq   -0x18(%rbp)
mov    -0x28(%rbp),%eax
movzbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
and    $0xff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x21(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <rc4_init+0x4f>
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc4_init>:
mov    %rdx,%r8
movaps 0xef6(%rip),%xmm0
movups %xmm0,(%rdi)
movaps 0xefc(%rip),%xmm0
movups %xmm0,0x10(%rdi)
movaps 0xf01(%rip),%xmm0
movups %xmm0,0x20(%rdi)
movaps 0xf06(%rip),%xmm0
movups %xmm0,0x30(%rdi)
movaps 0xf0b(%rip),%xmm0
movups %xmm0,0x40(%rdi)
movaps 0xf10(%rip),%xmm0
movups %xmm0,0x50(%rdi)
movaps 0xf15(%rip),%xmm0
movups %xmm0,0x60(%rdi)
movaps 0xf1a(%rip),%xmm0
movups %xmm0,0x70(%rdi)
movaps 0xf1f(%rip),%xmm0
movups %xmm0,0x80(%rdi)
movaps 0xf21(%rip),%xmm0
movups %xmm0,0x90(%rdi)
movaps 0xf23(%rip),%xmm0
movups %xmm0,0xa0(%rdi)
movaps 0xf25(%rip),%xmm0
movups %xmm0,0xb0(%rdi)
movaps 0xf27(%rip),%xmm0
movups %xmm0,0xc0(%rdi)
movaps 0xf29(%rip),%xmm0
movups %xmm0,0xd0(%rdi)
movaps 0xf2b(%rip),%xmm0
movups %xmm0,0xe0(%rdi)
movaps 0xf2d(%rip),%xmm0
movups %xmm0,0xf0(%rdi)
xor    %ecx,%ecx
xor    %eax,%eax
jmp    11fb <rc4_init+0xfb>
mov    %rcx,%rax
xor    %edx,%edx
div    %r8
movzbl (%rsi,%rdx,1),%eax
add    %eax,%r10d
movzbl %r10b,%eax
movzbl (%rdi,%rax,1),%edx
mov    %dl,(%rdi,%rcx,1)
mov    %r9b,(%rdi,%rax,1)
add    $0x1,%rcx
cmp    $0x100,%rcx
je     121b <rc4_init+0x11b>
movzbl (%rdi,%rcx,1),%r9d
mov    %eax,%r10d
add    %r9,%r10
mov    %rcx,%rax
or     %r8,%rax
shr    $0x20,%rax
jne    11d0 <rc4_init+0xd0>
mov    %ecx,%eax
xor    %edx,%edx
div    %r8d
jmp    11d8 <rc4_init+0xd8>
ret

LLVM IR (-O0):
define void @rc4_init(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %7
br label %10
10: ; preds = %20, %3
%11 = load i32, i32* %7
%12 = icmp ult i32 %11, 256
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = load i32, i32* %7
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %4
%17 = load i32, i32* %7
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 %15, i8* %19
br label %20
20: ; preds = %13
%21 = load i32, i32* %7
%22 = add i32 %21, 1
store i32 %22, i32* %7
br label %10
23: ; preds = %10
store i32 0, i32* %8
store i32 0, i32* %7
br label %24
24: ; preds = %65, %23
%25 = load i32, i32* %7
%26 = icmp ult i32 %25, 256
br i1 %26, label %27, label %68
27: ; preds = %24
%28 = load i32, i32* %8
%29 = load i8*, i8** %4
%30 = load i32, i32* %7
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = add i32 %28, %34
%36 = load i8*, i8** %5
%37 = load i32, i32* %7
%38 = zext i32 %37 to i64
%39 = load i64, i64* %6
%40 = urem i64 %38, %39
%41 = getelementptr inbounds i8, i8* %36, i64 %40
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = add i32 %35, %43
%45 = urem i32 %44, 256
store i32 %45, i32* %8
%46 = load i8*, i8** %4
%47 = load i32, i32* %7
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
store i8 %50, i8* %9
%51 = load i8*, i8** %4
%52 = load i32, i32* %8
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = load i8*, i8** %4
%57 = load i32, i32* %7
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 %55, i8* %59
%60 = load i8, i8* %9
%61 = load i8*, i8** %4
%62 = load i32, i32* %8
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 %60, i8* %64
br label %65
65: ; preds = %27
%66 = load i32, i32* %7
%67 = add i32 %66, 1
store i32 %67, i32* %7
br label %24
68: ; preds = %24
ret void
}

LLVM IR (-O2):
define void @rc4_init(i8* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = bitcast i8* %0 to <16 x i8>*
store <16 x i8> <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, <16 x i8>* %4
%5 = getelementptr inbounds i8, i8* %0, i64 16
%6 = bitcast i8* %5 to <16 x i8>*
store <16 x i8> <i8 16, i8 17, i8 18, i8 19, i8 20, i8 21, i8 22, i8 23, i8 24, i8 25, i8 26, i8 27, i8 28, i8 29, i8 30, i8 31>, <16 x i8>* %6
%7 = getelementptr inbounds i8, i8* %0, i64 32
%8 = bitcast i8* %7 to <16 x i8>*
store <16 x i8> <i8 32, i8 33, i8 34, i8 35, i8 36, i8 37, i8 38, i8 39, i8 40, i8 41, i8 42, i8 43, i8 44, i8 45, i8 46, i8 47>, <16 x i8>* %8
%9 = getelementptr inbounds i8, i8* %0, i64 48
%10 = bitcast i8* %9 to <16 x i8>*
store <16 x i8> <i8 48, i8 49, i8 50, i8 51, i8 52, i8 53, i8 54, i8 55, i8 56, i8 57, i8 58, i8 59, i8 60, i8 61, i8 62, i8 63>, <16 x i8>* %10
%11 = getelementptr inbounds i8, i8* %0, i64 64
%12 = bitcast i8* %11 to <16 x i8>*
store <16 x i8> <i8 64, i8 65, i8 66, i8 67, i8 68, i8 69, i8 70, i8 71, i8 72, i8 73, i8 74, i8 75, i8 76, i8 77, i8 78, i8 79>, <16 x i8>* %12
%13 = getelementptr inbounds i8, i8* %0, i64 80
%14 = bitcast i8* %13 to <16 x i8>*
store <16 x i8> <i8 80, i8 81, i8 82, i8 83, i8 84, i8 85, i8 86, i8 87, i8 88, i8 89, i8 90, i8 91, i8 92, i8 93, i8 94, i8 95>, <16 x i8>* %14
%15 = getelementptr inbounds i8, i8* %0, i64 96
%16 = bitcast i8* %15 to <16 x i8>*
store <16 x i8> <i8 96, i8 97, i8 98, i8 99, i8 100, i8 101, i8 102, i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 109, i8 110, i8 111>, <16 x i8>* %16
%17 = getelementptr inbounds i8, i8* %0, i64 112
%18 = bitcast i8* %17 to <16 x i8>*
store <16 x i8> <i8 112, i8 113, i8 114, i8 115, i8 116, i8 117, i8 118, i8 119, i8 120, i8 121, i8 122, i8 123, i8 124, i8 125, i8 126, i8 127>, <16 x i8>* %18
%19 = getelementptr inbounds i8, i8* %0, i64 128
%20 = bitcast i8* %19 to <16 x i8>*
store <16 x i8> <i8 -128, i8 -127, i8 -126, i8 -125, i8 -124, i8 -123, i8 -122, i8 -121, i8 -120, i8 -119, i8 -118, i8 -117, i8 -116, i8 -115, i8 -114, i8 -113>, <16 x i8>* %20
%21 = getelementptr inbounds i8, i8* %0, i64 144
%22 = bitcast i8* %21 to <16 x i8>*
store <16 x i8> <i8 -112, i8 -111, i8 -110, i8 -109, i8 -108, i8 -107, i8 -106, i8 -105, i8 -104, i8 -103, i8 -102, i8 -101, i8 -100, i8 -99, i8 -98, i8 -97>, <16 x i8>* %22
%23 = getelementptr inbounds i8, i8* %0, i64 160
%24 = bitcast i8* %23 to <16 x i8>*
store <16 x i8> <i8 -96, i8 -95, i8 -94, i8 -93, i8 -92, i8 -91, i8 -90, i8 -89, i8 -88, i8 -87, i8 -86, i8 -85, i8 -84, i8 -83, i8 -82, i8 -81>, <16 x i8>* %24
%25 = getelementptr inbounds i8, i8* %0, i64 176
%26 = bitcast i8* %25 to <16 x i8>*
store <16 x i8> <i8 -80, i8 -79, i8 -78, i8 -77, i8 -76, i8 -75, i8 -74, i8 -73, i8 -72, i8 -71, i8 -70, i8 -69, i8 -68, i8 -67, i8 -66, i8 -65>, <16 x i8>* %26
%27 = getelementptr inbounds i8, i8* %0, i64 192
%28 = bitcast i8* %27 to <16 x i8>*
store <16 x i8> <i8 -64, i8 -63, i8 -62, i8 -61, i8 -60, i8 -59, i8 -58, i8 -57, i8 -56, i8 -55, i8 -54, i8 -53, i8 -52, i8 -51, i8 -50, i8 -49>, <16 x i8>* %28
%29 = getelementptr inbounds i8, i8* %0, i64 208
%30 = bitcast i8* %29 to <16 x i8>*
store <16 x i8> <i8 -48, i8 -47, i8 -46, i8 -45, i8 -44, i8 -43, i8 -42, i8 -41, i8 -40, i8 -39, i8 -38, i8 -37, i8 -36, i8 -35, i8 -34, i8 -33>, <16 x i8>* %30
%31 = getelementptr inbounds i8, i8* %0, i64 224
%32 = bitcast i8* %31 to <16 x i8>*
store <16 x i8> <i8 -32, i8 -31, i8 -30, i8 -29, i8 -28, i8 -27, i8 -26, i8 -25, i8 -24, i8 -23, i8 -22, i8 -21, i8 -20, i8 -19, i8 -18, i8 -17>, <16 x i8>* %32
%33 = getelementptr inbounds i8, i8* %0, i64 240
%34 = bitcast i8* %33 to <16 x i8>*
store <16 x i8> <i8 -16, i8 -15, i8 -14, i8 -13, i8 -12, i8 -11, i8 -10, i8 -9, i8 -8, i8 -7, i8 -6, i8 -5, i8 -4, i8 -3, i8 -2, i8 -1>, <16 x i8>* %34
br label %35
35: ; preds = %3, %35
%36 = phi i64 [ %51, %35 ], [ 0, %3 ]
%37 = phi i32 [ %47, %35 ], [ 0, %3 ]
%38 = getelementptr inbounds i8, i8* %0, i64 %36
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = add nuw nsw i32 %37, %40
%42 = urem i64 %36, %2
%43 = getelementptr inbounds i8, i8* %1, i64 %42
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = add nuw nsw i32 %41, %45
%47 = and i32 %46, 255
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %0, i64 %48
%50 = load i8, i8* %49
store i8 %50, i8* %38
store i8 %39, i8* %49
%51 = add nuw nsw i64 %36, 1
%52 = icmp eq i64 %51, 256
br i1 %52, label %53, label %35
53: ; preds = %35
ret void
}