#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__ get_executable_dirname(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void get_default_config_path(const char *name, char *buffer, int buffer_size) {
  if (get_executable_dirname(buffer, buffer_size)) {
    strncpy(buffer, name, buffer_size);
    buffer[buffer_size - 1] = '\0';
    return;
  }
  int directory_len = strlen(buffer);
  snprintf(buffer + directory_len, buffer_size - directory_len, "/%s", name);
}


x86 assembly (clang, -O0):
<get_default_config_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <get_executable_dirname@plt>
cmp    $0x0,%rax
je     118f <get_default_config_path+0x4f>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11bc <get_default_config_path+0x7c>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
sub    -0x18(%rbp),%esi
mov    -0x8(%rbp),%rcx
lea    0xe49(%rip),%rdx
call   1050 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_default_config_path>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %edx,%esi
call   1060 <get_executable_dirname@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     1175 <get_default_config_path+0x35>
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,-0x1(%rax,%rbx,1)
pop    %rbx
pop    %r14
pop    %rbp
ret
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
sub    %eax,%ebp
lea    0xe78(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <snprintf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"/%s\00"
define void @get_default_config_path(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %5
%9 = load i32, i32* %6
%10 = call i64 @get_executable_dirname(i8* %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i8*, i8** %4
%15 = load i32, i32* %6
%16 = call i32 @strncpy(i8* %13, i8* %14, i32 %15)
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8 0, i8* %21
br label %34
22: ; preds = %3
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %7
%25 = load i8*, i8** %5
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = sub nsw i32 %29, %30
%32 = load i8*, i8** %4
%33 = call i32 @snprintf(i8* %28, i32 %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %22, %12
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"/%s\00"
define void @get_default_config_path(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @get_executable_dirname(i8* %1, i32 %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %2)
%8 = add nsw i32 %2, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 0, i8* %10
br label %17
11: ; preds = %3
%12 = tail call i32 @strlen(i8* %1)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = sub nsw i32 %2, %12
%16 = tail call i32 @snprintf(i8* %14, i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %11, %6
ret void
}