#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 /*<<< orphan*/ free(char *);
char *getenv(char *);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *resolved_bus_path(char *arg) {
  if (arg[0] != '.' && arg[0] != '/' && arg[0] != 0) {
    const char *home = getenv("HOME");
    const char *s = "/.ipc/";
    static char *path = 0;
    if (path != 0) {
      free(path);
    }
    path = malloc(sizeof(char) * (strlen(home) + strlen(s) + strlen(arg) + 2));
    strcpy(path, home);
    strcat(path, s);
    strcat(path, arg);
    return path;
  }
  return arg;
}


x86 assembly (clang, -O0):
<resolved_bus_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1257 <resolved_bus_path+0xf7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1257 <resolved_bus_path+0xf7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1257 <resolved_bus_path+0xf7>
lea    0xe5d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
lea    0xe52(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,0x2e99(%rip)
je     11d1 <resolved_bus_path+0x71>
mov    0x2e8c(%rip),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,0x2e41(%rip)
mov    0x2e3a(%rip),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcpy@plt>
mov    0x2e2a(%rip),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcat@plt>
mov    0x2e1a(%rip),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    0x2e0a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    125f <resolved_bus_path+0xff>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolved_bus_path>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
movzbl (%rdi),%eax
cmp    $0x2f,%rax
ja     1188 <resolved_bus_path+0x28>
movabs $0xc00000000001,%rcx
bt     %rax,%rcx
jb     1211 <resolved_bus_path+0xb1>
lea    0xe71(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
mov    0x2eba(%rip),%rdi
test   %rdi,%rdi
je     11a8 <resolved_bus_path+0x48>
call   1040 <free@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%r12d
lea    0xe4b(%rip),%r15
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <strlen@plt>
add    %r12d,%ebp
lea    (%rax,%rbp,1),%edi
add    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,0x2e77(%rip)
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
mov    0x2e65(%rip),%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    0x2e56(%rip),%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
mov    0x2e47(%rip),%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [7 x i8] c"/.ipc/\00"
@resolved_bus_path.path = internal global i8* null
define i8* @resolved_bus_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 46
br i1 %10, label %11, label %54
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 47
br i1 %16, label %17, label %54
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %54
23: ; preds = %17
%24 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %24, i8** %4
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %5
%25 = load i8*, i8** @resolved_bus_path.path
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i8*, i8** @resolved_bus_path.path
%29 = call i32 @free(i8* %28)
br label %30
30: ; preds = %27, %23
%31 = load i8*, i8** %4
%32 = call i32 @strlen(i8* %31)
%33 = load i8*, i8** %5
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %32, %34
%36 = load i8*, i8** %3
%37 = call i32 @strlen(i8* %36)
%38 = add nsw i32 %35, %37
%39 = add nsw i32 %38, 2
%40 = sext i32 %39 to i64
%41 = mul i64 1, %40
%42 = trunc i64 %41 to i32
%43 = call i8* @malloc(i32 %42)
store i8* %43, i8** @resolved_bus_path.path
%44 = load i8*, i8** @resolved_bus_path.path
%45 = load i8*, i8** %4
%46 = call i32 @strcpy(i8* %44, i8* %45)
%47 = load i8*, i8** @resolved_bus_path.path
%48 = load i8*, i8** %5
%49 = call i32 @strcat(i8* %47, i8* %48)
%50 = load i8*, i8** @resolved_bus_path.path
%51 = load i8*, i8** %3
%52 = call i32 @strcat(i8* %50, i8* %51)
%53 = load i8*, i8** @resolved_bus_path.path
store i8* %53, i8** %2
br label %56
54: ; preds = %17, %11, %1
%55 = load i8*, i8** %3
store i8* %55, i8** %2
br label %56
56: ; preds = %54, %30
%57 = load i8*, i8** %2
ret i8* %57
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [7 x i8] c"/.ipc/\00"
@resolved_bus_path.path = internal unnamed_addr global i8* null
define i8* @resolved_bus_path(i8* %0) {
%2 = load i8, i8* %0
switch i8 %2, label %3 [
i8 46, label %23
i8 47, label %23
i8 0, label %23
]
3: ; preds = %1
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = load i8*, i8** @resolved_bus_path.path
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @free(i8* %5)
br label %9
9: ; preds = %7, %3
%10 = tail call i32 @strlen(i8* %4)
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @strlen(i8* %0)
%13 = add i32 %10, 2
%14 = add i32 %13, %11
%15 = add i32 %14, %12
%16 = tail call i8* @malloc(i32 %15)
store i8* %16, i8** @resolved_bus_path.path
%17 = tail call i32 @strcpy(i8* %16, i8* %4)
%18 = load i8*, i8** @resolved_bus_path.path
%19 = tail call i32 @strcat(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%20 = load i8*, i8** @resolved_bus_path.path
%21 = tail call i32 @strcat(i8* %20, i8* %0)
%22 = load i8*, i8** @resolved_bus_path.path
br label %23
23: ; preds = %1, %1, %1, %9
%24 = phi i8* [ %22, %9 ], [ %0, %1 ], [ %0, %1 ], [ %0, %1 ]
ret i8* %24
}