#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 */
int _dlfcn(char *, char *, char const *);
int main(int argc, char *argv[]) {
  int ret = 0;
  char const *soname = argv[0];
  if (argc == 2)
    soname = argv[1];
  ret |= _dlfcn(argv[0], "dlopen() (1/2)", soname);
  ret |= _dlfcn(argv[0], "dlopen() (2/2)", NULL);
  return (ret == 0) ? 0 : 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    114e <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rdx
lea    0xea0(%rip),%rsi
call   1030 <_dlfcn@plt>
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe96(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <_dlfcn@plt>
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edx
mov    $0x2,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    (%rsi,%rax,8),%rdx
mov    (%rsi),%rdi
lea    0xed4(%rip),%rsi
call   1030 <_dlfcn@plt>
mov    %eax,%ebp
mov    (%rbx),%rdi
lea    0xed2(%rip),%rsi
xor    %edx,%edx
call   1030 <_dlfcn@plt>
xor    %ecx,%ecx
or     %ebp,%eax
setne  %cl
add    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"dlopen() (1/2)\00"
@.str.1 = [15 x i8] c"dlopen() (2/2)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
store i8* %10, i8** %7
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %7
br label %17
17: ; preds = %13, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i8*, i8** %7
%22 = call i32 @_dlfcn(i8* %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* %6
%24 = or i32 %23, %22
store i32 %24, i32* %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 @_dlfcn(i8* %27, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* null)
%29 = load i32, i32* %6
%30 = or i32 %29, %28
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 0
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 0, i32 2
ret i32 %34
}

LLVM IR (-O2):
@.str = [15 x i8] c"dlopen() (1/2)\00"
@.str.1 = [15 x i8] c"dlopen() (2/2)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
%4 = zext i1 %3 to i64
%5 = getelementptr i8*, i8** %1, i64 %4
%6 = load i8*, i8** %5
%7 = load i8*, i8** %1
%8 = tail call i32 @_dlfcn(i8* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %6)
%9 = load i8*, i8** %1
%10 = tail call i32 @_dlfcn(i8* %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* null)
%11 = or i32 %10, %8
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 0, i32 2
ret i32 %13
}