#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*/ assert(int);
int /*<<< orphan*/ memcpy(unsigned char *, ...);
int /*<<< orphan*/ rc4(unsigned char *, unsigned char *, size_t,
                       unsigned char *, size_t);
size_t strlen(char *);
void ciphersaber_1_dec(unsigned char *out, unsigned char *cmsg, size_t clen,
                       char *key) {
  unsigned char iv[10];
  assert(clen >= 10);
  memcpy(iv, cmsg, 10);
  size_t l = strlen(key);
  assert(l < 256);
  unsigned char dec_key[l + 10];
  memcpy(dec_key, key, l);
  memcpy(dec_key + l, iv, 10);
  rc4(out, cmsg + 10, clen - 10, dec_key, l + 10);
}


x86 assembly (clang, -O0):
<ciphersaber_1_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
sub    $0xa,%rax
setae  %al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
lea    -0x2a(%rbp),%rdi
mov    $0xa,%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    $0x100,%rax
setb   %al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x38(%rbp),%rcx
mov    %rcx,%rax
add    $0xa,%rax
mov    %rsp,%rdx
mov    %rdx,-0x40(%rbp)
add    $0x19,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%rdx
xor    %eax,%eax
call   1060 <memcpy@plt>
mov    -0x50(%rbp),%rdi
add    -0x38(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
xor    %eax,%eax
mov    $0xa,%edx
call   1060 <memcpy@plt>
mov    -0x50(%rbp),%rcx
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0xa,%rsi
mov    -0x18(%rbp),%rdx
sub    $0xa,%rdx
mov    -0x38(%rbp),%r8
add    $0xa,%r8
call   1040 <rc4@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ciphersaber_1_dec>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,-0x40(%rbp)
xor    %edi,%edi
cmp    $0xa,%rdx
setae  %dil
call   1050 <assert@plt>
lea    -0x4a(%rbp),%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
xor    %eax,%eax
call   1060 <memcpy@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
xor    %edi,%edi
cmp    $0x100,%rax
setb   %dil
call   1050 <assert@plt>
mov    %rsp,-0x38(%rbp)
lea    0xa(%r13),%rax
mov    %rax,-0x30(%rbp)
mov    %rsp,%r15
lea    0x19(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <memcpy@plt>
add    %r15,%r13
mov    %r13,%rdi
lea    -0x4a(%rbp),%rsi
mov    $0xa,%edx
xor    %eax,%eax
call   1060 <memcpy@plt>
add    $0xa,%rbx
add    $0xfffffffffffffff6,%r14
mov    -0x40(%rbp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    -0x30(%rbp),%r8
call   1040 <rc4@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ciphersaber_1_dec(i8* %0, i8* %1, i64 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca [10 x i8]
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i8* %3, i8** %8
%13 = load i64, i64* %7
%14 = icmp uge i64 %13, 10
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%18 = load i8*, i8** %6
%19 = call i32 (i8*, ...) @memcpy(i8* %17, i8* %18, i32 10)
%20 = load i8*, i8** %8
%21 = call i64 @strlen(i8* %20)
store i64 %21, i64* %10
%22 = load i64, i64* %10
%23 = icmp ult i64 %22, 256
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i64, i64* %10
%27 = add i64 %26, 10
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %11
%29 = alloca i8, i64 %27
store i64 %27, i64* %12
%30 = load i8*, i8** %8
%31 = load i64, i64* %10
%32 = call i32 (i8*, ...) @memcpy(i8* %29, i8* %30, i64 %31)
%33 = load i64, i64* %10
%34 = getelementptr inbounds i8, i8* %29, i64 %33
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%36 = call i32 (i8*, ...) @memcpy(i8* %34, i8* %35, i32 10)
%37 = load i8*, i8** %5
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i64 10
%40 = load i64, i64* %7
%41 = sub i64 %40, 10
%42 = load i64, i64* %10
%43 = add i64 %42, 10
%44 = call i32 @rc4(i8* %37, i8* %39, i64 %41, i8* %29, i64 %43)
%45 = load i8*, i8** %11
ret void
}

LLVM IR (-O2):
define void @ciphersaber_1_dec(i8* %0, i8* %1, i64 %2, i8* %3) {
%5 = alloca [10 x i8]
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%7 = icmp ugt i64 %2, 9
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = call i32 (i8*, ...) @memcpy(i8* %6, i8* %1, i32 10)
%11 = call i64 @strlen(i8* dereferenceable(1) %3)
%12 = icmp ult i64 %11, 256
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = add i64 %11, 10
%16 = call i8* @llvm.stacksave()
%17 = alloca i8, i64 %15
%18 = call i32 (i8*, ...) @memcpy(i8* %17, i8* %3, i64 %11)
%19 = getelementptr inbounds i8, i8* %17, i64 %11
%20 = call i32 (i8*, ...) @memcpy(i8* %19, i8* %6, i32 10)
%21 = getelementptr inbounds i8, i8* %1, i64 10
%22 = add i64 %2, -10
%23 = call i32 @rc4(i8* %0, i8* %21, i64 %22, i8* %17, i64 %15)
ret void
}