#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 decrypt(unsigned char *, int, unsigned char *, unsigned char *);
int encrypt(unsigned char *, int, unsigned char *, unsigned char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ slv_to_uchar(char *, unsigned char *, int);
int /*<<< orphan*/ uchar_to_slv(unsigned char *, char *, int);
void cryptData(char *datain, char *key, char mode, char *dataout, int bytelen) {
  int crypt_len;
  unsigned char c_din[bytelen];
  unsigned char c_key[bytelen];
  unsigned char c_dout[bytelen];
  slv_to_uchar(datain, c_din, bytelen);
  slv_to_uchar(key, c_key, bytelen);
  if (mode) {
    crypt_len = encrypt(c_din, bytelen, c_key, c_dout);
  } else {
    crypt_len = decrypt(c_din, bytelen, c_key, c_dout);
  }
  if (crypt_len != 8) {
    printf("Warning: crypt operation returned with unexpected length %d\n",
           crypt_len);
  }
  uchar_to_slv(c_dout, dataout, bytelen);
  return;
}


x86 assembly (clang, -O0):
<cryptData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x60(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
call   1040 <slv_to_uchar@plt>
mov    -0x50(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
call   1040 <slv_to_uchar@plt>
cmpb   $0x0,-0x11(%rbp)
je     1213 <cryptData+0xc3>
mov    -0x58(%rbp),%rcx
mov    -0x50(%rbp),%rdx
mov    -0x60(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <encrypt@plt>
mov    %eax,-0x28(%rbp)
jmp    122a <cryptData+0xda>
mov    -0x58(%rbp),%rcx
mov    -0x50(%rbp),%rdx
mov    -0x60(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <decrypt@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x8,-0x28(%rbp)
je     1243 <cryptData+0xf3>
mov    -0x28(%rbp),%esi
lea    0xdc2(%rip),%rdi
call   1050 <printf@plt>
mov    -0x58(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1070 <uchar_to_slv@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cryptData>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r15d
mov    %rcx,-0x38(%rbp)
mov    %edx,-0x2c(%rbp)
mov    %rsi,%r14
mov    %r8d,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
mov    %rbx,%rsi
mov    %r8d,%edx
call   1040 <slv_to_uchar@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1040 <slv_to_uchar@plt>
cmpb   $0x0,-0x2c(%rbp)
je     11f5 <cryptData+0xa5>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12,%rdx
mov    %r13,%rcx
call   1060 <encrypt@plt>
cmp    $0x8,%eax
je     11d7 <cryptData+0x87>
lea    0xe30(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %r13,%rdi
mov    -0x38(%rbp),%rsi
mov    %r15d,%edx
call   1070 <uchar_to_slv@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12,%rdx
mov    %r13,%rcx
call   1030 <decrypt@plt>
cmp    $0x8,%eax
jne    11c9 <cryptData+0x79>
jmp    11d7 <cryptData+0x87>

LLVM IR (-O0):
@.str = [61 x i8] c"Warning: crypt operation returned with unexpected length %d\0A\00"
define void @cryptData(i8* %0, i8* %1, i8 signext %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8 %2, i8* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%16 = load i32, i32* %10
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %12
%19 = alloca i8, i64 %17
store i64 %17, i64* %13
%20 = load i32, i32* %10
%21 = zext i32 %20 to i64
%22 = alloca i8, i64 %21
store i64 %21, i64* %14
%23 = load i32, i32* %10
%24 = zext i32 %23 to i64
%25 = alloca i8, i64 %24
store i64 %24, i64* %15
%26 = load i8*, i8** %6
%27 = load i32, i32* %10
%28 = call i32 @slv_to_uchar(i8* %26, i8* %19, i32 %27)
%29 = load i8*, i8** %7
%30 = load i32, i32* %10
%31 = call i32 @slv_to_uchar(i8* %29, i8* %22, i32 %30)
%32 = load i8, i8* %8
%33 = icmp ne i8 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %5
%35 = load i32, i32* %10
%36 = call i32 @encrypt(i8* %19, i32 %35, i8* %22, i8* %25)
store i32 %36, i32* %11
br label %40
37: ; preds = %5
%38 = load i32, i32* %10
%39 = call i32 @decrypt(i8* %19, i32 %38, i8* %22, i8* %25)
store i32 %39, i32* %11
br label %40
40: ; preds = %37, %34
%41 = load i32, i32* %11
%42 = icmp ne i32 %41, 8
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32, i32* %11
%45 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %43, %40
%47 = load i8*, i8** %9
%48 = load i32, i32* %10
%49 = call i32 @uchar_to_slv(i8* %25, i8* %47, i32 %48)
%50 = load i8*, i8** %12
ret void
}

LLVM IR (-O2):
@.str = [61 x i8] c"Warning: crypt operation returned with unexpected length %d\0A\00"
define void @cryptData(i8* %0, i8* %1, i8 signext %2, i8* %3, i32 %4) {
%6 = zext i32 %4 to i64
%7 = alloca i8, i64 %6
%8 = alloca i8, i64 %6
%9 = alloca i8, i64 %6
%10 = call i32 @slv_to_uchar(i8* %0, i8* %7, i32 %4)
%11 = call i32 @slv_to_uchar(i8* %1, i8* %8, i32 %4)
%12 = icmp eq i8 %2, 0
br i1 %12, label %15, label %13
13: ; preds = %5
%14 = call i32 @encrypt(i8* %7, i32 %4, i8* %8, i8* %9)
br label %17
15: ; preds = %5
%16 = call i32 @decrypt(i8* %7, i32 %4, i8* %8, i8* %9)
br label %17
17: ; preds = %15, %13
%18 = phi i32 [ %14, %13 ], [ %16, %15 ]
%19 = icmp eq i32 %18, 8
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %22
22: ; preds = %20, %17
%23 = call i32 @uchar_to_slv(i8* %9, i8* %3, i32 %4)
ret void
}