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

/* Variables and functions */
int /*<<< orphan*/ EC_KEY_generate_key(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_KEY_new_by_curve_name(int /*<<< orphan*/);
int /*<<< orphan*/ NID_X9_62_prime256v1;
int /*<<< orphan*/ die(char *);
EC_KEY *gen_key(void) {
  EC_KEY *key;
  key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
  if (key == NULL)
    die("Failed to create lKey object.\n");
  if (!EC_KEY_generate_key(key))
    die("Failed to generate EC key.\n");
  return key;
}


x86 assembly (clang, -O0):
<gen_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
call   1050 <EC_KEY_new_by_curve_name@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1161 <gen_key+0x31>
lea    0xea4(%rip),%rdi
call   1040 <die@plt>
mov    -0x8(%rbp),%rdi
call   1030 <EC_KEY_generate_key@plt>
cmp    $0x0,%eax
jne    117f <gen_key+0x4f>
lea    0xea5(%rip),%rdi
call   1040 <die@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_key>:
push   %rbx
mov    0x2ea8(%rip),%rax
mov    (%rax),%edi
call   1050 <EC_KEY_new_by_curve_name@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1153 <gen_key+0x23>
lea    0xeb2(%rip),%rdi
call   1040 <die@plt>
mov    %rbx,%rdi
call   1030 <EC_KEY_generate_key@plt>
test   %eax,%eax
jne    116b <gen_key+0x3b>
lea    0xeb9(%rip),%rdi
call   1040 <die@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@NID_X9_62_prime256v1 = global i32 0
@.str = [31 x i8] c"Failed to create lKey object.\0A\00"
@.str.1 = [28 x i8] c"Failed to generate EC key.\0A\00"
define i32* @gen_key() {
%1 = alloca i32*
%2 = load i32, i32* @NID_X9_62_prime256v1
%3 = call i32* @EC_KEY_new_by_curve_name(i32 %2)
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = load i32*, i32** %1
%10 = call i32 @EC_KEY_generate_key(i32* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = call i32 @die(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i32*, i32** %1
ret i32* %15
}

LLVM IR (-O2):
@NID_X9_62_prime256v1 = global i32 0
@.str = [31 x i8] c"Failed to create lKey object.\0A\00"
@.str.1 = [28 x i8] c"Failed to generate EC key.\0A\00"
define i32* @gen_key() {
%1 = load i32, i32* @NID_X9_62_prime256v1
%2 = tail call i32* @EC_KEY_new_by_curve_name(i32 %1)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = tail call i32 @EC_KEY_generate_key(i32* %2)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @die(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
ret i32* %2
}