#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_n(unsigned char *, unsigned char *, size_t,
                         unsigned char *, size_t, size_t);
size_t strlen(char *);
void ciphersaber_2_dec(unsigned char *out, unsigned char *cmsg, size_t clen,
                       char *key, size_t n) {
  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_n(out, cmsg + 10, clen - 10, dec_key, l + 10, n);
}


x86 assembly (clang, -O0):
<ciphersaber_2_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%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    -0x32(%rbp),%rdi
mov    $0xa,%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
sub    $0x100,%rax
setb   %al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x40(%rbp),%rcx
mov    %rcx,%rax
add    $0xa,%rax
mov    %rsp,%rdx
mov    %rdx,-0x48(%rbp)
add    $0x19,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x40(%rbp),%rdx
xor    %eax,%eax
call   1060 <memcpy@plt>
mov    -0x58(%rbp),%rdi
add    -0x40(%rbp),%rdi
lea    -0x32(%rbp),%rsi
xor    %eax,%eax
mov    $0xa,%edx
call   1060 <memcpy@plt>
mov    -0x58(%rbp),%rcx
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0xa,%rsi
mov    -0x18(%rbp),%rdx
sub    $0xa,%rdx
mov    -0x40(%rbp),%r8
add    $0xa,%r8
mov    -0x28(%rbp),%r9
call   1030 <rc4_n@plt>
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ciphersaber_2_dec>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,-0x48(%rbp)
mov    %rcx,%r13
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,-0x40(%rbp)
xor    %edi,%edi
cmp    $0xa,%rdx
setae  %dil
call   1050 <assert@plt>
lea    -0x52(%rbp),%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
xor    %eax,%eax
call   1060 <memcpy@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
xor    %edi,%edi
cmp    $0x100,%rax
setb   %dil
call   1050 <assert@plt>
mov    %rsp,-0x38(%rbp)
lea    0xa(%r12),%rax
mov    %rax,-0x30(%rbp)
mov    %rsp,%r14
lea    0x19(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <memcpy@plt>
add    %r14,%r12
mov    %r12,%rdi
lea    -0x52(%rbp),%rsi
mov    $0xa,%edx
xor    %eax,%eax
call   1060 <memcpy@plt>
add    $0xa,%rbx
add    $0xfffffffffffffff6,%r15
mov    -0x40(%rbp),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    -0x30(%rbp),%r8
mov    -0x48(%rbp),%r9
call   1030 <rc4_n@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_2_dec(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca [10 x i8]
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%15 = load i64, i64* %8
%16 = icmp uge i64 %15, 10
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%20 = load i8*, i8** %7
%21 = call i32 (i8*, ...) @memcpy(i8* %19, i8* %20, i32 10)
%22 = load i8*, i8** %9
%23 = call i64 @strlen(i8* %22)
store i64 %23, i64* %12
%24 = load i64, i64* %12
%25 = icmp ult i64 %24, 256
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i64, i64* %12
%29 = add i64 %28, 10
%30 = call i8* @llvm.stacksave()
store i8* %30, i8** %13
%31 = alloca i8, i64 %29
store i64 %29, i64* %14
%32 = load i8*, i8** %9
%33 = load i64, i64* %12
%34 = call i32 (i8*, ...) @memcpy(i8* %31, i8* %32, i64 %33)
%35 = load i64, i64* %12
%36 = getelementptr inbounds i8, i8* %31, i64 %35
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%38 = call i32 (i8*, ...) @memcpy(i8* %36, i8* %37, i32 10)
%39 = load i8*, i8** %6
%40 = load i8*, i8** %7
%41 = getelementptr inbounds i8, i8* %40, i64 10
%42 = load i64, i64* %8
%43 = sub i64 %42, 10
%44 = load i64, i64* %12
%45 = add i64 %44, 10
%46 = load i64, i64* %10
%47 = call i32 @rc4_n(i8* %39, i8* %41, i64 %43, i8* %31, i64 %45, i64 %46)
%48 = load i8*, i8** %13
ret void
}

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