#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*/ BIO_dump_fp(int /*<<< orphan*/, char const *, size_t);
size_t cryptoshit_decrypt(unsigned char **, void *, size_t, char *, size_t);
int /*<<< orphan*/ cryptoshit_encrypt(unsigned char **, char *, size_t, void *,
                                      size_t);
int /*<<< orphan*/ cryptoshit_init();
int /*<<< orphan*/ cryptoshit_secrete_key(char *, unsigned char **, int);
void *malloc(size_t);
int /*<<< orphan*/ memset(void *, int, size_t);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdout;
int strlen(char *);
int main(int argc, char *argv[]) {
  cryptoshit_init();
  char *password = "this is where the password goes";
  unsigned char *key[32];
  cryptoshit_secrete_key(password, key, 32);
  printf("derived key from password '%s':\n", password);
  BIO_dump_fp(stdout, (const char *)key, 32);
  char *inTxt =
      "A spectre is haunting Europe — the spectre of communism. All the powers "
      "of old Europe have entered into a holy alliance to exorcise this "
      "spectre: Pope and Tsar, Metternich and Guizot, French Radicals and "
      "German police-spies.\nWhere is the party in opposition that has not "
      "been decried as communistic by its opponents in power? Where is the "
      "opposition that has not hurled back the branding reproach of communism, "
      "against the more advanced opposition parties, as well as against its "
      "reactionary adversaries?\nTwo things result from this fact:\n\tI. "
      "Communism is already acknowledged by all European powers to be itself a "
      "power.\n\tII. It is high time that Communists should openly, in the "
      "face of the whole world, publish their views, their aims, their "
      "tendencies, and meet this nursery tale of the Spectre of Communism with "
      "a manifesto of the party itself.\nTo this end, Communists of various "
      "nationalities have assembled in London and sketched the following "
      "manifesto, to be published in the English, French, German, Italian, "
      "Flemish and Danish languages.";
  size_t inSz = strlen(inTxt) + 1;
  size_t outTxtSz = 2048;
  char *outTxt = (char *)malloc(outTxtSz);
  memset(outTxt, 0x00, outTxtSz);
  size_t cryptoBufSz = 2048;
  void *cryptoBuf = malloc(cryptoBufSz);
  memset(cryptoBuf, 0x00, cryptoBufSz);
  cryptoshit_encrypt(key, inTxt, inSz, cryptoBuf, cryptoBufSz);
  printf("%p bytes of plaintext\n", (void *)inSz);
  BIO_dump_fp(stdout, (const char *)cryptoBuf, cryptoBufSz);
  size_t actuallyDecrypted = 0;
  actuallyDecrypted =
      cryptoshit_decrypt(key, cryptoBuf, cryptoBufSz, outTxt, outTxtSz);
  outTxt[actuallyDecrypted] = 0x00;
  printf("%s", outTxt);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10a0 <cryptoshit_init@plt>
lea    0xe50(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x20,%edx
call   1070 <cryptoshit_secrete_key@plt>
mov    -0x18(%rbp),%rsi
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rsi
mov    $0x20,%edx
call   10b0 <BIO_dump_fp@plt>
lea    0xe47(%rip),%rax
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x130(%rbp)
movq   $0x800,-0x138(%rbp)
mov    -0x138(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x140(%rbp)
mov    -0x140(%rbp),%rdi
mov    -0x138(%rbp),%rdx
xor    %esi,%esi
call   1060 <memset@plt>
movq   $0x800,-0x148(%rbp)
mov    -0x148(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x150(%rbp)
mov    -0x150(%rbp),%rdi
mov    -0x148(%rbp),%rdx
xor    %esi,%esi
call   1060 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
mov    -0x130(%rbp),%rdx
mov    -0x150(%rbp),%rcx
mov    -0x148(%rbp),%r8
call   1080 <cryptoshit_encrypt@plt>
mov    -0x130(%rbp),%rsi
lea    0x11a7(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
mov    -0x150(%rbp),%rsi
mov    -0x148(%rbp),%rdx
call   10b0 <BIO_dump_fp@plt>
movq   $0x0,-0x158(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x150(%rbp),%rsi
mov    -0x148(%rbp),%rdx
mov    -0x140(%rbp),%rcx
mov    -0x138(%rbp),%r8
call   1050 <cryptoshit_decrypt@plt>
mov    %rax,-0x158(%rbp)
mov    -0x140(%rbp),%rax
mov    -0x158(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x140(%rbp),%rsi
lea    0x1143(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
xor    %eax,%eax
call   10a0 <cryptoshit_init@plt>
lea    0xe51(%rip),%rbx
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x20,%edx
call   1070 <cryptoshit_secrete_key@plt>
lea    0xe57(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x2e08(%rip),%rbp
mov    0x0(%rbp),%edi
mov    $0x20,%edx
mov    %r14,%rsi
call   10b0 <BIO_dump_fp@plt>
lea    0xe52(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%r12
mov    $0x800,%edi
call   1090 <malloc@plt>
mov    %rax,%r13
mov    $0x800,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0x800,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    $0x800,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0x800,%r8d
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1080 <cryptoshit_encrypt@plt>
lea    0x1209(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    0x0(%rbp),%edi
mov    $0x800,%edx
mov    %rbx,%rsi
call   10b0 <BIO_dump_fp@plt>
mov    $0x800,%edx
mov    $0x800,%r8d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r13,%rcx
call   1050 <cryptoshit_decrypt@plt>
movb   $0x0,0x0(%r13,%rax,1)
lea    0x11e2(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"this is where the password goes\00"
@.str.1 = [33 x i8] c"derived key from password '%s':\0A\00"
@stdout = global i32 0
@.str.2 = [1051 x i8] c"A spectre is haunting Europe \E2\80\94 the spectre of communism. All the powers of old Europe have entered into a holy alliance to exorcise this spectre: Pope and Tsar, Metternich and Guizot, French Radicals and German police-spies.\0AWhere is the party in opposition that has not been decried as communistic by its opponents in power? Where is the opposition that has not hurled back the branding reproach of communism, against the more advanced opposition parties, as well as against its reactionary adversaries?\0ATwo things result from this fact:\0A\09I. Communism is already acknowledged by all European powers to be itself a power.\0A\09II. It is high time that Communists should openly, in the face of the whole world, publish their views, their aims, their tendencies, and meet this nursery tale of the Spectre of Communism with a manifesto of the party itself.\0ATo this end, Communists of various nationalities have assembled in London and sketched the following manifesto, to be published in the English, French, German, Italian, Flemish and Danish languages.\00"
@.str.3 = [23 x i8] c"%p bytes of plaintext\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca [32 x i8*]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%14 = call i32 (...) @cryptoshit_init()
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8** %5
%15 = load i8*, i8** %5
%16 = getelementptr inbounds [32 x i8*], [32 x i8*]* %6, i64 0, i64 0
%17 = call i32 @cryptoshit_secrete_key(i8* %15, i8** %16, i32 32)
%18 = load i8*, i8** %5
%19 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @stdout
%21 = getelementptr inbounds [32 x i8*], [32 x i8*]* %6, i64 0, i64 0
%22 = bitcast i8** %21 to i8*
%23 = call i32 @BIO_dump_fp(i32 %20, i8* %22, i64 32)
store i8* getelementptr inbounds ([1051 x i8], [1051 x i8]* @.str.2, i64 0, i64 0), i8** %7
%24 = load i8*, i8** %7
%25 = call i32 @strlen(i8* %24)
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
store i64 %27, i64* %8
store i64 2048, i64* %9
%28 = load i64, i64* %9
%29 = call i8* @malloc(i64 %28)
store i8* %29, i8** %10
%30 = load i8*, i8** %10
%31 = load i64, i64* %9
%32 = call i32 @memset(i8* %30, i32 0, i64 %31)
store i64 2048, i64* %11
%33 = load i64, i64* %11
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %12
%35 = load i8*, i8** %12
%36 = load i64, i64* %11
%37 = call i32 @memset(i8* %35, i32 0, i64 %36)
%38 = getelementptr inbounds [32 x i8*], [32 x i8*]* %6, i64 0, i64 0
%39 = load i8*, i8** %7
%40 = load i64, i64* %8
%41 = load i8*, i8** %12
%42 = load i64, i64* %11
%43 = call i32 @cryptoshit_encrypt(i8** %38, i8* %39, i64 %40, i8* %41, i64 %42)
%44 = load i64, i64* %8
%45 = inttoptr i64 %44 to i8*
%46 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @stdout
%48 = load i8*, i8** %12
%49 = load i64, i64* %11
%50 = call i32 @BIO_dump_fp(i32 %47, i8* %48, i64 %49)
store i64 0, i64* %13
%51 = getelementptr inbounds [32 x i8*], [32 x i8*]* %6, i64 0, i64 0
%52 = load i8*, i8** %12
%53 = load i64, i64* %11
%54 = load i8*, i8** %10
%55 = load i64, i64* %9
%56 = call i64 @cryptoshit_decrypt(i8** %51, i8* %52, i64 %53, i8* %54, i64 %55)
store i64 %56, i64* %13
%57 = load i8*, i8** %10
%58 = load i64, i64* %13
%59 = getelementptr inbounds i8, i8* %57, i64 %58
store i8 0, i8* %59
%60 = load i8*, i8** %10
%61 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"this is where the password goes\00"
@.str.1 = [33 x i8] c"derived key from password '%s':\0A\00"
@stdout = global i32 0
@.str.2 = [1051 x i8] c"A spectre is haunting Europe \E2\80\94 the spectre of communism. All the powers of old Europe have entered into a holy alliance to exorcise this spectre: Pope and Tsar, Metternich and Guizot, French Radicals and German police-spies.\0AWhere is the party in opposition that has not been decried as communistic by its opponents in power? Where is the opposition that has not hurled back the branding reproach of communism, against the more advanced opposition parties, as well as against its reactionary adversaries?\0ATwo things result from this fact:\0A\09I. Communism is already acknowledged by all European powers to be itself a power.\0A\09II. It is high time that Communists should openly, in the face of the whole world, publish their views, their aims, their tendencies, and meet this nursery tale of the Spectre of Communism with a manifesto of the party itself.\0ATo this end, Communists of various nationalities have assembled in London and sketched the following manifesto, to be published in the English, French, German, Italian, Flemish and Danish languages.\00"
@.str.3 = [23 x i8] c"%p bytes of plaintext\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i8*]
%4 = tail call i32 (...) @cryptoshit_init()
%5 = bitcast [32 x i8*]* %3 to i8*
%6 = getelementptr inbounds [32 x i8*], [32 x i8*]* %3, i64 0, i64 0
%7 = call i32 @cryptoshit_secrete_key(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8** %6, i32 32)
%8 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stdout
%10 = call i32 @BIO_dump_fp(i32 %9, i8* %5, i64 32)
%11 = call i32 @strlen(i8* getelementptr inbounds ([1051 x i8], [1051 x i8]* @.str.2, i64 0, i64 0))
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = call dereferenceable_or_null(2048) i8* @malloc(i64 2048)
%15 = call i32 @memset(i8* %14, i32 0, i64 2048)
%16 = call dereferenceable_or_null(2048) i8* @malloc(i64 2048)
%17 = call i32 @memset(i8* %16, i32 0, i64 2048)
%18 = call i32 @cryptoshit_encrypt(i8** %6, i8* getelementptr inbounds ([1051 x i8], [1051 x i8]* @.str.2, i64 0, i64 0), i64 %13, i8* %16, i64 2048)
%19 = inttoptr i64 %13 to i8*
%20 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @stdout
%22 = call i32 @BIO_dump_fp(i32 %21, i8* %16, i64 2048)
%23 = call i64 @cryptoshit_decrypt(i8** %6, i8* %16, i64 2048, i8* %14, i64 2048)
%24 = getelementptr inbounds i8, i8* %14, i64 %23
store i8 0, i8* %24
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %14)
ret i32 0
}