#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ *we_wordv;
};
typedef TYPE_1__ wordexp_t;

/* Variables and functions */
char *calloc(unsigned long, int);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, unsigned long);
unsigned long strlen(int /*<<< orphan*/);
int /*<<< orphan*/ wordexp(char const *, TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ wordfree(TYPE_1__ *);
const char *host_expand_path(const char *path) {
  wordexp_t exp_result;
  wordexp(path, &exp_result, 0);
  unsigned long len = strlen(exp_result.we_wordv[0]);
  char *result = calloc(len + 1, sizeof(*result));
  memcpy(result, exp_result.we_wordv[0], len);
  wordfree(&exp_result);
  return result;
}


x86 assembly (clang, -O0):
<host_expand_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1070 <wordexp@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
call   1050 <memcpy@plt>
lea    -0x10(%rbp),%rdi
call   1060 <wordfree@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<host_expand_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%r14
mov    %r14,%rsi
xor    %edx,%edx
call   1070 <wordexp@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%edi
call   1030 <strlen@plt>
mov    %rax,%r15
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1050 <memcpy@plt>
mov    %r14,%rdi
call   1060 <wordfree@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32* }
define i8* @host_expand_path(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.TYPE_4__
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @wordexp(i8* %6, %struct.TYPE_4__* %3, i32 0)
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 0
%9 = load i32*, i32** %8
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
%12 = call i64 @strlen(i32 %11)
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = add i64 %13, 1
%15 = call i8* @calloc(i64 %14, i32 1)
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 0
%18 = load i32*, i32** %17
%19 = getelementptr inbounds i32, i32* %18, i64 0
%20 = load i32, i32* %19
%21 = load i64, i64* %4
%22 = call i32 @memcpy(i8* %16, i32 %20, i64 %21)
%23 = call i32 @wordfree(%struct.TYPE_4__* %3)
%24 = load i8*, i8** %5
ret i8* %24
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32* }
define i8* @host_expand_path(i8* %0) {
%2 = alloca %struct.TYPE_4__
%3 = bitcast %struct.TYPE_4__* %2 to i8*
%4 = call i32 @wordexp(i8* %0, %struct.TYPE_4__* %2, i32 0)
%5 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%6 = load i32*, i32** %5
%7 = load i32, i32* %6
%8 = call i64 @strlen(i32 %7)
%9 = add i64 %8, 1
%10 = call i8* @calloc(i64 %9, i32 1)
%11 = load i32*, i32** %5
%12 = load i32, i32* %11
%13 = call i32 @memcpy(i8* %10, i32 %12, i64 %8)
%14 = call i32 @wordfree(%struct.TYPE_4__* %2)
ret i8* %10
}