#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 */

/* Type definitions */

/* Variables and functions */
char **get_arguments(char *);
void *malloc(int);
char *strtok(char *, char *);
char ***parse_command(char *command, int *commands_nr) {
  int index = 0, i;
  char *aux_command;
  char **aux_commands = malloc(sizeof(char ***));
  char ***commands = malloc(sizeof(char ***));
  aux_command = strtok(command, "|");
  while (aux_command != NULL) {
    aux_commands[index] = malloc(sizeof(char *));
    aux_commands[index] = aux_command;
    *commands_nr += 1;
    index += 1;
    aux_command = strtok(NULL, "|");
  }
  for (i = 0; i < index; i++) {
    commands[i] = malloc(sizeof(char ***));
    commands[i] = get_arguments(aux_commands[i]);
  }
  return commands;
}


x86 assembly (clang, -O0):
<parse_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d8 <parse_command+0xa8>
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe36(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1177 <parse_command+0x47>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1232 <parse_command+0x102>
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <get_arguments@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11df <parse_command+0xaf>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_command>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%r13
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xea0(%rip),%rsi
mov    %r12,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11c7 <parse_command+0x97>
xor    %ebx,%ebx
lea    0xe8a(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rax,0x0(%r13,%rbx,8)
addl   $0x1,(%r15)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r12,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1180 <parse_command+0x50>
test   %ebx,%ebx
je     11c7 <parse_command+0x97>
mov    %ebx,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%rbx,8),%rdi
call   1030 <get_arguments@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11b0 <parse_command+0x80>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"|\00"
define i8*** @parse_command(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i8***
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %5
%10 = call i8* @malloc(i32 8)
%11 = bitcast i8* %10 to i8**
store i8** %11, i8*** %8
%12 = call i8* @malloc(i32 8)
%13 = bitcast i8* %12 to i8***
store i8*** %13, i8**** %9
%14 = load i8*, i8** %3
%15 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %7
br label %16
16: ; preds = %19, %2
%17 = load i8*, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %36
19: ; preds = %16
%20 = call i8* @malloc(i32 8)
%21 = load i8**, i8*** %8
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
store i8* %20, i8** %24
%25 = load i8*, i8** %7
%26 = load i8**, i8*** %8
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
store i8* %25, i8** %29
%30 = load i32*, i32** %4
%31 = load i32, i32* %30
%32 = add nsw i32 %31, 1
store i32 %32, i32* %30
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
%35 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %35, i8** %7
br label %16
36: ; preds = %16
store i32 0, i32* %6
br label %37
37: ; preds = %58, %36
%38 = load i32, i32* %6
%39 = load i32, i32* %5
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %61
41: ; preds = %37
%42 = call i8* @malloc(i32 8)
%43 = bitcast i8* %42 to i8**
%44 = load i8***, i8**** %9
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8**, i8*** %44, i64 %46
store i8** %43, i8*** %47
%48 = load i8**, i8*** %8
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i8** @get_arguments(i8* %52)
%54 = load i8***, i8**** %9
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8**, i8*** %54, i64 %56
store i8** %53, i8*** %57
br label %58
58: ; preds = %41
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
store i32 %60, i32* %6
br label %37
61: ; preds = %37
%62 = load i8***, i8**** %9
ret i8*** %62
}

LLVM IR (-O2):
@.str = [2 x i8] c"|\00"
define noalias i8*** @parse_command(i8* %0, i32* nocapture %1) {
%3 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%4 = bitcast i8* %3 to i8**
%5 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%6 = bitcast i8* %5 to i8***
%7 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %31, label %14
9: ; preds = %14
%10 = trunc i64 %20 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %31, label %12
12: ; preds = %9
%13 = and i64 %20, 4294967295
br label %23
14: ; preds = %2, %14
%15 = phi i64 [ %20, %14 ], [ 0, %2 ]
%16 = phi i8* [ %21, %14 ], [ %7, %2 ]
%17 = getelementptr inbounds i8*, i8** %4, i64 %15
store i8* %16, i8** %17
%18 = load i32, i32* %1
%19 = add nsw i32 %18, 1
store i32 %19, i32* %1
%20 = add nuw i64 %15, 1
%21 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %9, label %14
23: ; preds = %12, %23
%24 = phi i64 [ 0, %12 ], [ %29, %23 ]
%25 = getelementptr inbounds i8**, i8*** %6, i64 %24
%26 = getelementptr inbounds i8*, i8** %4, i64 %24
%27 = load i8*, i8** %26
%28 = tail call i8** @get_arguments(i8* %27)
store i8** %28, i8*** %25
%29 = add nuw nsw i64 %24, 1
%30 = icmp eq i64 %29, %13
br i1 %30, label %31, label %23
31: ; preds = %23, %2, %9
ret i8*** %6
}