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

/* Variables and functions */
int /*<<< orphan*/ ASN1_INTEGER_set(int /*<<< orphan*/, int);
int /*<<< orphan*/ EVP_PKEY_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_CTX_new_id(int /*<<< orphan*/,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_PKEY_CTX_set_rsa_keygen_bits(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ EVP_PKEY_RSA;
int /*<<< orphan*/ EVP_PKEY_keygen(int /*<<< orphan*/ *, int /*<<< orphan*/ **);
int /*<<< orphan*/ EVP_PKEY_keygen_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_sha256();
int /*<<< orphan*/ MBSTRING_ASC;
int /*<<< orphan*/ X509_NAME_add_entry_by_txt(int /*<<< orphan*/ *, char *,
                                              int /*<<< orphan*/,
                                              unsigned char const *, int, int,
                                              int /*<<< orphan*/);
int /*<<< orphan*/ X509_get_notAfter(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_get_notBefore(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_get_serialNumber(int /*<<< orphan*/ *);
int /*<<< orphan*/ *X509_get_subject_name(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_gmtime_adj(int /*<<< orphan*/, int);
int /*<<< orphan*/ *X509_new();
int /*<<< orphan*/ X509_set_issuer_name(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_set_pubkey(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_set_version(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ X509_sign(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                             int /*<<< orphan*/);
void mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int years) {
  X509 *cert = X509_new();
  EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL);
  EVP_PKEY_keygen_init(ctx);
  EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits);
  EVP_PKEY *pk = NULL;
  EVP_PKEY_keygen(ctx, &pk);
  EVP_PKEY_CTX_free(ctx);
  X509_set_version(cert, 2);
  ASN1_INTEGER_set(X509_get_serialNumber(cert), serial);
  X509_gmtime_adj(X509_get_notBefore(cert), 0);
  X509_gmtime_adj(X509_get_notAfter(cert), 60 * 60 * 24 * 365 * years);
  X509_set_pubkey(cert, pk);
  X509_NAME *name = X509_get_subject_name(cert);
  X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC,
                             (const unsigned char *)"NVIDIA GameStream Client",
                             -1, -1, 0);
  X509_set_issuer_name(cert, name);
  X509_sign(cert, pk, EVP_sha256());
  *x509p = cert;
  *pkeyp = pk;
}


x86 assembly (clang, -O0):
<mkcert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    $0x0,%al
call   1140 <X509_new@plt>
mov    %rax,-0x28(%rbp)
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   10d0 <EVP_PKEY_CTX_new_id@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1110 <EVP_PKEY_keygen_init@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10c0 <EVP_PKEY_CTX_set_rsa_keygen_bits@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <EVP_PKEY_keygen@plt>
mov    -0x30(%rbp),%rdi
call   1130 <EVP_PKEY_CTX_free@plt>
mov    -0x28(%rbp),%rdi
mov    $0x2,%esi
call   1050 <X509_set_version@plt>
mov    -0x28(%rbp),%rdi
call   1090 <X509_get_serialNumber@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%esi
call   10a0 <ASN1_INTEGER_set@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <X509_get_notBefore@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1030 <X509_gmtime_adj@plt>
mov    -0x28(%rbp),%rdi
call   1060 <X509_get_notAfter@plt>
mov    %eax,%edi
imul   $0x1e13380,-0x1c(%rbp),%esi
call   1030 <X509_gmtime_adj@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10f0 <X509_set_pubkey@plt>
mov    -0x28(%rbp),%rdi
call   1070 <X509_get_subject_name@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2ce3(%rip),%rax
mov    (%rax),%edx
lea    0xcfa(%rip),%rsi
lea    0xcf6(%rip),%rcx
mov    $0xffffffff,%r9d
xor    %eax,%eax
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   10e0 <X509_NAME_add_entry_by_txt@plt>
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1080 <X509_set_issuer_name@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1120 <EVP_sha256@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1100 <X509_sign@plt>
mov    -0x28(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkcert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r12d
mov    %ecx,%r13d
mov    %edx,%ebp
mov    %rsi,0x10(%rsp)
mov    %rdi,%r15
xor    %eax,%eax
call   1140 <X509_new@plt>
mov    %rax,%rbx
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   10d0 <EVP_PKEY_CTX_new_id@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1110 <EVP_PKEY_keygen_init@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   10c0 <EVP_PKEY_CTX_set_rsa_keygen_bits@plt>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <EVP_PKEY_keygen@plt>
mov    %r14,%rdi
call   1130 <EVP_PKEY_CTX_free@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1050 <X509_set_version@plt>
mov    %rbx,%rdi
call   1090 <X509_get_serialNumber@plt>
mov    %eax,%edi
mov    %r13d,%esi
call   10a0 <ASN1_INTEGER_set@plt>
mov    %rbx,%rdi
call   10b0 <X509_get_notBefore@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1030 <X509_gmtime_adj@plt>
mov    %rbx,%rdi
call   1060 <X509_get_notAfter@plt>
imul   $0x1e13380,%r12d,%esi
mov    %eax,%edi
call   1030 <X509_gmtime_adj@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10f0 <X509_set_pubkey@plt>
mov    %rbx,%rdi
call   1070 <X509_get_subject_name@plt>
mov    %rax,%rbp
mov    0x2cf0(%rip),%rax
mov    (%rax),%edx
movl   $0x0,(%rsp)
lea    0xd00(%rip),%rsi
lea    0xcfc(%rip),%rcx
mov    %rbp,%rdi
mov    $0xffffffff,%r8d
mov    $0xffffffff,%r9d
call   10e0 <X509_NAME_add_entry_by_txt@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <X509_set_issuer_name@plt>
mov    0x8(%rsp),%rbp
xor    %eax,%eax
call   1120 <EVP_sha256@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1100 <X509_sign@plt>
mov    %rbx,(%r15)
mov    0x8(%rsp),%rax
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EVP_PKEY_RSA = global i32 0
@.str = [3 x i8] c"CN\00"
@MBSTRING_ASC = global i32 0
@.str.1 = [25 x i8] c"NVIDIA GameStream Client\00"
define void @mkcert(i32** %0, i32** %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32**
%7 = alloca i32**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
store i32** %0, i32*** %6
store i32** %1, i32*** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%15 = call i32* (...) @X509_new()
store i32* %15, i32** %11
%16 = load i32, i32* @EVP_PKEY_RSA
%17 = call i32* @EVP_PKEY_CTX_new_id(i32 %16, i32* null)
store i32* %17, i32** %12
%18 = load i32*, i32** %12
%19 = call i32 @EVP_PKEY_keygen_init(i32* %18)
%20 = load i32*, i32** %12
%21 = load i32, i32* %8
%22 = call i32 @EVP_PKEY_CTX_set_rsa_keygen_bits(i32* %20, i32 %21)
store i32* null, i32** %13
%23 = load i32*, i32** %12
%24 = call i32 @EVP_PKEY_keygen(i32* %23, i32** %13)
%25 = load i32*, i32** %12
%26 = call i32 @EVP_PKEY_CTX_free(i32* %25)
%27 = load i32*, i32** %11
%28 = call i32 @X509_set_version(i32* %27, i32 2)
%29 = load i32*, i32** %11
%30 = call i32 @X509_get_serialNumber(i32* %29)
%31 = load i32, i32* %9
%32 = call i32 @ASN1_INTEGER_set(i32 %30, i32 %31)
%33 = load i32*, i32** %11
%34 = call i32 @X509_get_notBefore(i32* %33)
%35 = call i32 @X509_gmtime_adj(i32 %34, i32 0)
%36 = load i32*, i32** %11
%37 = call i32 @X509_get_notAfter(i32* %36)
%38 = load i32, i32* %10
%39 = mul nsw i32 31536000, %38
%40 = call i32 @X509_gmtime_adj(i32 %37, i32 %39)
%41 = load i32*, i32** %11
%42 = load i32*, i32** %13
%43 = call i32 @X509_set_pubkey(i32* %41, i32* %42)
%44 = load i32*, i32** %11
%45 = call i32* @X509_get_subject_name(i32* %44)
store i32* %45, i32** %14
%46 = load i32*, i32** %14
%47 = load i32, i32* @MBSTRING_ASC
%48 = call i32 @X509_NAME_add_entry_by_txt(i32* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %47, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%49 = load i32*, i32** %11
%50 = load i32*, i32** %14
%51 = call i32 @X509_set_issuer_name(i32* %49, i32* %50)
%52 = load i32*, i32** %11
%53 = load i32*, i32** %13
%54 = call i32 (...) @EVP_sha256()
%55 = call i32 @X509_sign(i32* %52, i32* %53, i32 %54)
%56 = load i32*, i32** %11
%57 = load i32**, i32*** %6
store i32* %56, i32** %57
%58 = load i32*, i32** %13
%59 = load i32**, i32*** %7
store i32* %58, i32** %59
ret void
}

LLVM IR (-O2):
@EVP_PKEY_RSA = global i32 0
@.str = [3 x i8] c"CN\00"
@MBSTRING_ASC = global i32 0
@.str.1 = [25 x i8] c"NVIDIA GameStream Client\00"
define void @mkcert(i32** nocapture writeonly %0, i32** nocapture writeonly %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = tail call i32* (...) @X509_new()
%8 = load i32, i32* @EVP_PKEY_RSA
%9 = tail call i32* @EVP_PKEY_CTX_new_id(i32 %8, i32* null)
%10 = tail call i32 @EVP_PKEY_keygen_init(i32* %9)
%11 = tail call i32 @EVP_PKEY_CTX_set_rsa_keygen_bits(i32* %9, i32 %2)
%12 = bitcast i32** %6 to i8*
store i32* null, i32** %6
%13 = call i32 @EVP_PKEY_keygen(i32* %9, i32** %6)
%14 = call i32 @EVP_PKEY_CTX_free(i32* %9)
%15 = call i32 @X509_set_version(i32* %7, i32 2)
%16 = call i32 @X509_get_serialNumber(i32* %7)
%17 = call i32 @ASN1_INTEGER_set(i32 %16, i32 %3)
%18 = call i32 @X509_get_notBefore(i32* %7)
%19 = call i32 @X509_gmtime_adj(i32 %18, i32 0)
%20 = call i32 @X509_get_notAfter(i32* %7)
%21 = mul nsw i32 %4, 31536000
%22 = call i32 @X509_gmtime_adj(i32 %20, i32 %21)
%23 = load i32*, i32** %6
%24 = call i32 @X509_set_pubkey(i32* %7, i32* %23)
%25 = call i32* @X509_get_subject_name(i32* %7)
%26 = load i32, i32* @MBSTRING_ASC
%27 = call i32 @X509_NAME_add_entry_by_txt(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %26, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%28 = call i32 @X509_set_issuer_name(i32* %7, i32* %25)
%29 = load i32*, i32** %6
%30 = call i32 (...) @EVP_sha256()
%31 = call i32 @X509_sign(i32* %7, i32* %29, i32 %30)
store i32* %7, i32** %0
%32 = load i32*, i32** %6
store i32* %32, i32** %1
ret void
}