#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef scalar_t__ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ abort();
int encrypt(void *, size_t, void *, void *, void *);
int /*<<< orphan*/ generateIv(void *);
int /*<<< orphan*/ printf(char *, size_t, size_t);
__attribute__((visibility("default"))) void
cryptoshit_encrypt(void *key, void *in, size_t inSz, void *out, size_t outSz) {
  size_t inSzUp = (inSz & 0xF) ? ((inSz & (~0xF)) + 0xF) : inSz;
  size_t minOutSz = inSzUp + 16;
  if (outSz < minOutSz) {
    printf("ur stupid the out buffer must be %lu, it's actually %lu (kill "
           "urself)\n",
           minOutSz, outSz);
    abort();
  }
  void *iv = out;
  uint64_t *plainSzPtr = (uint64_t *)(((uint8_t *)iv) + 16);
  uint64_t *cryptoSzPtr = (uint64_t *)(((uint8_t *)plainSzPtr) + 8);
  void *cryptoText = ((uint8_t *)cryptoSzPtr) + 8;
  *plainSzPtr = (uint64_t)inSz;
  generateIv(iv);
  int bytesEncrypted = encrypt(in, inSz, key, iv, cryptoText);
  *cryptoSzPtr = (uint64_t)bytesEncrypted;
}


x86 assembly (clang, -O0):
<cryptoshit_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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
and    $0xf,%rax
cmp    $0x0,%rax
je     1183 <cryptoshit_encrypt+0x43>
mov    -0x18(%rbp),%rax
and    $0xfffffffffffffff0,%rax
add    $0xf,%rax
mov    %rax,-0x68(%rbp)
jmp    118b <cryptoshit_encrypt+0x4b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    11c8 <cryptoshit_encrypt+0x88>
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rdi
call   1060 <generateIv@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x58(%rbp),%r8
call   1050 <encrypt@plt>
mov    %eax,-0x5c(%rbp)
movslq -0x5c(%rbp),%rcx
mov    -0x50(%rbp),%rax
mov    %rcx,(%rax)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cryptoshit_encrypt>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdx,%rsi
or     $0xf,%rsi
test   $0xf,%bl
cmove  %rdx,%rsi
add    $0x10,%rsi
cmp    %r8,%rsi
ja     11a3 <cryptoshit_encrypt+0x63>
mov    %rcx,%r14
mov    %rdi,%r15
lea    0x80(%rcx),%r13
mov    %rbx,0x40(%rcx)
mov    %rcx,%rdi
call   1060 <generateIv@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %r13,%r8
call   1050 <encrypt@plt>
cltq
mov    %rax,0x60(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe56(%rip),%rdi
mov    %r8,%rdx
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [71 x i8] c"ur stupid the out buffer must be %lu, it's actually %lu (kill urself)\0A\00"
define void @cryptoshit_encrypt(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 i64
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i64*
%15 = alloca i64*
%16 = alloca i8*
%17 = alloca i32
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
%18 = load i64, i64* %8
%19 = and i64 %18, 15
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %5
%22 = load i64, i64* %8
%23 = and i64 %22, -16
%24 = add i64 %23, 15
br label %27
25: ; preds = %5
%26 = load i64, i64* %8
br label %27
27: ; preds = %25, %21
%28 = phi i64 [ %24, %21 ], [ %26, %25 ]
store i64 %28, i64* %11
%29 = load i64, i64* %11
%30 = add i64 %29, 16
store i64 %30, i64* %12
%31 = load i64, i64* %10
%32 = load i64, i64* %12
%33 = icmp ult i64 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %27
%35 = load i64, i64* %12
%36 = load i64, i64* %10
%37 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i64 %35, i64 %36)
%38 = call i32 (...) @abort()
unreachable
39: ; preds = %27
%40 = load i8*, i8** %9
store i8* %40, i8** %13
%41 = load i8*, i8** %13
%42 = bitcast i8* %41 to i32*
%43 = getelementptr inbounds i32, i32* %42, i64 16
%44 = bitcast i32* %43 to i64*
store i64* %44, i64** %14
%45 = load i64*, i64** %14
%46 = bitcast i64* %45 to i32*
%47 = getelementptr inbounds i32, i32* %46, i64 8
%48 = bitcast i32* %47 to i64*
store i64* %48, i64** %15
%49 = load i64*, i64** %15
%50 = bitcast i64* %49 to i32*
%51 = getelementptr inbounds i32, i32* %50, i64 8
%52 = bitcast i32* %51 to i8*
store i8* %52, i8** %16
%53 = load i64, i64* %8
%54 = load i64*, i64** %14
store i64 %53, i64* %54
%55 = load i8*, i8** %13
%56 = call i32 @generateIv(i8* %55)
%57 = load i8*, i8** %7
%58 = load i64, i64* %8
%59 = load i8*, i8** %6
%60 = load i8*, i8** %13
%61 = load i8*, i8** %16
%62 = call i32 @encrypt(i8* %57, i64 %58, i8* %59, i8* %60, i8* %61)
store i32 %62, i32* %17
%63 = load i32, i32* %17
%64 = sext i32 %63 to i64
%65 = load i64*, i64** %15
store i64 %64, i64* %65
ret void
}

LLVM IR (-O2):
@.str = [71 x i8] c"ur stupid the out buffer must be %lu, it's actually %lu (kill urself)\0A\00"
define void @cryptoshit_encrypt(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = and i64 %2, 15
%7 = icmp eq i64 %6, 0
%8 = or i64 %2, 15
%9 = select i1 %7, i64 %2, i64 %8
%10 = add i64 %9, 16
%11 = icmp ugt i64 %10, %4
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = tail call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i64 %10, i64 %4)
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %5
%16 = getelementptr inbounds i8, i8* %3, i64 64
%17 = bitcast i8* %16 to i64*
%18 = getelementptr inbounds i8, i8* %3, i64 96
%19 = bitcast i8* %18 to i64*
%20 = getelementptr inbounds i8, i8* %3, i64 128
store i64 %2, i64* %17
%21 = tail call i32 @generateIv(i8* %3)
%22 = tail call i32 @encrypt(i8* %1, i64 %2, i8* %0, i8* %3, i8* %20)
%23 = sext i32 %22 to i64
store i64 %23, i64* %19
ret void
}