#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
char *malloc(int);
scalar_t__ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char const *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
size_t strcspn(char *, char *);
char *rsa_decrypt_msg(const char *priv_key_path, const char *enc_msg) {
  char cmd[(512)];
  char *dec_msg = malloc((1024) * sizeof(char));
  sprintf(cmd,
          "echo \"%s\" | openssl enc -base64 -A -d | "
          "openssl rsautl -decrypt -inkey %s",
          enc_msg, priv_key_path);
  FILE *dec_msg_stream = popen((const char *)cmd, "r");
  if (fgets(dec_msg, (1024), dec_msg_stream) != NULL) {
    dec_msg[strcspn(dec_msg, "\n")] = '\0';
  }
  if (pclose(dec_msg_stream) != 0) {
    fprintf(stderr,
            "[ERROR] Could not decrypt the message using the "
            "private rsa key: %s\n[ERROR] Exiting\n",
            priv_key_path);
    exit(-1);
  }
  return dec_msg;
}


x86 assembly (clang, -O0):
<rsa_decrypt_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe46(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x210(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x220(%rbp)
mov    -0x218(%rbp),%rdi
mov    -0x220(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     122a <rsa_decrypt_msg+0xaa>
mov    -0x218(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x218(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,%rcx
mov    -0x228(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x220(%rbp),%rdi
call   1030 <pclose@plt>
cmp    $0x0,%rax
je     1263 <rsa_decrypt_msg+0xe3>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdf8(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x218(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsa_decrypt_msg>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0xe58(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1090 <sprintf@plt>
lea    0xe8a(%rip),%rsi
mov    %r12,%rdi
call   1080 <popen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f4 <rsa_decrypt_msg+0x74>
lea    0xeb8(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcspn@plt>
movb   $0x0,(%r15,%rax,1)
mov    %rbx,%rdi
call   1030 <pclose@plt>
test   %rax,%rax
jne    1213 <rsa_decrypt_msg+0x93>
mov    %r15,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [74 x i8] c"echo \22%s\22 | openssl enc -base64 -A -d | openssl rsautl -decrypt -inkey %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.3 = [85 x i8] c"[ERROR] Could not decrypt the message using the private rsa key: %s\0A[ERROR] Exiting\0A\00"
define i8* @rsa_decrypt_msg(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [512 x i8]
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = call i8* @malloc(i32 1024)
store i8* %8, i8** %6
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = load i8*, i8** %3
%12 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11)
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%14 = call i32* @popen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %7
%15 = load i8*, i8** %6
%16 = load i32*, i32** %7
%17 = call i32* @fgets(i8* %15, i32 1024, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i8*, i8** %6
%21 = load i8*, i8** %6
%22 = call i64 @strcspn(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %19, %2
%25 = load i32*, i32** %7
%26 = call i64 @pclose(i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %3
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %24
%34 = load i8*, i8** %6
ret i8* %34
}

LLVM IR (-O2):
@.str = [74 x i8] c"echo \22%s\22 | openssl enc -base64 -A -d | openssl rsautl -decrypt -inkey %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.3 = [85 x i8] c"[ERROR] Could not decrypt the message using the private rsa key: %s\0A[ERROR] Exiting\0A\00"
define i8* @rsa_decrypt_msg(i8* %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0)
%7 = call i32* @popen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32* @fgets(i8* %5, i32 1024, i32* %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = tail call i64 @strcspn(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds i8, i8* %5, i64 %11
store i8 0, i8* %12
br label %13
13: ; preds = %10, %2
%14 = tail call i64 @pclose(i32* %7)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %13
ret i8* %5
}