#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 *, int /*<<< orphan*/);
scalar_t__ dlsym(void *, char *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  void *handle = dlopen("/lib/libc.so.6", 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)
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1040 <dlopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeac(%rip),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe98(%rip),%rsi
call   1050 <dlsym@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
je     119d <main+0x6d>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
jmp    11a9 <main+0x79>
lea    0xe86(%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    0xebf(%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    0xea4(%rip),%rax
lea    0xea4(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/lib/libc.so.6\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*
store i32 0, i32* %1
%3 = load i32, i32* @RTLD_LAZY
%4 = call i8* @dlopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %3)
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @dlsym(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = call i64 @dlsym(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp ne i64 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"/lib/libc.so.6\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 ([15 x i8], [15 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
}