#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__ {
  char **gl_pathv;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ GLOB_TILDE;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ calloc(scalar_t__, int);
scalar_t__ glob(char *, int /*<<< orphan*/, int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *CreatePathByExpandingTildePath(char *path) {
  glob_t globbuf;
  char **v;
  char *expandedPath = NULL, *result = NULL;
  assert(path != NULL);
  if (glob(path, GLOB_TILDE, NULL, &globbuf) == 0) {
    v = globbuf.gl_pathv;
    expandedPath = v[0];
    result = (char *)calloc(strlen(expandedPath) + 1, sizeof(char));
    if (result)
      strncpy(result, expandedPath, strlen(expandedPath) + 1);
    globfree(&globbuf);
  }
  return result;
}


x86 assembly (clang, -O0):
<CreatePathByExpandingTildePath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x10(%rbp),%rcx
call   1080 <glob@plt>
cmp    $0x0,%rax
jne    1224 <CreatePathByExpandingTildePath+0xc4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     121b <CreatePathByExpandingTildePath+0xbb>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <strncpy@plt>
lea    -0x10(%rbp),%rdi
call   1030 <globfree@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreatePathByExpandingTildePath>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1070 <assert@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
xor    %r15d,%r15d
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
xor    %edx,%edx
call   1080 <glob@plt>
test   %rax,%rax
jne    11e1 <CreatePathByExpandingTildePath+0x81>
mov    0x8(%rsp),%rax
mov    (%rax),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11d7 <CreatePathByExpandingTildePath+0x77>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strncpy@plt>
lea    0x8(%rsp),%rdi
call   1030 <globfree@plt>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i8** }
@GLOB_TILDE = global i32 0
define i8* @CreatePathByExpandingTildePath(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.TYPE_4__
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %5
store i8* null, i8** %6
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %2
%12 = load i32, i32* @GLOB_TILDE
%13 = call i64 @glob(i8* %11, i32 %12, i32* null, %struct.TYPE_4__* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %37
15: ; preds = %1
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 0
%17 = load i8**, i8*** %16
store i8** %17, i8*** %4
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = call i64 @strlen(i8* %21)
%23 = add nsw i64 %22, 1
%24 = call i64 @calloc(i64 %23, i32 1)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %35
28: ; preds = %15
%29 = load i8*, i8** %6
%30 = load i8*, i8** %5
%31 = load i8*, i8** %5
%32 = call i64 @strlen(i8* %31)
%33 = add nsw i64 %32, 1
%34 = call i32 @strncpy(i8* %29, i8* %30, i64 %33)
br label %35
35: ; preds = %28, %15
%36 = call i32 @globfree(%struct.TYPE_4__* %3)
br label %37
37: ; preds = %35, %1
%38 = load i8*, i8** %6
ret i8* %38
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i8** }
@GLOB_TILDE = global i32 0
define i8* @CreatePathByExpandingTildePath(i8* %0) {
%2 = alloca %struct.TYPE_4__
%3 = bitcast %struct.TYPE_4__* %2 to i8*
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = load i32, i32* @GLOB_TILDE
%8 = call i64 @glob(i8* %0, i32 %7, i32* null, %struct.TYPE_4__* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %1
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%12 = load i8**, i8*** %11
%13 = load i8*, i8** %12
%14 = call i64 @strlen(i8* dereferenceable(1) %13)
%15 = add nsw i64 %14, 1
%16 = call i64 @calloc(i64 %15, i32 1)
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i64 %16, 0
br i1 %18, label %23, label %19
19: ; preds = %10
%20 = call i64 @strlen(i8* dereferenceable(1) %13)
%21 = add nsw i64 %20, 1
%22 = call i32 @strncpy(i8* %17, i8* %13, i64 %21)
br label %23
23: ; preds = %19, %10
%24 = call i32 @globfree(%struct.TYPE_4__* %2)
br label %25
25: ; preds = %23, %1
%26 = phi i8* [ %17, %23 ], [ null, %1 ]
ret i8* %26
}