#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 */
char *lbs_posix_readlink(char *);
char *lbs_sysdep_get_executable(void) {
  char *myexec;
  if ((myexec = lbs_posix_readlink("/proc/self/exe")) != NULL) {
    return myexec;
  }
  if ((myexec = lbs_posix_readlink("/proc/curproc/exe")) != NULL) {
    return myexec;
  }
  if ((myexec = lbs_posix_readlink("/proc/curproc/file")) != NULL) {
    return myexec;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<lbs_sysdep_get_executable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xee1(%rip),%rdi
call   1030 <lbs_posix_readlink@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     113f <lbs_sysdep_get_executable+0x2f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1195 <lbs_sysdep_get_executable+0x85>
lea    0xec9(%rip),%rdi
call   1030 <lbs_posix_readlink@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1166 <lbs_sysdep_get_executable+0x56>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1195 <lbs_sysdep_get_executable+0x85>
lea    0xeb4(%rip),%rdi
call   1030 <lbs_posix_readlink@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     118d <lbs_sysdep_get_executable+0x7d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1195 <lbs_sysdep_get_executable+0x85>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lbs_sysdep_get_executable>:
push   %rax
lea    0xee8(%rip),%rdi
call   1030 <lbs_posix_readlink@plt>
test   %rax,%rax
jne    1133 <lbs_sysdep_get_executable+0x23>
lea    0xee6(%rip),%rdi
call   1030 <lbs_posix_readlink@plt>
test   %rax,%rax
je     1135 <lbs_sysdep_get_executable+0x25>
pop    %rcx
ret
lea    0xee5(%rip),%rdi
pop    %rax
jmp    1030 <lbs_posix_readlink@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [18 x i8] c"/proc/curproc/exe\00"
@.str.2 = [19 x i8] c"/proc/curproc/file\00"
define i8* @lbs_sysdep_get_executable() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @lbs_posix_readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = icmp ne i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = load i8*, i8** %2
store i8* %6, i8** %1
br label %18
7: ; preds = %0
%8 = call i8* @lbs_posix_readlink(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i8* %8, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = load i8*, i8** %2
store i8* %11, i8** %1
br label %18
12: ; preds = %7
%13 = call i8* @lbs_posix_readlink(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i8* %13, i8** %2
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = load i8*, i8** %2
store i8* %16, i8** %1
br label %18
17: ; preds = %12
store i8* null, i8** %1
br label %18
18: ; preds = %17, %15, %10, %5
%19 = load i8*, i8** %1
ret i8* %19
}

LLVM IR (-O2):
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [18 x i8] c"/proc/curproc/exe\00"
@.str.2 = [19 x i8] c"/proc/curproc/file\00"
define i8* @lbs_sysdep_get_executable() {
%1 = tail call i8* @lbs_posix_readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %8
3: ; preds = %0
%4 = tail call i8* @lbs_posix_readlink(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i8* @lbs_posix_readlink(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %6, %3, %0
%9 = phi i8* [ %1, %0 ], [ %4, %3 ], [ %7, %6 ]
ret i8* %9
}