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

/* Variables and functions */
int /*<<< orphan*/ *ENGINE_by_id(char *);
int /*<<< orphan*/ ENGINE_ctrl_cmd_string(int /*<<< orphan*/ *, char *,
                                          char const *, int /*<<< orphan*/);
int /*<<< orphan*/ ENGINE_free(int /*<<< orphan*/ *);
ENGINE *try_load_engine(BIO *err, const char *engine) {
  ENGINE *e = ENGINE_by_id("dynamic");
  if (e) {
    if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", engine, 0) ||
        !ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0)) {
      ENGINE_free(e);
      e = NULL;
    }
  }
  return e;
}


x86 assembly (clang, -O0):
<try_load_engine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb9(%rip),%rdi
call   1050 <ENGINE_by_id@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11af <try_load_engine+0x7f>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe9e(%rip),%rsi
xor    %ecx,%ecx
call   1040 <ENGINE_ctrl_cmd_string@plt>
cmp    $0x0,%eax
je     1199 <try_load_engine+0x69>
mov    -0x18(%rbp),%rdi
lea    0xe8b(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <ENGINE_ctrl_cmd_string@plt>
cmp    $0x0,%eax
jne    11aa <try_load_engine+0x7a>
mov    -0x18(%rbp),%rdi
call   1030 <ENGINE_free@plt>
movq   $0x0,-0x18(%rbp)
jmp    11af <try_load_engine+0x7f>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<try_load_engine>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xec2(%rip),%rdi
call   1050 <ENGINE_by_id@plt>
test   %rax,%rax
je     1182 <try_load_engine+0x52>
mov    %rax,%rbx
lea    0xeb6(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1040 <ENGINE_ctrl_cmd_string@plt>
test   %eax,%eax
je     117a <try_load_engine+0x4a>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <ENGINE_ctrl_cmd_string@plt>
test   %eax,%eax
jne    1184 <try_load_engine+0x54>
mov    %rbx,%rdi
call   1030 <ENGINE_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"dynamic\00"
@.str.1 = [8 x i8] c"SO_PATH\00"
@.str.2 = [5 x i8] c"LOAD\00"
define i32* @try_load_engine(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = call i32* @ENGINE_by_id(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %22
9: ; preds = %2
%10 = load i32*, i32** %5
%11 = load i8*, i8** %4
%12 = call i32 @ENGINE_ctrl_cmd_string(i32* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 0)
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32*, i32** %5
%16 = call i32 @ENGINE_ctrl_cmd_string(i32* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* null, i32 0)
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14, %9
%19 = load i32*, i32** %5
%20 = call i32 @ENGINE_free(i32* %19)
store i32* null, i32** %5
br label %21
21: ; preds = %18, %14
br label %22
22: ; preds = %21, %2
%23 = load i32*, i32** %5
ret i32* %23
}

LLVM IR (-O2):
@.str = [8 x i8] c"dynamic\00"
@.str.1 = [8 x i8] c"SO_PATH\00"
@.str.2 = [5 x i8] c"LOAD\00"
define i32* @try_load_engine(i32* nocapture readnone %0, i8* %1) {
%3 = tail call i32* @ENGINE_by_id(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = tail call i32 @ENGINE_ctrl_cmd_string(i32* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i32 @ENGINE_ctrl_cmd_string(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* null, i32 0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8, %5
%12 = tail call i32 @ENGINE_free(i32* %3)
br label %13
13: ; preds = %8, %11, %2
%14 = phi i32* [ %3, %8 ], [ null, %11 ], [ null, %2 ]
ret i32* %14
}