#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 we_wordc;
  int /*<<< orphan*/ *we_wordv;
};
typedef TYPE_1__ wordexp_t;

/* Variables and functions */
char *strdup_wrap(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ wordexp(char const *, TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ wordfree(TYPE_1__ *);
char *expand_string(const char *str) {
  char *s = NULL;
  wordexp_t p;
  wordexp(str, &p, 0);
  if (p.we_wordc >= 1)
    s = strdup_wrap(p.we_wordv[0], NULL, 0);
  wordfree(&p);
  return s;
}


x86 assembly (clang, -O0):
<expand_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <wordexp@plt>
cmpl   $0x1,-0x20(%rbp)
jl     1172 <expand_string+0x42>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1030 <strdup_wrap@plt>
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <wordfree@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_string>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rsi
xor    %ebx,%ebx
xor    %edx,%edx
call   1050 <wordexp@plt>
cmpl   $0x0,(%rsp)
jle    115a <expand_string+0x2a>
mov    0x8(%rsp),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <strdup_wrap@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
call   1040 <wordfree@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32* }
define i8* @expand_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.TYPE_4__
store i8* %0, i8** %2
store i8* null, i8** %3
%5 = load i8*, i8** %2
%6 = call i32 @wordexp(i8* %5, %struct.TYPE_4__* %4, i32 0)
%7 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %4, i32 0, i32 0
%8 = load i32, i32* %7
%9 = icmp sge i32 %8, 1
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %4, i32 0, i32 1
%12 = load i32*, i32** %11
%13 = getelementptr inbounds i32, i32* %12, i64 0
%14 = load i32, i32* %13
%15 = call i8* @strdup_wrap(i32 %14, i32* null, i32 0)
store i8* %15, i8** %3
br label %16
16: ; preds = %10, %1
%17 = call i32 @wordfree(%struct.TYPE_4__* %4)
%18 = load i8*, i8** %3
ret i8* %18
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32* }
define i8* @expand_string(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 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 1
%10 = load i32*, i32** %9
%11 = load i32, i32* %10
%12 = call i8* @strdup_wrap(i32 %11, i32* null, i32 0)
br label %13
13: ; preds = %8, %1
%14 = phi i8* [ %12, %8 ], [ null, %1 ]
%15 = call i32 @wordfree(%struct.TYPE_4__* %2)
ret i8* %14
}