#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 strlen(char *);
int /*<<< orphan*/ swap(unsigned char *, unsigned char *);
int KSA(char *key, unsigned char *S) {
  int len = strlen(key);
  int j = 0;
  for (int i = 0; i < 256; i++)
    S[i] = i;
  for (int i = 0; i < 256; i++) {
    j = (j + S[i] + key[i % len]) % 256;
    swap(&S[i], &S[j]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<KSA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jge    1175 <KSA+0x55>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114a <KSA+0x2a>
movl   $0x0,-0x20(%rbp)
cmpl   $0x100,-0x20(%rbp)
jge    11e8 <KSA+0xc8>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    -0x24(%rbp),%eax
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    117c <KSA+0x5c>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<KSA>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%r15d
movaps 0xec3(%rip),%xmm0
movups %xmm0,(%r12)
movaps 0xec7(%rip),%xmm0
movups %xmm0,0x10(%r12)
movaps 0xeca(%rip),%xmm0
movups %xmm0,0x20(%r12)
movaps 0xecd(%rip),%xmm0
movups %xmm0,0x30(%r12)
movaps 0xed0(%rip),%xmm0
movups %xmm0,0x40(%r12)
movaps 0xed3(%rip),%xmm0
movups %xmm0,0x50(%r12)
movaps 0xed6(%rip),%xmm0
movups %xmm0,0x60(%r12)
movaps 0xed9(%rip),%xmm0
movups %xmm0,0x70(%r12)
movaps 0xedc(%rip),%xmm0
movups %xmm0,0x80(%r12)
movaps 0xedc(%rip),%xmm0
movups %xmm0,0x90(%r12)
movaps 0xedc(%rip),%xmm0
movups %xmm0,0xa0(%r12)
movaps 0xedc(%rip),%xmm0
movups %xmm0,0xb0(%r12)
movaps 0xedc(%rip),%xmm0
movups %xmm0,0xc0(%r12)
movaps 0xedc(%rip),%xmm0
movups %xmm0,0xd0(%r12)
movaps 0xedc(%rip),%xmm0
movups %xmm0,0xe0(%r12)
movaps 0xedc(%rip),%xmm0
movups %xmm0,0xf0(%r12)
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbp,1),%rdi
movzbl (%r12,%rbp,1),%ecx
add    %ebx,%ecx
mov    %ebp,%eax
cltd
idiv   %r15d
movsbl (%r14,%rdx,1),%eax
mov    %ecx,%ebx
add    %eax,%ebx
lea    0xff(%rax,%rcx,1),%eax
cmovns %ebx,%eax
and    $0xffffff00,%eax
sub    %eax,%ebx
movslq %ebx,%rsi
add    %r12,%rsi
call   1040 <swap@plt>
add    $0x1,%rbp
cmp    $0x100,%rbp
jne    1230 <KSA+0x110>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @KSA(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = bitcast i8* %1 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* %1, 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* %1, 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* %1, 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* %1, 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* %1, 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* %1, 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* %1, 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* %1, 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* %1, 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* %1, 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* %1, 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* %1, 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* %1, 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* %1, 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* %1, 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 %36
35: ; preds = %36
ret i32 0
36: ; preds = %2, %36
%37 = phi i64 [ %54, %36 ], [ 0, %2 ]
%38 = phi i32 [ %50, %36 ], [ 0, %2 ]
%39 = getelementptr inbounds i8, i8* %1, i64 %37
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = add nsw i32 %38, %41
%43 = trunc i64 %37 to i32
%44 = srem i32 %43, %3
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = add nsw i32 %42, %48
%50 = srem i32 %49, 256
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %1, i64 %51
%53 = tail call i32 @swap(i8* %39, i8* %52)
%54 = add nuw nsw i64 %37, 1
%55 = icmp eq i64 %54, 256
br i1 %55, label %35, label %36
}