#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__ {
  scalar_t__ we_wordc;
  int /*<<< orphan*/ *we_wordv;
};
typedef TYPE_1__ wordexp_t;
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ ret;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ stat(int /*<<< orphan*/, struct stat *);
size_t strlen(int /*<<< orphan*/);
int /*<<< orphan*/ wordexp(char *, TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ wordfree(TYPE_1__ *);
char *bbb_wildCardPath(char *path) {
  size_t size = 0;
  char *ptr = NULL;
  static char ret[1024];
  wordexp_t p;
  struct stat st;
  wordexp(path, &p, 0);
  if (p.we_wordc > 0) {
    size = strlen(*(p.we_wordv));
    if (size < sizeof(ret) && stat(*(p.we_wordv), &st) == 0) {
      memset(ret, 0, sizeof(ret));
      memcpy(ret, *(p.we_wordv), size);
      ptr = ret;
    }
  }
  wordfree(&p);
  return ptr;
}


x86 assembly (clang, -O0):
<bbb_wildCardPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1080 <wordexp@plt>
cmpq   $0x0,-0x28(%rbp)
jle    1205 <bbb_wildCardPath+0xa5>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x400,-0x10(%rbp)
jae    1200 <bbb_wildCardPath+0xa0>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jne    1200 <bbb_wildCardPath+0xa0>
lea    0x2e8d(%rip),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
lea    0x2e70(%rip),%rdi
call   1060 <memcpy@plt>
lea    0x2e64(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1205 <bbb_wildCardPath+0xa5>
lea    -0x28(%rbp),%rdi
call   1070 <wordfree@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bbb_wildCardPath>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%rsi
xor    %ebx,%ebx
xor    %edx,%edx
call   1080 <wordexp@plt>
cmpq   $0x0,(%rsp)
jle    11d3 <bbb_wildCardPath+0x73>
mov    0x8(%rsp),%rax
mov    (%rax),%edi
call   1030 <strlen@plt>
cmp    $0x3ff,%rax
ja     11a7 <bbb_wildCardPath+0x47>
mov    %rax,%r14
mov    0x8(%rsp),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1050 <stat@plt>
test   %rax,%rax
je     11ab <bbb_wildCardPath+0x4b>
xor    %ebx,%ebx
jmp    11d3 <bbb_wildCardPath+0x73>
lea    0x2eae(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <memcpy@plt>
mov    %rsp,%rdi
call   1070 <wordfree@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i64, i32* }
%struct.stat = type { i32 }
@bbb_wildCardPath.ret = internal global [1024 x i8] zeroinitializer
define i8* @bbb_wildCardPath(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca %struct.TYPE_4__
%6 = alloca %struct.stat
store i8* %0, i8** %2
store i64 0, i64* %3
store i8* null, i8** %4
%7 = load i8*, i8** %2
%8 = call i32 @wordexp(i8* %7, %struct.TYPE_4__* %5, i32 0)
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i32 0, i32 0
%10 = load i64, i64* %9
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %33
12: ; preds = %1
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i32 0, i32 1
%14 = load i32*, i32** %13
%15 = load i32, i32* %14
%16 = call i64 @strlen(i32 %15)
store i64 %16, i64* %3
%17 = load i64, i64* %3
%18 = icmp ult i64 %17, 1024
br i1 %18, label %19, label %32
19: ; preds = %12
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i32 0, i32 1
%21 = load i32*, i32** %20
%22 = load i32, i32* %21
%23 = call i64 @stat(i32 %22, %struct.stat* %6)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %19
%26 = call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bbb_wildCardPath.ret, i64 0, i64 0), i32 0, i32 1024)
%27 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i32 0, i32 1
%28 = load i32*, i32** %27
%29 = load i32, i32* %28
%30 = load i64, i64* %3
%31 = call i32 @memcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bbb_wildCardPath.ret, i64 0, i64 0), i32 %29, i64 %30)
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bbb_wildCardPath.ret, i64 0, i64 0), i8** %4
br label %32
32: ; preds = %25, %19, %12
br label %33
33: ; preds = %32, %1
%34 = call i32 @wordfree(%struct.TYPE_4__* %5)
%35 = load i8*, i8** %4
ret i8* %35
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64, i32* }
%struct.stat = type { i32 }
@bbb_wildCardPath.ret = internal global [1024 x i8] zeroinitializer
define i8* @bbb_wildCardPath(i8* %0) {
%2 = alloca %struct.TYPE_4__
%3 = alloca %struct.stat
%4 = bitcast %struct.TYPE_4__* %2 to i8*
%5 = bitcast %struct.stat* %3 to i8*
%6 = call i32 @wordexp(i8* %0, %struct.TYPE_4__* %2, i32 0)
%7 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%8 = load i64, i64* %7
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %1
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 1
%12 = load i32*, i32** %11
%13 = load i32, i32* %12
%14 = call i64 @strlen(i32 %13)
%15 = icmp ult i64 %14, 1024
br i1 %15, label %16, label %26
16: ; preds = %10
%17 = load i32*, i32** %11
%18 = load i32, i32* %17
%19 = call i64 @stat(i32 %18, %struct.stat* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bbb_wildCardPath.ret, i64 0, i64 0), i32 0, i32 1024)
%23 = load i32*, i32** %11
%24 = load i32, i32* %23
%25 = call i32 @memcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @bbb_wildCardPath.ret, i64 0, i64 0), i32 %24, i64 %14)
br label %26
26: ; preds = %10, %16, %21, %1
%27 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @bbb_wildCardPath.ret, i64 0, i64 0), %21 ], [ null, %16 ], [ null, %10 ], [ null, %1 ]
%28 = call i32 @wordfree(%struct.TYPE_4__* %2)
ret i8* %27
}