#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 crypt(char, unsigned char *, int, unsigned char *);
int finalize(char);
int /*<<< orphan*/ init(unsigned char *, unsigned char *, 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 *iv, char mode, char start,
               char final, char *dataout, int bytelen) {
  int crypt_len;
  unsigned char c_din[bytelen];
  unsigned char c_key[bytelen];
  unsigned char c_iv[bytelen];
  unsigned char c_dout[bytelen];
  slv_to_uchar(datain, c_din, bytelen);
  slv_to_uchar(key, c_key, bytelen);
  slv_to_uchar(iv, c_iv, bytelen);
  if (start) {
    init(c_key, c_iv, mode);
  }
  crypt_len = crypt(mode, c_din, bytelen, c_dout);
  if (crypt_len != bytelen) {
    printf("Warning: encrypt() returned with unexpected length %d\n",
           crypt_len);
  }
  if (final) {
    crypt_len = finalize(mode);
    if (crypt_len != 0) {
      printf("Warning: finalize() 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    $0x80,%rsp
mov    %r8d,-0x80(%rbp)
mov    %ecx,%eax
mov    -0x80(%rbp),%ecx
mov    %eax,-0x7c(%rbp)
mov    %rdx,%rax
mov    -0x7c(%rbp),%edx
mov    %rax,-0x78(%rbp)
mov    %rsi,%rax
mov    -0x78(%rbp),%rsi
mov    %rax,-0x70(%rbp)
mov    %rdi,%r8
mov    -0x70(%rbp),%rdi
mov    %r9b,%al
mov    0x18(%rbp),%r9d
mov    0x10(%rbp),%r9
mov    %r8,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %dl,-0x19(%rbp)
mov    %cl,-0x1a(%rbp)
mov    %al,-0x1b(%rbp)
mov    0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x68(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x30(%rbp)
mov    0x18(%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,-0x38(%rbp)
mov    0x18(%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    0x18(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x18(%rbp),%edx
call   1030 <slv_to_uchar@plt>
mov    -0x58(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    0x18(%rbp),%edx
call   1030 <slv_to_uchar@plt>
mov    -0x50(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    0x18(%rbp),%edx
call   1030 <slv_to_uchar@plt>
cmpb   $0x0,-0x1a(%rbp)
je     127d <cryptData+0x11d>
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rdi
movsbl -0x19(%rbp),%edx
call   1080 <init@plt>
mov    -0x60(%rbp),%rcx
mov    -0x68(%rbp),%rsi
mov    -0x19(%rbp),%al
mov    0x18(%rbp),%edx
movsbl %al,%edi
call   1040 <crypt@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    0x18(%rbp),%eax
je     12b1 <cryptData+0x151>
mov    -0x20(%rbp),%esi
lea    0xd54(%rip),%rdi
call   1050 <printf@plt>
cmpb   $0x0,-0x1b(%rbp)
je     12e5 <cryptData+0x185>
movsbl -0x19(%rbp),%edi
call   1060 <finalize@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     12e0 <cryptData+0x180>
mov    -0x20(%rbp),%esi
lea    0xd5c(%rip),%rdi
call   1050 <printf@plt>
jmp    12e5 <cryptData+0x185>
mov    -0x60(%rbp),%rdi
mov    0x10(%rbp),%rsi
mov    0x18(%rbp),%edx
call   1070 <uchar_to_slv@plt>
mov    -0x28(%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    $0x28,%rsp
mov    %r9d,-0x34(%rbp)
mov    %r8d,-0x30(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    %rdx,-0x48(%rbp)
mov    %rsi,-0x40(%rbp)
mov    0x18(%rbp),%r13d
mov    %rsp,%r14
mov    %r13,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r14,%rsi
mov    %r13d,%edx
call   1030 <slv_to_uchar@plt>
mov    -0x40(%rbp),%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   1030 <slv_to_uchar@plt>
mov    -0x48(%rbp),%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1030 <slv_to_uchar@plt>
movsbl -0x2c(%rbp),%r13d
cmpb   $0x0,-0x30(%rbp)
je     11f9 <cryptData+0x99>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1080 <init@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    0x18(%rbp),%r15d
mov    %r15d,%edx
mov    %rbx,%rcx
call   1040 <crypt@plt>
cmp    %r15d,%eax
je     1221 <cryptData+0xc1>
lea    0xde6(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    0x10(%rbp),%r14
cmpb   $0x0,-0x34(%rbp)
je     1245 <cryptData+0xe5>
mov    %r13d,%edi
call   1060 <finalize@plt>
test   %eax,%eax
je     1245 <cryptData+0xe5>
lea    0xdf9(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%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

LLVM IR (-O0):
@.str = [55 x i8] c"Warning: encrypt() returned with unexpected length %d\0A\00"
@.str.1 = [56 x i8] c"Warning: finalize() returned with unexpected length %d\0A\00"
define void @cryptData(i8* %0, i8* %1, i8* %2, i8 signext %3, i8 signext %4, i8 signext %5, i8* %6, i32 %7) {
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8
%13 = alloca i8
%14 = alloca i8
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i64
%20 = alloca i64
%21 = alloca i64
%22 = alloca i64
store i8* %0, i8** %9
store i8* %1, i8** %10
store i8* %2, i8** %11
store i8 %3, i8* %12
store i8 %4, i8* %13
store i8 %5, i8* %14
store i8* %6, i8** %15
store i32 %7, i32* %16
%23 = load i32, i32* %16
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %18
%26 = alloca i8, i64 %24
store i64 %24, i64* %19
%27 = load i32, i32* %16
%28 = zext i32 %27 to i64
%29 = alloca i8, i64 %28
store i64 %28, i64* %20
%30 = load i32, i32* %16
%31 = zext i32 %30 to i64
%32 = alloca i8, i64 %31
store i64 %31, i64* %21
%33 = load i32, i32* %16
%34 = zext i32 %33 to i64
%35 = alloca i8, i64 %34
store i64 %34, i64* %22
%36 = load i8*, i8** %9
%37 = load i32, i32* %16
%38 = call i32 @slv_to_uchar(i8* %36, i8* %26, i32 %37)
%39 = load i8*, i8** %10
%40 = load i32, i32* %16
%41 = call i32 @slv_to_uchar(i8* %39, i8* %29, i32 %40)
%42 = load i8*, i8** %11
%43 = load i32, i32* %16
%44 = call i32 @slv_to_uchar(i8* %42, i8* %32, i32 %43)
%45 = load i8, i8* %13
%46 = icmp ne i8 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %8
%48 = load i8, i8* %12
%49 = call i32 @init(i8* %29, i8* %32, i8 signext %48)
br label %50
50: ; preds = %47, %8
%51 = load i8, i8* %12
%52 = load i32, i32* %16
%53 = call i32 @crypt(i8 signext %51, i8* %26, i32 %52, i8* %35)
store i32 %53, i32* %17
%54 = load i32, i32* %17
%55 = load i32, i32* %16
%56 = icmp ne i32 %54, %55
br i1 %56, label %57, label %60
57: ; preds = %50
%58 = load i32, i32* %17
%59 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %57, %50
%61 = load i8, i8* %14
%62 = icmp ne i8 %61, 0
br i1 %62, label %63, label %72
63: ; preds = %60
%64 = load i8, i8* %12
%65 = call i32 @finalize(i8 signext %64)
store i32 %65, i32* %17
%66 = load i32, i32* %17
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = load i32, i32* %17
%70 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %68, %63
br label %72
72: ; preds = %71, %60
%73 = load i8*, i8** %15
%74 = load i32, i32* %16
%75 = call i32 @uchar_to_slv(i8* %35, i8* %73, i32 %74)
%76 = load i8*, i8** %18
ret void
}

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