#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char **malloc(int);
int /*<<< orphan*/ perror(char *);
char **realloc(char **, int);
char *tokenize(char **);
char **parseInput(char *input) {
  char **result;
  int spots = 0;
  int i = 0, outer = 0, inner = 0, pars_buf = 10;
  if ((result = malloc(pars_buf * sizeof(char *))) == NULL) {
    perror("mySH: malloc() ");
    exit(EXIT_FAILURE);
  }
  while (*input != '\0') {
    *(result + spots) = tokenize(&input);
    outer++;
    spots++;
    input++;
    if (outer >= pars_buf &&
        ((result = realloc(result, sizeof(char *) * (pars_buf += 10))) ==
         NULL)) {
      perror("mySH: realloc() ");
      exit(EXIT_FAILURE);
    }
  }
  *(result + spots) = NULL;
  return result;
}


x86 assembly (clang, -O0):
<parseInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0xa,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b6 <parseInput+0x66>
lea    0xe5d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11bb <parseInput+0x6b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1254 <parseInput+0x104>
lea    -0x8(%rbp),%rdi
call   1040 <tokenize@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     124f <parseInput+0xff>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x24(%rbp)
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    124f <parseInput+0xff>
lea    0xdd4(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11bb <parseInput+0x6b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseInput>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rdi,(%rsp)
mov    $0x50,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     120f <parseInput+0xbf>
mov    %rax,%r15
cmpb   $0x0,(%r14)
je     11dc <parseInput+0x8c>
mov    $0xa,%r12d
xor    %ebx,%ebx
mov    %rsp,%r14
jmp    1195 <parseInput+0x45>
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,(%rax)
je     11d8 <parseInput+0x88>
mov    %r14,%rdi
call   1040 <tokenize@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
mov    (%rsp),%rax
add    $0x1,%rax
mov    %rax,(%rsp)
cmp    %ebx,%r12d
jg     1190 <parseInput+0x40>
lea    0x50(,%r12,8),%esi
mov    %r15,%rdi
call   1050 <realloc@plt>
test   %rax,%rax
je     11f5 <parseInput+0xa5>
mov    %rax,%r15
add    $0xa,%r12d
mov    (%rsp),%rax
jmp    1190 <parseInput+0x40>
mov    %ebx,%eax
jmp    11de <parseInput+0x8e>
xor    %eax,%eax
movq   $0x0,(%r15,%rax,8)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe14(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xdea(%rip),%rdi
jmp    11fc <parseInput+0xac>

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

LLVM IR (-O2):
@.str = [16 x i8] c"mySH: malloc() \00"
@EXIT_FAILURE = global i32 0
@.str.1 = [17 x i8] c"mySH: realloc() \00"
define i8** @parseInput(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = tail call i8** @malloc(i32 80)
%4 = icmp eq i8** %3, null
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %42, label %12
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %5, %34
%13 = phi i64 [ %18, %34 ], [ 0, %5 ]
%14 = phi i32 [ %37, %34 ], [ 10, %5 ]
%15 = phi i8** [ %36, %34 ], [ %3, %5 ]
%16 = call i8* @tokenize(i8** %2)
%17 = getelementptr inbounds i8*, i8** %15, i64 %13
store i8* %16, i8** %17
%18 = add nuw i64 %13, 1
%19 = trunc i64 %18 to i32
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %21, i8** %2
%22 = icmp sgt i32 %14, %19
br i1 %22, label %34, label %23
23: ; preds = %12
%24 = add nsw i32 %14, 10
%25 = shl i32 %24, 3
%26 = call i8** @realloc(i8** %15, i32 %25)
%27 = icmp eq i8** %26, null
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = load i8*, i8** %2
br label %34
30: ; preds = %23
%31 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %28, %12
%35 = phi i8* [ %29, %28 ], [ %21, %12 ]
%36 = phi i8** [ %26, %28 ], [ %15, %12 ]
%37 = phi i32 [ %24, %28 ], [ %14, %12 ]
%38 = load i8, i8* %35
%39 = icmp eq i8 %38, 0
br i1 %39, label %40, label %12
40: ; preds = %34
%41 = and i64 %18, 4294967295
br label %42
42: ; preds = %40, %5
%43 = phi i64 [ 0, %5 ], [ %41, %40 ]
%44 = phi i8** [ %3, %5 ], [ %36, %40 ]
%45 = getelementptr inbounds i8*, i8** %44, i64 %43
store i8* null, i8** %45
ret i8** %44
}