#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 */
#define WRDE_NOSPACE 128
scalar_t__ asprintf(char **, char *, int /*<<< orphan*/);
int wordexp(char const *, TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ wordfree(TYPE_1__ *);
char *expand_user_path(const char *path) {
  wordexp_t result;
  char *ret = 0;
  switch (wordexp(path, &result, 0)) {
  case 0:
    break;
  case WRDE_NOSPACE:
    wordfree(&result);
  default:
    return 0;
  }
  if (asprintf(&ret, "%s", result.we_wordv[0]) < 0) {
    ret = 0;
  }
  wordfree(&result);
  return ret;
}


x86 assembly (clang, -O0):
<expand_user_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1050 <wordexp@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
test   %eax,%eax
je     1178 <expand_user_path+0x48>
jmp    1165 <expand_user_path+0x35>
mov    -0x24(%rbp),%eax
sub    $0x80,%eax
je     117d <expand_user_path+0x4d>
jmp    1186 <expand_user_path+0x56>
jmp    1193 <expand_user_path+0x63>
lea    -0x18(%rbp),%rdi
call   1040 <wordfree@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cc <expand_user_path+0x9c>
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1030 <asprintf@plt>
cmp    $0x0,%rax
jge    11bb <expand_user_path+0x8b>
movq   $0x0,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <wordfree@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_user_path>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
lea    0x8(%rsp),%rsi
xor    %ebx,%ebx
xor    %edx,%edx
call   1050 <wordexp@plt>
test   %eax,%eax
je     1164 <expand_user_path+0x34>
cmp    $0x80,%eax
jne    1195 <expand_user_path+0x65>
lea    0x8(%rsp),%rdi
call   1040 <wordfree@plt>
xor    %ebx,%ebx
jmp    1195 <expand_user_path+0x65>
mov    0x8(%rsp),%rax
mov    (%rax),%edx
lea    0xe8e(%rip),%rsi
mov    %rsp,%rdi
call   1030 <asprintf@plt>
test   %rax,%rax
jns    1187 <expand_user_path+0x57>
movq   $0x0,(%rsp)
lea    0x8(%rsp),%rdi
call   1040 <wordfree@plt>
mov    (%rsp),%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32* }
@.str = [3 x i8] c"%s\00"
define i8* @expand_user_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.TYPE_4__
%5 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %5
%6 = load i8*, i8** %3
%7 = call i32 @wordexp(i8* %6, %struct.TYPE_4__* %4, i32 0)
switch i32 %7, label %11 [
i32 0, label %8
i32 128, label %9
]
8: ; preds = %1
br label %12
9: ; preds = %1
%10 = call i32 @wordfree(%struct.TYPE_4__* %4)
br label %11
11: ; preds = %1, %9
store i8* null, i8** %2
br label %23
12: ; preds = %8
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %4, i32 0, i32 0
%14 = load i32*, i32** %13
%15 = getelementptr inbounds i32, i32* %14, i64 0
%16 = load i32, i32* %15
%17 = call i64 @asprintf(i8** %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %12
store i8* null, i8** %5
br label %20
20: ; preds = %19, %12
%21 = call i32 @wordfree(%struct.TYPE_4__* %4)
%22 = load i8*, i8** %5
store i8* %22, i8** %2
br label %23
23: ; preds = %20, %11
%24 = load i8*, i8** %2
ret i8* %24
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32* }
@.str = [3 x i8] c"%s\00"
define i8* @expand_user_path(i8* %0) {
%2 = alloca %struct.TYPE_4__
%3 = alloca i8*
%4 = bitcast %struct.TYPE_4__* %2 to i8*
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = call i32 @wordexp(i8* %0, %struct.TYPE_4__* %2, i32 0)
switch i32 %6, label %19 [
i32 0, label %9
i32 128, label %7
]
7: ; preds = %1
%8 = call i32 @wordfree(%struct.TYPE_4__* %2)
br label %19
9: ; preds = %1
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%11 = load i32*, i32** %10
%12 = load i32, i32* %11
%13 = call i64 @asprintf(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
store i8* null, i8** %3
br label %16
16: ; preds = %15, %9
%17 = call i32 @wordfree(%struct.TYPE_4__* %2)
%18 = load i8*, i8** %3
br label %19
19: ; preds = %7, %1, %16
%20 = phi i8* [ %18, %16 ], [ null, %1 ], [ null, %7 ]
ret i8* %20
}