#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*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char **);
char **malloc(int);
char **realloc(char **, int);
int /*<<< orphan*/ stderr;
char *strtok(char *, char *);
char **psh_tok_line(char *line) {
  int buffer = 16;
  int position = 0;
  char *token;
  char **tokens;
  char **tokens_backup;
  tokens = malloc(buffer * sizeof(char *));
  if (!tokens) {
    fprintf(stderr, "psh: Allocation failure :(\n");
    exit(EXIT_FAILURE);
  }
  token = strtok(line, " \t\r\n\a");
  while (token) {
    tokens[position++] = token;
    if (position >= buffer) {
      buffer += 16;
      tokens_backup = tokens;
      tokens = realloc(tokens, buffer * sizeof(char *));
      if (!tokens) {
        free(tokens_backup);
        fprintf(stderr, "psh: Allocation failure :(\n");
        exit(EXIT_FAILURE);
      }
    }
    token = strtok(NULL, " \t\r\n\a");
  }
  tokens[position] = NULL;
  return tokens;
}


x86 assembly (clang, -O0):
<psh_tok_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x10,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bb <psh_tok_line+0x5b>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     127d <psh_tok_line+0x11d>
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1264 <psh_tok_line+0x104>
mov    -0xc(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0xc(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    125f <psh_tok_line+0xff>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1264 <psh_tok_line+0x104>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdad(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    11cf <psh_tok_line+0x6f>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psh_tok_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x80,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     120f <psh_tok_line+0xaf>
mov    %rax,%r15
lea    0xe94(%rip),%rsi
mov    %r14,%rdi
call   1070 <strtok@plt>
test   %rax,%rax
je     11ee <psh_tok_line+0x8e>
mov    $0x10,%r12d
xor    %ebx,%ebx
lea    0xe78(%rip),%r14
jmp    11bf <psh_tok_line+0x5f>
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r14,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     11ea <psh_tok_line+0x8a>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %ebx,%r12d
jg     11b0 <psh_tok_line+0x50>
lea    0x80(,%r12,8),%esi
mov    %r15,%rdi
call   1060 <realloc@plt>
test   %rax,%rax
je     1207 <psh_tok_line+0xa7>
add    $0x10,%r12d
mov    %rax,%r15
jmp    11b0 <psh_tok_line+0x50>
mov    %ebx,%eax
jmp    11f0 <psh_tok_line+0x90>
xor    %eax,%eax
movq   $0x0,(%r15,%rax,8)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

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

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