#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 = getenv("HOME");
  snprintf(pbuf, bufsize, "%s/config/settings/%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    1349 <get_config_path+0x1e9>
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    1349 <get_config_path+0x1e9>
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    0xe4f(%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    1349 <get_config_path+0x1e9>
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    0xdf4(%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    1349 <get_config_path+0x1e9>
lea    0xd8f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x228(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x228(%rbp),%rcx
lea    0xd85(%rip),%rdx
lea    0xd99(%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     12e1 <get_config_path+0x181>
jmp    1349 <get_config_path+0x1e9>
lea    0xd62(%rip),%rax
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rdi
call   1060 <check_path@plt>
cmp    $0x0,%rax
je     130a <get_config_path+0x1aa>
jmp    1349 <get_config_path+0x1e9>
lea    0xd39(%rip),%rax
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rdi
call   1060 <check_path@plt>
cmp    $0x0,%rax
je     1333 <get_config_path+0x1d3>
jmp    1349 <get_config_path+0x1e9>
lea    0xd26(%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    120d <get_config_path+0xad>
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <check_path@plt>
test   %rax,%rax
jne    120d <get_config_path+0xad>
mov    %rsp,%rdi
mov    $0x200,%esi
call   1050 <getcwd@plt>
lea    0xe63(%rip),%rdx
lea    0xe95(%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
jne    120a <get_config_path+0xaa>
lea    0xe40(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe39(%rip),%rdx
lea    0xe60(%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     121d <get_config_path+0xbd>
mov    %r15,%rbx
mov    %rbx,%rax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdf8(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe04(%rip),%rdx
lea    0xe18(%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    120d <get_config_path+0xad>
lea    0xdee(%rip),%rbx
mov    %rbx,%rdi
call   1060 <check_path@plt>
test   %rax,%rax
jne    120d <get_config_path+0xad>
lea    0xdda(%rip),%rbx
mov    %rbx,%rdi
call   1060 <check_path@plt>
test   %rax,%rax
jne    120d <get_config_path+0xad>
lea    0xddc(%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"%s/config/settings/%s\00"
@.str.6 = [22 x i8] c"/etc/proxychains.conf\00"
@.str.7 = [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 %67
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 %67
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 %67
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 %67
43: ; preds = %32
%44 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %44, i8** %8
%45 = load i8*, i8** %5
%46 = load i64, i64* %6
%47 = load i8*, i8** %8
%48 = call i32 @snprintf(i8* %45, i64 %46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %47, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%49 = load i8*, i8** %5
store i8* %49, i8** %8
%50 = load i8*, i8** %8
%51 = call i64 @check_path(i8* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %43
br label %67
54: ; preds = %43
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8** %8
%55 = load i8*, i8** %8
%56 = call i64 @check_path(i8* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %54
br label %67
59: ; preds = %54
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8** %8
%60 = load i8*, i8** %8
%61 = call i64 @check_path(i8* %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %59
br label %67
64: ; preds = %59
%65 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %63, %58, %53, %42, %31, %19, %13
%68 = load i8*, i8** %8
ret i8* %68
}

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"%s/config/settings/%s\00"
@.str.6 = [22 x i8] c"/etc/proxychains.conf\00"
@.str.7 = [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 %36
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 %36
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 %36
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 %36
22: ; preds = %17
%23 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%25 = call i64 @check_path(i8* %1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %22
%28 = call i64 @check_path(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = call i64 @check_path(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %30, %27, %22, %17, %12, %8, %3
%37 = phi i8* [ %0, %3 ], [ %9, %8 ], [ %1, %12 ], [ %1, %17 ], [ %1, %22 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), %27 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), %30 ]
ret i8* %37
}