#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 encrypt(unsigned char *, int, unsigned char *);
int finalize();
int /*<<< orphan*/ init(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 *iv, 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);
  }
  crypt_len = encrypt(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();
    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    %r8b,%al
mov    0x10(%rbp),%r8d
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %cl,-0x19(%rbp)
mov    %al,-0x1a(%rbp)
mov    %r9,-0x28(%rbp)
mov    0x10(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x78(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x40(%rbp)
mov    0x10(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    0x10(%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,-0x50(%rbp)
mov    0x10(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x10(%rbp),%edx
call   1030 <slv_to_uchar@plt>
mov    -0x68(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    0x10(%rbp),%edx
call   1030 <slv_to_uchar@plt>
mov    -0x60(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    0x10(%rbp),%edx
call   1030 <slv_to_uchar@plt>
cmpb   $0x0,-0x19(%rbp)
je     124e <cryptData+0xee>
mov    -0x60(%rbp),%rsi
mov    -0x68(%rbp),%rdi
call   1080 <init@plt>
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rdi
mov    0x10(%rbp),%esi
call   1060 <encrypt@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    0x10(%rbp),%eax
je     127c <cryptData+0x11c>
mov    -0x2c(%rbp),%esi
lea    0xd89(%rip),%rdi
call   1040 <printf@plt>
cmpb   $0x0,-0x1a(%rbp)
je     12ae <cryptData+0x14e>
mov    $0x0,%al
call   1050 <finalize@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     12a9 <cryptData+0x149>
mov    -0x2c(%rbp),%esi
lea    0xd93(%rip),%rdi
call   1040 <printf@plt>
jmp    12ae <cryptData+0x14e>
mov    -0x70(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x10(%rbp),%edx
call   1070 <uchar_to_slv@plt>
mov    -0x38(%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    %r9,-0x48(%rbp)
mov    %r8d,-0x30(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %rsi,-0x38(%rbp)
mov    0x10(%rbp),%r12d
mov    %rsp,%r14
mov    %r12,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r14,%rsi
mov    %r12d,%edx
call   1030 <slv_to_uchar@plt>
mov    -0x38(%rbp),%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <slv_to_uchar@plt>
mov    -0x40(%rbp),%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1030 <slv_to_uchar@plt>
cmpb   $0x0,-0x2c(%rbp)
je     11f1 <cryptData+0x91>
mov    %r15,%rdi
mov    %r13,%rsi
call   1080 <init@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %rbx,%rdx
call   1060 <encrypt@plt>
cmp    %r12d,%eax
je     1212 <cryptData+0xb2>
lea    0xdf5(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
cmpb   $0x0,-0x30(%rbp)
je     1231 <cryptData+0xd1>
xor    %eax,%eax
call   1050 <finalize@plt>
test   %eax,%eax
je     1231 <cryptData+0xd1>
lea    0xe0d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    -0x48(%rbp),%rsi
mov    %r12d,%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* %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64
store i8* %0, i8** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i8 %3, i8* %11
store i8 %4, i8* %12
store i8* %5, i8** %13
store i32 %6, i32* %14
%21 = load i32, i32* %14
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %16
%24 = alloca i8, i64 %22
store i64 %22, i64* %17
%25 = load i32, i32* %14
%26 = zext i32 %25 to i64
%27 = alloca i8, i64 %26
store i64 %26, i64* %18
%28 = load i32, i32* %14
%29 = zext i32 %28 to i64
%30 = alloca i8, i64 %29
store i64 %29, i64* %19
%31 = load i32, i32* %14
%32 = zext i32 %31 to i64
%33 = alloca i8, i64 %32
store i64 %32, i64* %20
%34 = load i8*, i8** %8
%35 = load i32, i32* %14
%36 = call i32 @slv_to_uchar(i8* %34, i8* %24, i32 %35)
%37 = load i8*, i8** %9
%38 = load i32, i32* %14
%39 = call i32 @slv_to_uchar(i8* %37, i8* %27, i32 %38)
%40 = load i8*, i8** %10
%41 = load i32, i32* %14
%42 = call i32 @slv_to_uchar(i8* %40, i8* %30, i32 %41)
%43 = load i8, i8* %11
%44 = icmp ne i8 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %7
%46 = call i32 @init(i8* %27, i8* %30)
br label %47
47: ; preds = %45, %7
%48 = load i32, i32* %14
%49 = call i32 @encrypt(i8* %24, i32 %48, i8* %33)
store i32 %49, i32* %15
%50 = load i32, i32* %15
%51 = load i32, i32* %14
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = load i32, i32* %15
%55 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %53, %47
%57 = load i8, i8* %12
%58 = icmp ne i8 %57, 0
br i1 %58, label %59, label %67
59: ; preds = %56
%60 = call i32 (...) @finalize()
store i32 %60, i32* %15
%61 = load i32, i32* %15
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = load i32, i32* %15
%65 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %63, %59
br label %67
67: ; preds = %66, %56
%68 = load i8*, i8** %13
%69 = load i32, i32* %14
%70 = call i32 @uchar_to_slv(i8* %33, i8* %68, i32 %69)
%71 = load i8*, i8** %16
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* %5, i32 %6) {
%8 = zext i32 %6 to i64
%9 = alloca i8, i64 %8
%10 = alloca i8, i64 %8
%11 = alloca i8, i64 %8
%12 = alloca i8, i64 %8
%13 = call i32 @slv_to_uchar(i8* %0, i8* %9, i32 %6)
%14 = call i32 @slv_to_uchar(i8* %1, i8* %10, i32 %6)
%15 = call i32 @slv_to_uchar(i8* %2, i8* %11, i32 %6)
%16 = icmp eq i8 %3, 0
br i1 %16, label %19, label %17
17: ; preds = %7
%18 = call i32 @init(i8* %10, i8* %11)
br label %19
19: ; preds = %17, %7
%20 = call i32 @encrypt(i8* %9, i32 %6, i8* %12)
%21 = icmp eq i32 %20, %6
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %24
24: ; preds = %22, %19
%25 = icmp eq i8 %4, 0
br i1 %25, label %31, label %26
26: ; preds = %24
%27 = call i32 (...) @finalize()
%28 = icmp eq i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %31
31: ; preds = %26, %29, %24
%32 = call i32 @uchar_to_slv(i8* %12, i8* %5, i32 %6)
ret void
}