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

/* Variables and functions */
int /*<<< orphan*/ EC_KEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_KEY_generate_key(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_KEY_new();
int /*<<< orphan*/ EC_KEY_set_group(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
EC_KEY *ecdh_gerenate_key(EC_GROUP *group) {
  EC_KEY *key;
  if ((key = EC_KEY_new()) == NULL)
    return NULL;
  if (!EC_KEY_set_group(key, group) || !EC_KEY_generate_key(key)) {
    EC_KEY_free(key);
    return NULL;
  }
  return key;
}


x86 assembly (clang, -O0):
<ecdh_gerenate_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <EC_KEY_new@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    116e <ecdh_gerenate_key+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    11b4 <ecdh_gerenate_key+0x74>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <EC_KEY_set_group@plt>
cmp    $0x0,%eax
je     1196 <ecdh_gerenate_key+0x56>
mov    -0x18(%rbp),%rdi
call   1030 <EC_KEY_generate_key@plt>
cmp    $0x0,%eax
jne    11ac <ecdh_gerenate_key+0x6c>
mov    -0x18(%rbp),%rdi
call   1040 <EC_KEY_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b4 <ecdh_gerenate_key+0x74>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecdh_gerenate_key>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <EC_KEY_new@plt>
test   %rax,%rax
je     1179 <ecdh_gerenate_key+0x39>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <EC_KEY_set_group@plt>
test   %eax,%eax
je     1171 <ecdh_gerenate_key+0x31>
mov    %rbx,%rdi
call   1030 <EC_KEY_generate_key@plt>
test   %eax,%eax
jne    117b <ecdh_gerenate_key+0x3b>
mov    %rbx,%rdi
call   1040 <EC_KEY_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32* @ecdh_gerenate_key(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
store i32* %0, i32** %3
%5 = call i32* (...) @EC_KEY_new()
store i32* %5, i32** %4
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i32* null, i32** %2
br label %22
8: ; preds = %1
%9 = load i32*, i32** %4
%10 = load i32*, i32** %3
%11 = call i32 @EC_KEY_set_group(i32* %9, i32* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32*, i32** %4
%15 = call i32 @EC_KEY_generate_key(i32* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13, %8
%18 = load i32*, i32** %4
%19 = call i32 @EC_KEY_free(i32* %18)
store i32* null, i32** %2
br label %22
20: ; preds = %13
%21 = load i32*, i32** %4
store i32* %21, i32** %2
br label %22
22: ; preds = %20, %17, %7
%23 = load i32*, i32** %2
ret i32* %23
}

LLVM IR (-O2):
define i32* @ecdh_gerenate_key(i32* %0) {
%2 = tail call i32* (...) @EC_KEY_new()
%3 = icmp eq i32* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i32 @EC_KEY_set_group(i32* %2, i32* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i32 @EC_KEY_generate_key(i32* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7, %4
%11 = tail call i32 @EC_KEY_free(i32* %2)
br label %12
12: ; preds = %7, %1, %10
%13 = phi i32* [ null, %10 ], [ null, %1 ], [ %2, %7 ]
ret i32* %13
}