#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_sha1();
int /*<<< orphan*/ MBSTRING_ASC;
int /*<<< orphan*/ NID_basic_constraints;
int /*<<< orphan*/ NID_key_usage;
int /*<<< orphan*/ NID_subject_key_identifier;
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 /*<<< orphan*/ add_ext(int /*<<< orphan*/ *, int /*<<< orphan*/, char *);
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);
  add_ext(x, NID_basic_constraints, "critical,CA:TRUE");
  add_ext(x, NID_key_usage, "critical,keyCertSign,cRLSign");
  add_ext(x, NID_subject_key_identifier, "hash");
  if (!X509_sign(x, pk, EVP_sha1())) {
    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    1271 <mkcert+0x51>
mov    $0x0,%al
call   1100 <EVP_PKEY_new@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    126c <mkcert+0x4c>
mov    $0x0,%al
call   1050 <abort@plt>
jmp    127c <mkcert+0x5c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12a9 <mkcert+0x89>
mov    $0x0,%al
call   1140 <X509_new@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    12a4 <mkcert+0x84>
jmp    1437 <mkcert+0x217>
jmp    12b4 <mkcert+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d0a(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1130 <RSA_generate_key@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <EVP_PKEY_assign_RSA@plt>
cmp    $0x0,%eax
jne    12ed <mkcert+0xcd>
mov    $0x0,%al
call   1050 <abort@plt>
mov    -0x30(%rbp),%rdi
mov    $0x2,%esi
call   1070 <X509_set_version@plt>
mov    -0x30(%rbp),%rdi
call   10c0 <X509_get_serialNumber@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%esi
call   10d0 <ASN1_INTEGER_set@plt>
mov    -0x30(%rbp),%rdi
call   10e0 <X509_get_notBefore@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <X509_gmtime_adj@plt>
mov    -0x30(%rbp),%rdi
call   1080 <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   1110 <X509_set_pubkey@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <X509_get_subject_name@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    0x2c7e(%rip),%rax
mov    (%rax),%edx
lea    0xc95(%rip),%rsi
lea    0xc91(%rip),%rcx
mov    $0xffffffff,%r9d
xor    %eax,%eax
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   10f0 <X509_NAME_add_entry_by_txt@plt>
mov    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   10b0 <X509_set_issuer_name@plt>
mov    -0x30(%rbp),%rdi
mov    0x2c2f(%rip),%rax
mov    (%rax),%esi
lea    0xc72(%rip),%rdx
call   1040 <add_ext@plt>
mov    -0x30(%rbp),%rdi
mov    0x2c36(%rip),%rax
mov    (%rax),%esi
lea    0xc6a(%rip),%rdx
call   1040 <add_ext@plt>
mov    -0x30(%rbp),%rdi
mov    0x2be5(%rip),%rax
mov    (%rax),%esi
lea    0xc6e(%rip),%rdx
call   1040 <add_ext@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1090 <EVP_sha1@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
call   1120 <X509_sign@plt>
cmp    $0x0,%eax
jne    1415 <mkcert+0x1f5>
jmp    1437 <mkcert+0x217>
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    143e <mkcert+0x21e>
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    125a <mkcert+0x3a>
xor    %eax,%eax
call   1100 <EVP_PKEY_new@plt>
mov    %rax,%r12
test   %rax,%rax
je     13cc <mkcert+0x1ac>
mov    %rbx,0x8(%rsp)
mov    (%rbx),%rbx
test   %rbx,%rbx
jne    127d <mkcert+0x5d>
xor    %r13d,%r13d
xor    %eax,%eax
call   1140 <X509_new@plt>
mov    %rax,%rbx
test   %rax,%rax
je     13ba <mkcert+0x19a>
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
xor    %r13d,%r13d
mov    %r15d,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1130 <RSA_generate_key@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1060 <EVP_PKEY_assign_RSA@plt>
test   %eax,%eax
je     13cc <mkcert+0x1ac>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1070 <X509_set_version@plt>
mov    %rbx,%rdi
call   10c0 <X509_get_serialNumber@plt>
mov    %eax,%edi
mov    %r14d,%esi
call   10d0 <ASN1_INTEGER_set@plt>
mov    %rbx,%rdi
call   10e0 <X509_get_notBefore@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1030 <X509_gmtime_adj@plt>
mov    %rbx,%rdi
call   1080 <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   1110 <X509_set_pubkey@plt>
mov    %rbx,%rdi
call   10a0 <X509_get_subject_name@plt>
mov    %rax,%rbp
mov    0x2cd2(%rip),%rax
mov    (%rax),%edx
movl   $0x0,(%rsp)
lea    0xce2(%rip),%rsi
lea    0xcde(%rip),%rcx
mov    %rbp,%rdi
mov    $0xffffffff,%r8d
mov    $0xffffffff,%r9d
call   10f0 <X509_NAME_add_entry_by_txt@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <X509_set_issuer_name@plt>
mov    0x2c85(%rip),%rax
mov    (%rax),%esi
lea    0xcc8(%rip),%rdx
mov    %rbx,%rdi
call   1040 <add_ext@plt>
mov    0x2c8d(%rip),%rax
mov    (%rax),%esi
lea    0xcc1(%rip),%rdx
mov    %rbx,%rdi
call   1040 <add_ext@plt>
mov    0x2c3d(%rip),%rax
mov    (%rax),%esi
lea    0xcc6(%rip),%rdx
mov    %rbx,%rdi
call   1040 <add_ext@plt>
xor    %eax,%eax
call   1090 <EVP_sha1@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1120 <X509_sign@plt>
test   %eax,%eax
je     13ba <mkcert+0x19a>
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   1050 <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"
@NID_basic_constraints = global i32 0
@.str.2 = [17 x i8] c"critical,CA:TRUE\00"
@NID_key_usage = global i32 0
@.str.3 = [29 x i8] c"critical,keyCertSign,cRLSign\00"
@NID_subject_key_identifier = global i32 0
@.str.4 = [5 x i8] c"hash\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 %97
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* @NID_basic_constraints
%79 = call i32 @add_ext(i32* %77, i32 %78, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%80 = load i32*, i32** %12
%81 = load i32, i32* @NID_key_usage
%82 = call i32 @add_ext(i32* %80, i32 %81, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%83 = load i32*, i32** %12
%84 = load i32, i32* @NID_subject_key_identifier
%85 = call i32 @add_ext(i32* %83, i32 %84, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%86 = load i32*, i32** %12
%87 = load i32*, i32** %13
%88 = call i32 (...) @EVP_sha1()
%89 = call i32 @X509_sign(i32* %86, i32* %87, i32 %88)
%90 = icmp ne i32 %89, 0
br i1 %90, label %92, label %91
91: ; preds = %50
br label %97
92: ; preds = %50
%93 = load i32*, i32** %12
%94 = load i32**, i32*** %7
store i32* %93, i32** %94
%95 = load i32*, i32** %13
%96 = load i32**, i32*** %8
store i32* %95, i32** %96
store i32 1, i32* %6
br label %98
97: ; preds = %91, %35
store i32 0, i32* %6
br label %98
98: ; preds = %97, %92
%99 = load i32, i32* %6
ret i32 %99
}

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"
@NID_basic_constraints = global i32 0
@.str.2 = [17 x i8] c"critical,CA:TRUE\00"
@NID_key_usage = global i32 0
@.str.3 = [29 x i8] c"critical,keyCertSign,cRLSign\00"
@NID_subject_key_identifier = global i32 0
@.str.4 = [5 x i8] c"hash\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 %53, 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 = load i32, i32* @NID_basic_constraints
%44 = tail call i32 @add_ext(i32* %21, i32 %43, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* @NID_key_usage
%46 = tail call i32 @add_ext(i32* %21, i32 %45, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @NID_subject_key_identifier
%48 = tail call i32 @add_ext(i32* %21, i32 %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%49 = tail call i32 (...) @EVP_sha1()
%50 = tail call i32 @X509_sign(i32* %21, i32* %14, i32 %49)
%51 = icmp eq i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %28
store i32* %21, i32** %0
store i32* %14, i32** %1
br label %53
53: ; preds = %17, %28, %52
%54 = phi i32 [ 1, %52 ], [ 0, %28 ], [ 0, %17 ]
ret i32 %54
}