#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int we_wordc;
  char **we_wordv;
};
typedef TYPE_1__ wordexp_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
char **calloc(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int wordexp(char *, TYPE_1__ *, int /*<<< orphan*/);
char **expand_words(char *cmd) {
  char **arg_vec;
  int s;
  wordexp_t pwordexp;
  s = wordexp(cmd, &pwordexp, 0);
  if (s != 0) {
    fprintf(stderr, "Word expansion failed.\n"
                    "\tNote that only simple "
                    "commands plus arguments are supported\n"
                    "\t(no pipelines, I/O redirection, and so on)\n");
    return NULL;
  }
  arg_vec = calloc(pwordexp.we_wordc + 1, sizeof(char *));
  if (arg_vec == NULL)
    do {
      perror("calloc");
      exit(EXIT_FAILURE);
    } while (0);
  for (s = 0; s < pwordexp.we_wordc; s++)
    arg_vec[s] = pwordexp.we_wordv[s];
  arg_vec[pwordexp.we_wordc] = NULL;
  return arg_vec;
}


x86 assembly (clang, -O0):
<expand_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1070 <wordexp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     119a <expand_words+0x4a>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1229 <expand_words+0xd9>
mov    -0x30(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d8 <expand_words+0x88>
jmp    11be <expand_words+0x6e>
lea    0xebc(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1211 <expand_words+0xc1>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11df <expand_words+0x8f>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_words>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rsi
xor    %edx,%edx
call   1080 <wordexp@plt>
test   %eax,%eax
je     1190 <expand_words+0x30>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
call   1040 <fprintf@plt>
xor    %ebx,%ebx
jmp    11ce <expand_words+0x6e>
mov    (%rsp),%r14d
lea    0x1(%r14),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     11db <expand_words+0x7b>
mov    %rax,%rbx
movslq %r14d,%r15
test   %r14d,%r14d
jle    11c6 <expand_words+0x66>
mov    0x8(%rsp),%rsi
shl    $0x3,%r14
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <memcpy@plt>
movq   $0x0,(%rbx,%r15,8)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe9f(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i8** }
@stderr = global i32 0
@.str = [129 x i8] c"Word expansion failed.\0A\09Note that only simple commands plus arguments are supported\0A\09(no pipelines, I/O redirection, and so on)\0A\00"
@.str.1 = [7 x i8] c"calloc\00"
@EXIT_FAILURE = global i32 0
define i8** @expand_words(i8* %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca %struct.TYPE_3__
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @wordexp(i8* %7, %struct.TYPE_3__* %6, i32 0)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([129 x i8], [129 x i8]* @.str, i64 0, i64 0))
store i8** null, i8*** %2
br label %54
14: ; preds = %1
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
%18 = call i8** @calloc(i32 %17, i32 8)
store i8** %18, i8*** %4
%19 = load i8**, i8*** %4
%20 = icmp eq i8** %19, null
br i1 %20, label %21, label %27
21: ; preds = %14
br label %22
22: ; preds = %21
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; No predecessors!
br label %27
27: ; preds = %26, %14
store i32 0, i32* %5
br label %28
28: ; preds = %44, %27
%29 = load i32, i32* %5
%30 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%31 = load i32, i32* %30
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %47
33: ; preds = %28
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 1
%35 = load i8**, i8*** %34
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = load i8**, i8*** %4
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
store i8* %39, i8** %43
br label %44
44: ; preds = %33
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %28
47: ; preds = %28
%48 = load i8**, i8*** %4
%49 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%50 = load i32, i32* %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %48, i64 %51
store i8* null, i8** %52
%53 = load i8**, i8*** %4
store i8** %53, i8*** %2
br label %54
54: ; preds = %47, %11
%55 = load i8**, i8*** %2
ret i8** %55
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i8** }
@stderr = global i32 0
@.str = [129 x i8] c"Word expansion failed.\0A\09Note that only simple commands plus arguments are supported\0A\09(no pipelines, I/O redirection, and so on)\0A\00"
@.str.1 = [7 x i8] c"calloc\00"
@EXIT_FAILURE = global i32 0
define noalias i8** @expand_words(i8* %0) {
%2 = alloca %struct.TYPE_3__
%3 = bitcast %struct.TYPE_3__* %2 to i8*
%4 = call i32 @wordexp(i8* %0, %struct.TYPE_3__* %2, i32 0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([129 x i8], [129 x i8]* @.str, i64 0, i64 0))
br label %31
9: ; preds = %1
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
%13 = call i8** @calloc(i32 %12, i32 8)
%14 = bitcast i8** %13 to i8*
%15 = icmp eq i8** %13, null
br i1 %15, label %24, label %16
16: ; preds = %9
%17 = icmp sgt i32 %11, 0
br i1 %17, label %18, label %28
18: ; preds = %16
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 1
%20 = bitcast i8*** %19 to i8**
%21 = load i8*, i8** %20
%22 = zext i32 %11 to i64
%23 = shl nuw nsw i64 %22, 3
br label %28
24: ; preds = %9
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %18, %16
%29 = sext i32 %11 to i64
%30 = getelementptr inbounds i8*, i8** %13, i64 %29
store i8* null, i8** %30
br label %31
31: ; preds = %28, %6
%32 = phi i8** [ null, %6 ], [ %13, %28 ]
ret i8** %32
}