#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 */
scalar_t__ _checkPath(char *, char *);
char *getcwd(char *, int);
int readlink(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *strrchr(char *, char);
void _setSearchPath(char *so_name) {
  char path[256 + 1];
  int count;
  char *p;
  if (so_name[0] == '/')
    return;
  count = readlink("/proc/self/exe", path, 256);
  if (count > 0) {
    path[count] = 0;
    if ((p = strrchr(path, '/')) != 0)
      *p = '\0';
    if (path[0] == '\0')
      strcpy(path, "/");
    if (_checkPath(path, so_name))
      return;
  }
  p = getcwd(path, 256);
  if (p != 0)
    _checkPath(path, so_name);
}


x86 assembly (clang, -O0):
<_setSearchPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1174 <_setSearchPath+0x24>
jmp    1257 <_setSearchPath+0x107>
lea    -0x110(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x100,%edx
call   1040 <readlink@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jle    1221 <_setSearchPath+0xd1>
movslq -0x114(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x120(%rbp)
cmp    $0x0,%rax
je     11da <_setSearchPath+0x8a>
mov    -0x120(%rbp),%rax
movb   $0x0,(%rax)
movsbl -0x110(%rbp),%eax
cmp    $0x0,%eax
jne    11fd <_setSearchPath+0xad>
lea    -0x110(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <_checkPath@plt>
cmp    $0x0,%rax
je     121c <_setSearchPath+0xcc>
jmp    1257 <_setSearchPath+0x107>
jmp    1221 <_setSearchPath+0xd1>
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1060 <getcwd@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
je     1257 <_setSearchPath+0x107>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <_checkPath@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_setSearchPath>:
push   %rbx
sub    $0x110,%rsp
cmpb   $0x2f,(%rdi)
je     11d5 <_setSearchPath+0x85>
mov    %rdi,%rbx
lea    0xe99(%rip),%rdi
mov    %rsp,%rsi
mov    $0x100,%edx
call   1040 <readlink@plt>
test   %eax,%eax
jle    11b8 <_setSearchPath+0x68>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1193 <_setSearchPath+0x43>
movb   $0x0,(%rax)
cmpb   $0x0,(%rsp)
jne    11a8 <_setSearchPath+0x58>
lea    0xe6f(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1070 <_checkPath@plt>
test   %rax,%rax
jne    11d5 <_setSearchPath+0x85>
mov    %rsp,%rdi
mov    $0x100,%esi
call   1060 <getcwd@plt>
test   %rax,%rax
je     11d5 <_setSearchPath+0x85>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1070 <_checkPath@plt>
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [2 x i8] c"/\00"
define void @_setSearchPath(i8* %0) {
%2 = alloca i8*
%3 = alloca [257 x i8]
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 47
br i1 %10, label %11, label %12
11: ; preds = %1
br label %50
12: ; preds = %1
%13 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%14 = call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %13, i32 256)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %41
17: ; preds = %12
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 %19
store i8 0, i8* %20
%21 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%22 = call i8* @strrchr(i8* %21, i8 signext 47)
store i8* %22, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = load i8*, i8** %5
store i8 0, i8* %25
br label %26
26: ; preds = %24, %17
%27 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %31, %26
%35 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%36 = load i8*, i8** %2
%37 = call i64 @_checkPath(i8* %35, i8* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %34
br label %50
40: ; preds = %34
br label %41
41: ; preds = %40, %12
%42 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%43 = call i8* @getcwd(i8* %42, i32 256)
store i8* %43, i8** %5
%44 = load i8*, i8** %5
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%48 = load i8*, i8** %2
%49 = call i64 @_checkPath(i8* %47, i8* %48)
br label %50
50: ; preds = %11, %39, %46, %41
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [2 x i8] c"/\00"
define void @_setSearchPath(i8* %0) {
%2 = alloca [257 x i8]
%3 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 0
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 47
br i1 %5, label %28, label %6
6: ; preds = %1
%7 = call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %3, i32 256)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = zext i32 %7 to i64
%11 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i8* @strrchr(i8* %3, i8 signext 47)
%13 = icmp eq i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %9
store i8 0, i8* %12
br label %15
15: ; preds = %14, %9
%16 = load i8, i8* %3
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
%21 = call i64 @_checkPath(i8* %3, i8* %0)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %20, %6
%24 = call i8* @getcwd(i8* %3, i32 256)
%25 = icmp eq i8* %24, null
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = call i64 @_checkPath(i8* %3, i8* %0)
br label %28
28: ; preds = %23, %26, %20, %1
ret void
}