#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 *);
int /*<<< orphan*/ runes_sprintf_dup(char **, char *, char *);
char *runes_get_daemon_socket_name() {
  char *home, *runtime_dir, *socket_dir, *socket_file;
  home = getenv("HOME");
  runtime_dir = getenv("XDG_RUNTIME_DIR");
  if (runtime_dir) {
    runes_sprintf_dup(&socket_dir,
                      "%s/"
                      "runes",
                      runtime_dir);
  } else {
    runes_sprintf_dup(&socket_dir,
                      "%s/."
                      "runes",
                      home);
  }
  runes_sprintf_dup(&socket_file,
                    "%s/"
                    "runes"
                    "d",
                    socket_dir);
  free(socket_dir);
  return socket_file;
}


x86 assembly (clang, -O0):
<runes_get_daemon_socket_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
lea    0xeb6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117c <runes_get_daemon_socket_name+0x4c>
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1050 <runes_sprintf_dup@plt>
jmp    1190 <runes_get_daemon_socket_name+0x60>
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1050 <runes_sprintf_dup@plt>
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1050 <runes_sprintf_dup@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runes_get_daemon_socket_name>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1164 <runes_get_daemon_socket_name+0x34>
lea    0xeb9(%rip),%rsi
mov    %rsp,%rdi
mov    %rax,%rdx
jmp    1171 <runes_get_daemon_socket_name+0x41>
lea    0xeb3(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
call   1050 <runes_sprintf_dup@plt>
mov    (%rsp),%rdx
lea    0xea7(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1050 <runes_sprintf_dup@plt>
mov    (%rsp),%rdi
call   1040 <free@plt>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [16 x i8] c"XDG_RUNTIME_DIR\00"
@.str.2 = [9 x i8] c"%s/runes\00"
@.str.3 = [10 x i8] c"%s/.runes\00"
@.str.4 = [10 x i8] c"%s/runesd\00"
define i8* @runes_get_daemon_socket_name() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %1
%6 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i8*, i8** %2
%11 = call i32 @runes_sprintf_dup(i8** %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %15
12: ; preds = %0
%13 = load i8*, i8** %1
%14 = call i32 @runes_sprintf_dup(i8** %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %9
%16 = load i8*, i8** %3
%17 = call i32 @runes_sprintf_dup(i8** %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %3
%19 = call i32 @free(i8* %18)
%20 = load i8*, i8** %4
ret i8* %20
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [16 x i8] c"XDG_RUNTIME_DIR\00"
@.str.2 = [9 x i8] c"%s/runes\00"
@.str.3 = [10 x i8] c"%s/.runes\00"
@.str.4 = [10 x i8] c"%s/runesd\00"
define i8* @runes_get_daemon_socket_name() {
%1 = alloca i8*
%2 = alloca i8*
%3 = bitcast i8** %1 to i8*
%4 = bitcast i8** %2 to i8*
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 @runes_sprintf_dup(i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %12
10: ; preds = %0
%11 = call i32 @runes_sprintf_dup(i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %12
12: ; preds = %10, %8
%13 = load i8*, i8** %1
%14 = call i32 @runes_sprintf_dup(i8** %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %1
%16 = call i32 @free(i8* %15)
%17 = load i8*, i8** %2
ret i8* %17
}