#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_wordv;
};
typedef TYPE_1__ wordexp_t;

/* Variables and functions */
char *strdup(scalar_t__);
scalar_t__ wordexp(char const *, TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ wordfree(TYPE_1__ *);
const char *explode_path(const char *in) {
  const char *result = NULL;
  wordexp_t p;
  if (wordexp(in, &p, 0) != 0)
    return NULL;
  if (p.we_wordv[0])
    result = strdup(p.we_wordv[0]);
  wordfree(&p);
  return result;
}


x86 assembly (clang, -O0):
<explode_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <wordexp@plt>
cmp    $0x0,%rax
je     116a <explode_path+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    1199 <explode_path+0x69>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1188 <explode_path+0x58>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <wordfree@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<explode_path>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
xor    %ebx,%ebx
xor    %edx,%edx
call   1040 <wordexp@plt>
test   %rax,%rax
jne    116b <explode_path+0x3b>
mov    0x8(%rsp),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     115f <explode_path+0x2f>
call   1050 <strdup@plt>
mov    %rax,%rbx
jmp    1161 <explode_path+0x31>
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
call   1030 <wordfree@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64* }
define i8* @explode_path(i8* %0) {
%2 = alloca %struct.TYPE_4__
%3 = bitcast %struct.TYPE_4__* %2 to i8*
%4 = call i64 @wordexp(i8* %0, %struct.TYPE_4__* %2, i32 0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %1
%7 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%8 = load i64*, i64** %7
%9 = load i64, i64* %8
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = call i8* @strdup(i64 %9)
br label %13
13: ; preds = %11, %6
%14 = phi i8* [ %12, %11 ], [ null, %6 ]
%15 = call i32 @wordfree(%struct.TYPE_4__* %2)
br label %16
16: ; preds = %1, %13
%17 = phi i8* [ %14, %13 ], [ null, %1 ]
ret i8* %17
}