#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 EXIT_FAILURE;
int RTLD_GLOBAL;
int RTLD_LAZY;
int /*<<< orphan*/ dlopen(char *, int);
int getpid();
scalar_t__ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  dlopen("/dev/null", RTLD_GLOBAL | RTLD_LAZY);
  while (printf("%d\n", getpid()))
    sleep(5);
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    0x2e6a(%rip),%rax
or     (%rax),%esi
lea    0xe91(%rip),%rdi
call   1050 <dlopen@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
cmp    $0x0,%rax
je     11a2 <main+0x62>
mov    $0x5,%edi
call   1060 <sleep@plt>
jmp    1174 <main+0x34>
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    0x2e81(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xea6(%rip),%rdi
call   1050 <dlopen@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe9d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
test   %rax,%rax
je     11a0 <main+0x60>
lea    0xe8a(%rip),%rbx
mov    $0x5,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
test   %rax,%rax
jne    1180 <main+0x40>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@RTLD_GLOBAL = global i32 0
@RTLD_LAZY = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* @RTLD_GLOBAL
%7 = load i32, i32* @RTLD_LAZY
%8 = or i32 %6, %7
%9 = call i32 @dlopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %14, %2
%11 = call i32 (...) @getpid()
%12 = call i64 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @sleep(i32 5)
br label %10
16: ; preds = %10
%17 = load i32, i32* @EXIT_FAILURE
ret i32 %17
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@RTLD_GLOBAL = global i32 0
@RTLD_LAZY = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @RTLD_GLOBAL
%4 = load i32, i32* @RTLD_LAZY
%5 = or i32 %4, %3
%6 = tail call i32 @dlopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 (...) @getpid()
%8 = tail call i64 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %2, %10
%11 = tail call i32 @sleep(i32 5)
%12 = tail call i32 (...) @getpid()
%13 = tail call i64 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %10
15: ; preds = %10, %2
%16 = load i32, i32* @EXIT_FAILURE
ret i32 %16
}