#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*/ isDelimiter(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
char *realloc(char *, int);
char *tokenize(char **input) {
  char *result, *ptr = *input;
  int size = 0, str_size = 20;
  if ((result = malloc(str_size * sizeof(char))) == NULL) {
    perror("mySH: malloc() ");
    exit(EXIT_FAILURE);
  }
  do {
    *(result + size * sizeof(char)) = *(*input);
    size++;
    if (size >= str_size) {
      if ((result = realloc(result, sizeof(char) * (str_size += 20))) == NULL) {
        perror("mySH: realloc() ");
        exit(EXIT_FAILURE);
      }
    }
  } while (!isDelimiter((*(*input)++)));
  *(*input)--;
  *(result + (size - 1) * sizeof(char)) = 0;
  return result;
}


x86 assembly (clang, -O0):
<tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x14,-0x20(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11ac <tokenize+0x5c>
lea    0xe67(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11b1 <tokenize+0x61>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x0,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jl     1225 <tokenize+0xd5>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%eax
add    $0x14,%eax
mov    %eax,-0x20(%rbp)
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1220 <tokenize+0xd0>
lea    0xe03(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1225 <tokenize+0xd5>
jmp    122a <tokenize+0xda>
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
movsbl (%rax),%edi
call   1050 <isDelimiter@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b1 <tokenize+0x61>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x0,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x14,%ebp
mov    $0x14,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     11f4 <tokenize+0xa4>
mov    %rax,%r15
mov    $0xffffffffffffffff,%rbx
jmp    119a <tokenize+0x4a>
xchg   %ax,%ax
mov    (%r14),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%r14)
movsbl (%rax),%edi
call   1050 <isDelimiter@plt>
add    $0x1,%rbx
test   %eax,%eax
jne    11db <tokenize+0x8b>
mov    (%r14),%rax
movzbl (%rax),%eax
mov    %al,0x1(%r15,%rbx,1)
lea    0x2(%rbx),%eax
cmp    %eax,%ebp
jg     1180 <tokenize+0x30>
add    $0x14,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <realloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1180 <tokenize+0x30>
lea    0xe48(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    %ebx,%eax
addq   $0xffffffffffffffff,(%r14)
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe05(%rip),%rdi
jmp    11c8 <tokenize+0x78>

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* @tokenize(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %2
%7 = load i8**, i8*** %2
%8 = load i8*, i8** %7
store i8* %8, i8** %4
store i32 0, i32* %5
store i32 20, i32* %6
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 1
%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 = %49, %19
%21 = load i8**, i8*** %2
%22 = load i8*, i8** %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %3
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 1
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 %23, i8* %28
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = icmp sge i32 %31, %32
br i1 %33, label %34, label %48
34: ; preds = %20
%35 = load i8*, i8** %3
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 20
store i32 %37, i32* %6
%38 = sext i32 %37 to i64
%39 = mul i64 1, %38
%40 = trunc i64 %39 to i32
%41 = call i8* @realloc(i8* %35, i32 %40)
store i8* %41, i8** %3
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %47
43: ; preds = %34
%44 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %34
br label %48
48: ; preds = %47, %20
br label %49
49: ; preds = %48
%50 = load i8**, i8*** %2
%51 = load i8*, i8** %50
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %50
%53 = load i8, i8* %51
%54 = sext i8 %53 to i32
%55 = call i32 @isDelimiter(i32 %54)
%56 = icmp ne i32 %55, 0
%57 = xor i1 %56, true
br i1 %57, label %20, label %58
58: ; preds = %49
%59 = load i8**, i8*** %2
%60 = load i8*, i8** %59
%61 = getelementptr inbounds i8, i8* %60, i32 -1
store i8* %61, i8** %59
%62 = load i8, i8* %60
%63 = load i8*, i8** %3
%64 = load i32, i32* %5
%65 = sub nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = mul i64 %66, 1
%68 = getelementptr inbounds i8, i8* %63, i64 %67
store i8 0, i8* %68
%69 = load i8*, i8** %3
ret i8* %69
}

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* @tokenize(i8** nocapture %0) {
%2 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %1, %26
%9 = phi i64 [ %15, %26 ], [ 0, %1 ]
%10 = phi i8* [ %27, %26 ], [ %2, %1 ]
%11 = phi i32 [ %28, %26 ], [ 20, %1 ]
%12 = load i8*, i8** %0
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %10, i64 %9
store i8 %13, i8* %14
%15 = add nuw i64 %9, 1
%16 = trunc i64 %15 to i32
%17 = icmp sgt i32 %11, %16
br i1 %17, label %26, label %18
18: ; preds = %8
%19 = add nsw i32 %11, 20
%20 = tail call i8* @realloc(i8* %10, i32 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %8, %18
%27 = phi i8* [ %20, %18 ], [ %10, %8 ]
%28 = phi i32 [ %19, %18 ], [ %11, %8 ]
%29 = load i8*, i8** %0
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8* %30, i8** %0
%31 = load i8, i8* %29
%32 = sext i8 %31 to i32
%33 = tail call i32 @isDelimiter(i32 %32)
%34 = icmp eq i32 %33, 0
br i1 %34, label %8, label %35
35: ; preds = %26
%36 = and i64 %9, 4294967295
%37 = load i8*, i8** %0
%38 = getelementptr inbounds i8, i8* %37, i64 -1
store i8* %38, i8** %0
%39 = getelementptr inbounds i8, i8* %27, i64 %36
store i8 0, i8* %39
ret i8* %27
}