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

/* Variables and functions */
void *_sqo_dlopen_any(char const *, int);
void *dlopen(char const *, int);
void *_sqo_dlopen(const char *name, int mode) {
  if (name == NULL) {
    return dlopen(name, mode);
  }
  void *handle = NULL;
  if ((handle = dlopen(name, mode)) != NULL) {
    ;
    return handle;
  }
  return _sqo_dlopen_any(name, mode);
}


x86 assembly (clang, -O0):
<_sqo_dlopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114f <_sqo_dlopen+0x2f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <dlopen@plt>
mov    %rax,-0x8(%rbp)
jmp    118e <_sqo_dlopen+0x6e>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <dlopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     117e <_sqo_dlopen+0x5e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118e <_sqo_dlopen+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <_sqo_dlopen_any@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sqo_dlopen>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
test   %rdi,%rdi
je     1140 <_sqo_dlopen+0x20>
mov    %rdi,%rbx
mov    %ebp,%esi
call   1030 <dlopen@plt>
test   %rax,%rax
je     114f <_sqo_dlopen+0x2f>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %edi,%edi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <dlopen@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <_sqo_dlopen_any@plt>

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

LLVM IR (-O2):
define i8* @_sqo_dlopen(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i8* @dlopen(i8* null, i32 %1)
br label %11
6: ; preds = %2
%7 = tail call i8* @dlopen(i8* %0, i32 %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i8* @_sqo_dlopen_any(i8* %0, i32 %1)
br label %11
11: ; preds = %9, %6, %4
%12 = phi i8* [ %5, %4 ], [ %10, %9 ], [ %7, %6 ]
ret i8* %12
}