#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ check_path(char *);
int /*<<< orphan*/ exit(int);
char *getcwd(char *, int);
char *getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *, char *);
char *get_config_path(char *default_path, char *pbuf, size_t bufsize) {
  char buf[512];
  char *path = default_path;
  if (check_path(path))
    goto have;
  path = getenv("PROXYCHAINS_CONF_FILE");
  if (check_path(path))
    goto have;
  path = getcwd(buf, sizeof(buf));
  snprintf(pbuf, bufsize, "%s/%s", path, "proxychains.conf");
  path = pbuf;
  if (check_path(path))
    goto have;
  path = getenv("HOME");
  snprintf(pbuf, bufsize, "%s/.proxychains/%s", path, "proxychains.conf");
  path = pbuf;
  if (check_path(path))
    goto have;
  path = "/etc"
         "/"
         "proxychains.conf";
  if (check_path(path))
    goto have;
  path = "/etc/"
         "proxychains.conf";
  if (check_path(path))
    goto have;
  perror("couldnt find configuration file");
  exit(1);
  return NULL;
have:
  return path;
}


x86 assembly (clang, -O0):
<get_config_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rdi
call   1060 <check_path@plt>
cmp    $0x0,%rax
je     119d <get_config_path+0x3d>
jmp    12ee <get_config_path+0x18e>
lea    0xe5c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rdi
call   1060 <check_path@plt>
cmp    $0x0,%rax
je     11cb <get_config_path+0x6b>
jmp    12ee <get_config_path+0x18e>
lea    -0x220(%rbp),%rdi
mov    $0x200,%esi
call   1050 <getcwd@plt>
mov    %rax,-0x228(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x228(%rbp),%rcx
lea    0xe1d(%rip),%rdx
lea    0xe39(%rip),%r8
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rdi
call   1060 <check_path@plt>
cmp    $0x0,%rax
je     122b <get_config_path+0xcb>
jmp    12ee <get_config_path+0x18e>
lea    0xdea(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x228(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x228(%rbp),%rcx
lea    0xdcd(%rip),%rdx
lea    0xdde(%rip),%r8
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rdi
call   1060 <check_path@plt>
cmp    $0x0,%rax
je     1286 <get_config_path+0x126>
jmp    12ee <get_config_path+0x18e>
lea    0xda7(%rip),%rax
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rdi
call   1060 <check_path@plt>
cmp    $0x0,%rax
je     12af <get_config_path+0x14f>
jmp    12ee <get_config_path+0x18e>
lea    0xd7e(%rip),%rax
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rdi
call   1060 <check_path@plt>
cmp    $0x0,%rax
je     12d8 <get_config_path+0x178>
jmp    12ee <get_config_path+0x18e>
lea    0xd6b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x228(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_config_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1060 <check_path@plt>
test   %rax,%rax
jne    123e <get_config_path+0xde>
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <check_path@plt>
test   %rax,%rax
jne    123e <get_config_path+0xde>
mov    %rsp,%rdi
mov    $0x200,%esi
call   1050 <getcwd@plt>
lea    0xe5f(%rip),%rdx
lea    0xe7b(%rip),%r8
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rcx
call   1040 <snprintf@plt>
mov    %r15,%rdi
call   1060 <check_path@plt>
test   %rax,%rax
je     11de <get_config_path+0x7e>
mov    %r15,%rbx
jmp    123e <get_config_path+0xde>
lea    0xe37(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe30(%rip),%rdx
lea    0xe41(%rip),%r8
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rcx
call   1040 <snprintf@plt>
mov    %r15,%rdi
call   1060 <check_path@plt>
mov    %r15,%rbx
test   %rax,%rax
jne    123e <get_config_path+0xde>
lea    0xe17(%rip),%rbx
mov    %rbx,%rdi
call   1060 <check_path@plt>
test   %rax,%rax
jne    123e <get_config_path+0xde>
lea    0xe03(%rip),%rbx
mov    %rbx,%rdi
call   1060 <check_path@plt>
test   %rax,%rax
je     124e <get_config_path+0xee>
mov    %rbx,%rax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdf5(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"PROXYCHAINS_CONF_FILE\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [17 x i8] c"proxychains.conf\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [19 x i8] c"%s/.proxychains/%s\00"
@.str.5 = [22 x i8] c"/etc/proxychains.conf\00"
@.str.6 = [32 x i8] c"couldnt find configuration file\00"
define i8* @get_config_path(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [512 x i8]
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %4
store i8* %9, i8** %8
%10 = load i8*, i8** %8
%11 = call i64 @check_path(i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
br label %56
14: ; preds = %3
%15 = call i8* @getenv(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = call i64 @check_path(i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
br label %56
20: ; preds = %14
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%22 = call i8* @getcwd(i8* %21, i32 512)
store i8* %22, i8** %8
%23 = load i8*, i8** %5
%24 = load i64, i64* %6
%25 = load i8*, i8** %8
%26 = call i32 @snprintf(i8* %23, i64 %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8*, i8** %5
store i8* %27, i8** %8
%28 = load i8*, i8** %8
%29 = call i64 @check_path(i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %20
br label %56
32: ; preds = %20
%33 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %33, i8** %8
%34 = load i8*, i8** %5
%35 = load i64, i64* %6
%36 = load i8*, i8** %8
%37 = call i32 @snprintf(i8* %34, i64 %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%38 = load i8*, i8** %5
store i8* %38, i8** %8
%39 = load i8*, i8** %8
%40 = call i64 @check_path(i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %32
br label %56
43: ; preds = %32
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8** %8
%44 = load i8*, i8** %8
%45 = call i64 @check_path(i8* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %43
br label %56
48: ; preds = %43
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8** %8
%49 = load i8*, i8** %8
%50 = call i64 @check_path(i8* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %48
br label %56
53: ; preds = %48
%54 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %52, %47, %42, %31, %19, %13
%57 = load i8*, i8** %8
ret i8* %57
}

LLVM IR (-O2):
@.str = [22 x i8] c"PROXYCHAINS_CONF_FILE\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [17 x i8] c"proxychains.conf\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [19 x i8] c"%s/.proxychains/%s\00"
@.str.5 = [22 x i8] c"/etc/proxychains.conf\00"
@.str.6 = [32 x i8] c"couldnt find configuration file\00"
define i8* @get_config_path(i8* %0, i8* %1, i64 %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = tail call i64 @check_path(i8* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %31
8: ; preds = %3
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%10 = tail call i64 @check_path(i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = call i8* @getcwd(i8* %5, i32 512)
%14 = call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%15 = call i64 @check_path(i8* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %31
17: ; preds = %12
%18 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%20 = call i64 @check_path(i8* %1)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %17
%23 = call i64 @check_path(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = call i64 @check_path(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25, %22, %17, %12, %8, %3
%32 = phi i8* [ %0, %3 ], [ %9, %8 ], [ %1, %12 ], [ %1, %17 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), %22 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), %25 ]
ret i8* %32
}