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

/* Variables and functions */
int /*<<< orphan*/ ASN1_INTEGER_set(int /*<<< orphan*/, int);
int /*<<< orphan*/ EVP_PKEY_assign_RSA(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_new();
int /*<<< orphan*/ EVP_sha256();
int /*<<< orphan*/ MBSTRING_ASC;
int /*<<< orphan*/ RSA_F4;
int /*<<< orphan*/ *RSA_generate_key(int, int /*<<< orphan*/,
                                     int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_NAME_add_entry_by_txt(int /*<<< orphan*/ *, char *,
                                              int /*<<< orphan*/,
                                              unsigned char *, 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*/, long);
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*/);
int /*<<< orphan*/ abort();
int mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int years) {
  X509 *x;
  EVP_PKEY *pk;
  RSA *rsa;
  X509_NAME *name = NULL;
  if (*pkeyp == NULL) {
    if ((pk = EVP_PKEY_new()) == NULL) {
      abort();
      return (0);
    }
  } else {
    pk = *pkeyp;
  }
  if (*x509p == NULL) {
    if ((x = X509_new()) == NULL) {
      goto err;
    }
  } else {
    x = *x509p;
  }
  rsa = RSA_generate_key(bits, RSA_F4, NULL, NULL);
  if (!EVP_PKEY_assign_RSA(pk, rsa)) {
    abort();
    goto err;
  }
  X509_set_version(x, 2);
  ASN1_INTEGER_set(X509_get_serialNumber(x), serial);
  X509_gmtime_adj(X509_get_notBefore(x), 0);
  X509_gmtime_adj(X509_get_notAfter(x), (long)60 * 60 * 24 * 365 * years);
  X509_set_pubkey(x, pk);
  name = X509_get_subject_name(x);
  X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC,
                             (unsigned char *)"NVIDIA GameStream Client", -1,
                             -1, 0);
  X509_set_issuer_name(x, name);
  if (!X509_sign(x, pk, EVP_sha256())) {
    goto err;
  }
  *x509p = x;
  *pkeyp = pk;
  return (1);
err:
  return (0);
}


x86 assembly (clang, -O0):
<mkcert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1261 <mkcert+0x51>
mov    $0x0,%al
call   10e0 <EVP_PKEY_new@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    125c <mkcert+0x4c>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    126c <mkcert+0x5c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1299 <mkcert+0x89>
mov    $0x0,%al
call   1130 <X509_new@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1294 <mkcert+0x84>
jmp    13dc <mkcert+0x1cc>
jmp    12a4 <mkcert+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1120 <RSA_generate_key@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1050 <EVP_PKEY_assign_RSA@plt>
cmp    $0x0,%eax
jne    12dd <mkcert+0xcd>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x30(%rbp),%rdi
mov    $0x2,%esi
call   1060 <X509_set_version@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <X509_get_serialNumber@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%esi
call   10b0 <ASN1_INTEGER_set@plt>
mov    -0x30(%rbp),%rdi
call   10c0 <X509_get_notBefore@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <X509_gmtime_adj@plt>
mov    -0x30(%rbp),%rdi
call   1070 <X509_get_notAfter@plt>
mov    %eax,%edi
movslq -0x24(%rbp),%rax
imul   $0x1e13380,%rax,%rsi
call   1030 <X509_gmtime_adj@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10f0 <X509_set_pubkey@plt>
mov    -0x30(%rbp),%rdi
call   1080 <X509_get_subject_name@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    0x2c96(%rip),%rax
mov    (%rax),%edx
lea    0xca5(%rip),%rsi
lea    0xca1(%rip),%rcx
mov    $0xffffffff,%r9d
xor    %eax,%eax
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   10d0 <X509_NAME_add_entry_by_txt@plt>
mov    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1090 <X509_set_issuer_name@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1110 <EVP_sha256@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
call   1100 <X509_sign@plt>
cmp    $0x0,%eax
jne    13ba <mkcert+0x1aa>
jmp    13dc <mkcert+0x1cc>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    13e3 <mkcert+0x1d3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
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,%ebp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rdi,%rbx
mov    %rsi,0x10(%rsp)
mov    (%rsi),%r12
test   %r12,%r12
jne    124a <mkcert+0x3a>
xor    %eax,%eax
call   10e0 <EVP_PKEY_new@plt>
mov    %rax,%r12
test   %rax,%rax
je     1374 <mkcert+0x164>
mov    %rbx,0x8(%rsp)
mov    (%rbx),%rbx
test   %rbx,%rbx
jne    126d <mkcert+0x5d>
xor    %r13d,%r13d
xor    %eax,%eax
call   1130 <X509_new@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1362 <mkcert+0x152>
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
xor    %r13d,%r13d
mov    %r15d,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1120 <RSA_generate_key@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1050 <EVP_PKEY_assign_RSA@plt>
test   %eax,%eax
je     1374 <mkcert+0x164>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1060 <X509_set_version@plt>
mov    %rbx,%rdi
call   10a0 <X509_get_serialNumber@plt>
mov    %eax,%edi
mov    %r14d,%esi
call   10b0 <ASN1_INTEGER_set@plt>
mov    %rbx,%rdi
call   10c0 <X509_get_notBefore@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1030 <X509_gmtime_adj@plt>
mov    %rbx,%rdi
call   1070 <X509_get_notAfter@plt>
movslq %ebp,%rcx
imul   $0x1e13380,%rcx,%rsi
mov    %eax,%edi
call   1030 <X509_gmtime_adj@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10f0 <X509_set_pubkey@plt>
mov    %rbx,%rdi
call   1080 <X509_get_subject_name@plt>
mov    %rax,%rbp
mov    0x2cea(%rip),%rax
mov    (%rax),%edx
movl   $0x0,(%rsp)
lea    0xcf2(%rip),%rsi
lea    0xcee(%rip),%rcx
mov    %rbp,%rdi
mov    $0xffffffff,%r8d
mov    $0xffffffff,%r9d
call   10d0 <X509_NAME_add_entry_by_txt@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <X509_set_issuer_name@plt>
xor    %eax,%eax
call   1110 <EVP_sha256@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1100 <X509_sign@plt>
test   %eax,%eax
je     1362 <mkcert+0x152>
mov    0x8(%rsp),%rax
mov    %rbx,(%rax)
mov    0x10(%rsp),%rax
mov    %r12,(%rax)
mov    $0x1,%r13d
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@RSA_F4 = 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 i32 @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*
%15 = alloca i32*
store i32** %0, i32*** %7
store i32** %1, i32*** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32* null, i32** %15
%16 = load i32**, i32*** %8
%17 = load i32*, i32** %16
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %25
19: ; preds = %5
%20 = call i32* (...) @EVP_PKEY_new()
store i32* %20, i32** %13
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %19
br label %28
25: ; preds = %5
%26 = load i32**, i32*** %8
%27 = load i32*, i32** %26
store i32* %27, i32** %13
br label %28
28: ; preds = %25, %24
%29 = load i32**, i32*** %7
%30 = load i32*, i32** %29
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = call i32* (...) @X509_new()
store i32* %33, i32** %12
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %36
35: ; preds = %32
br label %88
36: ; preds = %32
br label %40
37: ; preds = %28
%38 = load i32**, i32*** %7
%39 = load i32*, i32** %38
store i32* %39, i32** %12
br label %40
40: ; preds = %37, %36
%41 = load i32, i32* %9
%42 = load i32, i32* @RSA_F4
%43 = call i32* @RSA_generate_key(i32 %41, i32 %42, i32* null, i32* null)
store i32* %43, i32** %14
%44 = load i32*, i32** %13
%45 = load i32*, i32** %14
%46 = call i32 @EVP_PKEY_assign_RSA(i32* %44, i32* %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %40
%49 = call i32 (...) @abort()
unreachable
50: ; preds = %40
%51 = load i32*, i32** %12
%52 = call i32 @X509_set_version(i32* %51, i32 2)
%53 = load i32*, i32** %12
%54 = call i32 @X509_get_serialNumber(i32* %53)
%55 = load i32, i32* %10
%56 = call i32 @ASN1_INTEGER_set(i32 %54, i32 %55)
%57 = load i32*, i32** %12
%58 = call i32 @X509_get_notBefore(i32* %57)
%59 = call i32 @X509_gmtime_adj(i32 %58, i64 0)
%60 = load i32*, i32** %12
%61 = call i32 @X509_get_notAfter(i32* %60)
%62 = load i32, i32* %11
%63 = sext i32 %62 to i64
%64 = mul nsw i64 31536000, %63
%65 = call i32 @X509_gmtime_adj(i32 %61, i64 %64)
%66 = load i32*, i32** %12
%67 = load i32*, i32** %13
%68 = call i32 @X509_set_pubkey(i32* %66, i32* %67)
%69 = load i32*, i32** %12
%70 = call i32* @X509_get_subject_name(i32* %69)
store i32* %70, i32** %15
%71 = load i32*, i32** %15
%72 = load i32, i32* @MBSTRING_ASC
%73 = call i32 @X509_NAME_add_entry_by_txt(i32* %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %72, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%74 = load i32*, i32** %12
%75 = load i32*, i32** %15
%76 = call i32 @X509_set_issuer_name(i32* %74, i32* %75)
%77 = load i32*, i32** %12
%78 = load i32*, i32** %13
%79 = call i32 (...) @EVP_sha256()
%80 = call i32 @X509_sign(i32* %77, i32* %78, i32 %79)
%81 = icmp ne i32 %80, 0
br i1 %81, label %83, label %82
82: ; preds = %50
br label %88
83: ; preds = %50
%84 = load i32*, i32** %12
%85 = load i32**, i32*** %7
store i32* %84, i32** %85
%86 = load i32*, i32** %13
%87 = load i32**, i32*** %8
store i32* %86, i32** %87
store i32 1, i32* %6
br label %89
88: ; preds = %82, %35
store i32 0, i32* %6
br label %89
89: ; preds = %88, %83
%90 = load i32, i32* %6
ret i32 %90
}

LLVM IR (-O2):
@RSA_F4 = 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 i32 @mkcert(i32** nocapture %0, i32** nocapture %1, i32 %2, i32 %3, i32 %4) {
%6 = load i32*, i32** %1
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = tail call i32* (...) @EVP_PKEY_new()
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 (...) @abort()
unreachable
13: ; preds = %5, %8
%14 = phi i32* [ %9, %8 ], [ %6, %5 ]
%15 = load i32*, i32** %0
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = tail call i32* (...) @X509_new()
%19 = icmp eq i32* %18, null
br i1 %19, label %47, label %20
20: ; preds = %13, %17
%21 = phi i32* [ %18, %17 ], [ %15, %13 ]
%22 = load i32, i32* @RSA_F4
%23 = tail call i32* @RSA_generate_key(i32 %2, i32 %22, i32* null, i32* null)
%24 = tail call i32 @EVP_PKEY_assign_RSA(i32* %14, i32* %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = tail call i32 (...) @abort()
unreachable
28: ; preds = %20
%29 = tail call i32 @X509_set_version(i32* %21, i32 2)
%30 = tail call i32 @X509_get_serialNumber(i32* %21)
%31 = tail call i32 @ASN1_INTEGER_set(i32 %30, i32 %3)
%32 = tail call i32 @X509_get_notBefore(i32* %21)
%33 = tail call i32 @X509_gmtime_adj(i32 %32, i64 0)
%34 = tail call i32 @X509_get_notAfter(i32* %21)
%35 = sext i32 %4 to i64
%36 = mul nsw i64 %35, 31536000
%37 = tail call i32 @X509_gmtime_adj(i32 %34, i64 %36)
%38 = tail call i32 @X509_set_pubkey(i32* %21, i32* %14)
%39 = tail call i32* @X509_get_subject_name(i32* %21)
%40 = load i32, i32* @MBSTRING_ASC
%41 = tail call i32 @X509_NAME_add_entry_by_txt(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 -1, i32 -1, i32 0)
%42 = tail call i32 @X509_set_issuer_name(i32* %21, i32* %39)
%43 = tail call i32 (...) @EVP_sha256()
%44 = tail call i32 @X509_sign(i32* %21, i32* %14, i32 %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %28
store i32* %21, i32** %0
store i32* %14, i32** %1
br label %47
47: ; preds = %17, %28, %46
%48 = phi i32 [ 1, %46 ], [ 0, %28 ], [ 0, %17 ]
ret i32 %48
}