#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*/ create_xdg_dirs();
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *);
int strlen(char const *);
char *xdg_config_home();
char *settings_filepath(const char *settings_filename) {
  create_xdg_dirs();
  char *config_home = xdg_config_home();
  int ret_size = strlen(config_home) + strlen(settings_filename) + 1;
  char *ret_str = (char *)malloc(sizeof(char) * ret_size);
  snprintf(ret_str, ret_size, "%s%s", config_home, settings_filename);
  free(config_home);
  return ret_str;
}


x86 assembly (clang, -O0):
<settings_filepath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <create_xdg_dirs@plt>
mov    $0x0,%al
call   1070 <xdg_config_home@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xe37(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<settings_filepath>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <create_xdg_dirs@plt>
xor    %eax,%eax
call   1070 <xdg_config_home@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe59(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r12,%rcx
mov    %r14,%r8
call   1050 <snprintf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
define i8* @settings_filepath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i32 (...) @create_xdg_dirs()
%7 = call i8* (...) @xdg_config_home()
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %9, %11
%13 = add nsw i32 %12, 1
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = load i32, i32* %4
%22 = load i8*, i8** %3
%23 = load i8*, i8** %2
%24 = call i32 @snprintf(i8* %20, i32 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %23)
%25 = load i8*, i8** %3
%26 = call i32 @free(i8* %25)
%27 = load i8*, i8** %5
ret i8* %27
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
define i8* @settings_filepath(i8* %0) {
%2 = tail call i32 (...) @create_xdg_dirs()
%3 = tail call i8* (...) @xdg_config_home()
%4 = tail call i32 @strlen(i8* %3)
%5 = tail call i32 @strlen(i8* %0)
%6 = add i32 %4, 1
%7 = add i32 %6, %5
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @snprintf(i8* %9, i32 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %0)
%11 = tail call i32 @free(i8* %3)
ret i8* %9
}