#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 /*<<< orphan*/ RTLD_LAZY;
void *dlopen(char const *, int /*<<< orphan*/);
scalar_t__ dlsym(void *, char *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  const char *libc = "/usr/lib/x86_64-linux-gnu/libc.so";
  void *handle = dlopen(libc, RTLD_LAZY);
  if (dlsym(handle, "execve") != dlsym(((void *)0), "execve"))
    printf("something fishy...\n");
  else
    printf("secure\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
call   1040 <dlopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb7(%rip),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xea3(%rip),%rsi
call   1050 <dlsym@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
je     11a5 <main+0x75>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
jmp    11b1 <main+0x81>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2ea5(%rip),%rax
mov    (%rax),%esi
lea    0xebc(%rip),%rdi
call   1040 <dlopen@plt>
lea    0xed2(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <dlsym@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <dlsym@plt>
cmp    %rax,%rbx
lea    0xeb7(%rip),%rax
lea    0xeb7(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [34 x i8] c"/usr/lib/x86_64-linux-gnu/libc.so\00"
@RTLD_LAZY = global i32 0
@.str.1 = [7 x i8] c"execve\00"
@.str.2 = [20 x i8] c"something fishy...\0A\00"
@.str.3 = [8 x i8] c"secure\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8** %2
%4 = load i8*, i8** %2
%5 = load i32, i32* @RTLD_LAZY
%6 = call i8* @dlopen(i8* %4, i32 %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @dlsym(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%9 = call i64 @dlsym(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %15
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %11
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"/usr/lib/x86_64-linux-gnu/libc.so\00"
@RTLD_LAZY = global i32 0
@.str.1 = [7 x i8] c"execve\00"
@str = [7 x i8] c"secure\00"
@str.4 = [19 x i8] c"something fishy...\00"
define i32 @main() {
%1 = load i32, i32* @RTLD_LAZY
%2 = tail call i8* @dlopen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i64 @dlsym(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i64 @dlsym(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i64 %3, %4
%6 = select i1 %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0)
%7 = tail call i32 @puts(i8* dereferenceable(1) %6)
ret i32 0
}