#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char **malloc(int);
int /*<<< orphan*/ perror(char *);
char **realloc(char **, int);
char *strtok_r(char *, char *, char **);
char **utils_tokenize(char *line) {
  char *saveptr;
  char *token;
  uint32_t bufsize = 32;
  char **buf = malloc(bufsize * sizeof(char *));
  if (!buf) {
    perror("malloc");
    exit(EXIT_FAILURE);
  }
  int i;
  for (i = 0;; ++i, line = NULL) {
    if (i >= bufsize) {
      bufsize *= 2;
      buf = realloc(buf, bufsize * sizeof(char *));
      if (!buf) {
        perror("realloc");
        exit(EXIT_FAILURE);
      }
    }
    token = strtok_r(line, " \n\t\r\f\v", &saveptr);
    if (token == NULL)
      break;
    buf[i] = token;
  }
  buf[i] = NULL;
  return buf;
}


x86 assembly (clang, -O0):
<utils_tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x20,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119b <utils_tokenize+0x4b>
lea    0xe78(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     11f8 <utils_tokenize+0xa8>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f3 <utils_tokenize+0xa3>
lea    0xe27(%rip),%rdi
call   1060 <perror@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11f8 <utils_tokenize+0xa8>
mov    -0x8(%rbp),%rdi
lea    0xe0c(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1030 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1220 <utils_tokenize+0xd0>
jmp    1246 <utils_tokenize+0xf6>
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
movq   $0x0,-0x8(%rbp)
jmp    11a2 <utils_tokenize+0x52>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utils_tokenize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
mov    $0x100,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1207 <utils_tokenize+0xb7>
mov    %rax,%r13
mov    $0x20,%ebp
xor    %ebx,%ebx
lea    0xe8d(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebp,%rax
cmp    %rax,%rbx
jl     11af <utils_tokenize+0x5f>
mov    %ebp,%esi
shl    $0x4,%esi
mov    %r13,%rdi
call   1050 <realloc@plt>
test   %rax,%rax
je     11ed <utils_tokenize+0x9d>
mov    %rax,%r13
add    %ebp,%ebp
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strtok_r@plt>
test   %rax,%rax
je     11d0 <utils_tokenize+0x80>
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
xor    %r12d,%r12d
jmp    1190 <utils_tokenize+0x40>
mov    %ebx,%eax
movq   $0x0,0x0(%r13,%rax,8)
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe13(%rip),%rdi
call   1060 <perror@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xdf2(%rip),%rdi
jmp    11f4 <utils_tokenize+0xa4>

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

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"realloc\00"
@.str.2 = [7 x i8] c" \0A\09\0D\0C\0B\00"
define i8** @utils_tokenize(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i8** @malloc(i32 256)
%5 = icmp eq i8** %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1, %31
%11 = phi i64 [ %33, %31 ], [ 0, %1 ]
%12 = phi i8* [ null, %31 ], [ %0, %1 ]
%13 = phi i32 [ %27, %31 ], [ 32, %1 ]
%14 = phi i8** [ %28, %31 ], [ %4, %1 ]
%15 = sext i32 %13 to i64
%16 = icmp slt i64 %11, %15
br i1 %16, label %26, label %17
17: ; preds = %10
%18 = shl nsw i32 %13, 1
%19 = shl i32 %13, 4
%20 = call i8** @realloc(i8** %14, i32 %19)
%21 = icmp eq i8** %20, null
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %17, %10
%27 = phi i32 [ %18, %17 ], [ %13, %10 ]
%28 = phi i8** [ %20, %17 ], [ %14, %10 ]
%29 = call i8* @strtok_r(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %2)
%30 = icmp eq i8* %29, null
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = getelementptr inbounds i8*, i8** %28, i64 %11
store i8* %29, i8** %32
%33 = add nuw i64 %11, 1
br label %10
34: ; preds = %26
%35 = and i64 %11, 4294967295
%36 = getelementptr inbounds i8*, i8** %28, i64 %35
store i8* null, i8** %36
ret i8** %28
}