#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*/ X509;
typedef int /*<<< orphan*/ RSA;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ EVP_PKEY;

/* Variables and functions */
int /*<<< orphan*/ *EVP_PKEY_new();
int /*<<< orphan*/ EVP_PKEY_set1_RSA(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_sha256();
int /*<<< orphan*/
PEM_write_RSAPrivateKey(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                        int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                        int /*<<< orphan*/, int /*<<< orphan*/ *,
                        int /*<<< orphan*/ *);
int /*<<< orphan*/ PEM_write_X509(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ RSA_F4;
int /*<<< orphan*/ *RSA_generate_key(int, int /*<<< orphan*/,
                                     int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *makeselfcert(int /*<<< orphan*/ *, int, char *,
                                 int /*<<< orphan*/);
void makersacert(int days, char *commonname, int bits) {
  RSA *key;
  EVP_PKEY *pkey;
  X509 *x;
  FILE *out;
  key = RSA_generate_key(bits, RSA_F4, NULL, NULL);
  pkey = EVP_PKEY_new();
  EVP_PKEY_set1_RSA(pkey, key);
  x = makeselfcert(pkey, days, commonname, EVP_sha256());
  out = fopen("rsa_cert.pem", "w");
  if (out == NULL)
    exit(-1);
  PEM_write_X509(out, x);
  fclose(out);
  out = fopen("rsa_cert_key.pem", "w");
  if (out == NULL)
    exit(-1);
  PEM_write_RSAPrivateKey(out, key, NULL, NULL, 0, NULL, NULL);
  fclose(out);
}


x86 assembly (clang, -O0):
<makersacert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   10b0 <RSA_generate_key@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <EVP_PKEY_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10c0 <EVP_PKEY_set1_RSA@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   10a0 <EVP_sha256@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    %eax,%ecx
call   1050 <makeselfcert@plt>
mov    %rax,-0x30(%rbp)
lea    0xde0(%rip),%rdi
lea    0xde6(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1245 <makersacert+0xa5>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <PEM_write_X509@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdad(%rip),%rdi
lea    0xda4(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1287 <makersacert+0xe7>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r9d
xor    %r8d,%r8d
mov    %r9,%rdx
mov    %r9,%rcx
movq   $0x0,(%rsp)
call   1030 <PEM_write_RSAPrivateKey@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makersacert>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
mov    %edx,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   10b0 <RSA_generate_key@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1070 <EVP_PKEY_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   10c0 <EVP_PKEY_set1_RSA@plt>
xor    %eax,%eax
call   10a0 <EVP_sha256@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %eax,%ecx
call   1050 <makeselfcert@plt>
mov    %rax,%rbx
lea    0xe08(%rip),%rdi
lea    0xe0e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1269 <makersacert+0xc9>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1060 <PEM_write_X509@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xde9(%rip),%rdi
lea    0xde0(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1269 <makersacert+0xc9>
mov    %rax,%rbx
movq   $0x0,(%rsp)
mov    %rax,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <PEM_write_RSAPrivateKey@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@RSA_F4 = global i32 0
@.str = [13 x i8] c"rsa_cert.pem\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [17 x i8] c"rsa_cert_key.pem\00"
define void @makersacert(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = load i32, i32* @RSA_F4
%13 = call i32* @RSA_generate_key(i32 %11, i32 %12, i32* null, i32* null)
store i32* %13, i32** %7
%14 = call i32* (...) @EVP_PKEY_new()
store i32* %14, i32** %8
%15 = load i32*, i32** %8
%16 = load i32*, i32** %7
%17 = call i32 @EVP_PKEY_set1_RSA(i32* %15, i32* %16)
%18 = load i32*, i32** %8
%19 = load i32, i32* %4
%20 = load i8*, i8** %5
%21 = call i32 (...) @EVP_sha256()
%22 = call i32* @makeselfcert(i32* %18, i32 %19, i8* %20, i32 %21)
store i32* %22, i32** %9
%23 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %10
%24 = load i32*, i32** %10
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %3
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %3
%29 = load i32*, i32** %10
%30 = load i32*, i32** %9
%31 = call i32 @PEM_write_X509(i32* %29, i32* %30)
%32 = load i32*, i32** %10
%33 = call i32 @fclose(i32* %32)
%34 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %34, i32** %10
%35 = load i32*, i32** %10
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %39
37: ; preds = %28
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %28
%40 = load i32*, i32** %10
%41 = load i32*, i32** %7
%42 = call i32 @PEM_write_RSAPrivateKey(i32* %40, i32* %41, i32* null, i32* null, i32 0, i32* null, i32* null)
%43 = load i32*, i32** %10
%44 = call i32 @fclose(i32* %43)
ret void
}

LLVM IR (-O2):
@RSA_F4 = global i32 0
@.str = [13 x i8] c"rsa_cert.pem\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [17 x i8] c"rsa_cert_key.pem\00"
define void @makersacert(i32 %0, i8* %1, i32 %2) {
%4 = load i32, i32* @RSA_F4
%5 = tail call i32* @RSA_generate_key(i32 %2, i32 %4, i32* null, i32* null)
%6 = tail call i32* (...) @EVP_PKEY_new()
%7 = tail call i32 @EVP_PKEY_set1_RSA(i32* %6, i32* %5)
%8 = tail call i32 (...) @EVP_sha256()
%9 = tail call i32* @makeselfcert(i32* %6, i32 %0, i8* %1, i32 %8)
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %3
%15 = tail call i32 @PEM_write_X509(i32* %10, i32* %9)
%16 = tail call i32 @fclose(i32* %10)
%17 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %14
%22 = tail call i32 @PEM_write_RSAPrivateKey(i32* %17, i32* %5, i32* null, i32* null, i32 0, i32* null, i32* null)
%23 = tail call i32 @fclose(i32* %17)
ret void
}