#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 *GetNextToken();
int /*<<< orphan*/ TokenizeExpression(char *, char *, size_t, int);
scalar_t__ calloc(size_t, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  size_t bufferCapacity = 256;
  char *buffer = (char *)calloc(bufferCapacity, sizeof(char));
  TokenizeExpression("1-(2+3)", buffer, bufferCapacity, 0);
  const char *token = NULL;
  token = GetNextToken();
  while (token) {
    printf("%s\n", token);
    token = GetNextToken();
  }
  printf("-----\n");
  TokenizeExpression("AAAaaa", buffer, bufferCapacity, 1);
  token = GetNextToken();
  while (token) {
    printf("%s\n", token);
    token = GetNextToken();
  }
  free(buffer);
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x100,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe68(%rip),%rdi
xor    %ecx,%ecx
call   1030 <TokenizeExpression@plt>
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1060 <GetNextToken@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11df <main+0x7f>
mov    -0x20(%rbp),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <GetNextToken@plt>
mov    %rax,-0x20(%rbp)
jmp    11b2 <main+0x52>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe17(%rip),%rdi
mov    $0x1,%ecx
call   1030 <TokenizeExpression@plt>
mov    $0x0,%al
call   1060 <GetNextToken@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     123e <main+0xde>
mov    -0x20(%rbp),%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <GetNextToken@plt>
mov    %rax,-0x20(%rbp)
jmp    1211 <main+0xb1>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x100,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
lea    0xe86(%rip),%rdi
mov    $0x100,%edx
mov    %rax,%rsi
xor    %ecx,%ecx
call   1030 <TokenizeExpression@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <GetNextToken@plt>
test   %rax,%rax
je     11a6 <main+0x46>
mov    %rax,%rdi
call   1050 <puts@plt>
jmp    1190 <main+0x30>
lea    0xe62(%rip),%rdi
call   1050 <puts@plt>
lea    0xe4f(%rip),%rdi
mov    $0x100,%edx
mov    %rbx,%rsi
mov    $0x1,%ecx
call   1030 <TokenizeExpression@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <GetNextToken@plt>
test   %rax,%rax
je     11e6 <main+0x86>
mov    %rax,%rdi
call   1050 <puts@plt>
jmp    11d0 <main+0x70>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"1-(2+3)\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [7 x i8] c"-----\0A\00"
@.str.3 = [7 x i8] c"AAAaaa\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
store i64 256, i64* %2
%5 = load i64, i64* %2
%6 = call i64 @calloc(i64 %5, i32 1)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = load i64, i64* %2
%10 = call i32 @TokenizeExpression(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %8, i64 %9, i32 0)
store i8* null, i8** %4
%11 = call i8* (...) @GetNextToken()
store i8* %11, i8** %4
br label %12
12: ; preds = %15, %0
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i8* (...) @GetNextToken()
store i8* %18, i8** %4
br label %12
19: ; preds = %12
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%21 = load i8*, i8** %3
%22 = load i64, i64* %2
%23 = call i32 @TokenizeExpression(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %21, i64 %22, i32 1)
%24 = call i8* (...) @GetNextToken()
store i8* %24, i8** %4
br label %25
25: ; preds = %28, %19
%26 = load i8*, i8** %4
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i8*, i8** %4
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i8* (...) @GetNextToken()
store i8* %31, i8** %4
br label %25
32: ; preds = %25
%33 = load i8*, i8** %3
%34 = call i32 @free(i8* %33)
%35 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"1-(2+3)\00"
@.str.3 = [7 x i8] c"AAAaaa\00"
@str = [6 x i8] c"-----\00"
define i32 @main() {
%1 = tail call i64 @calloc(i64 256, i32 1)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @TokenizeExpression(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %2, i64 256, i32 0)
%4 = tail call i8* (...) @GetNextToken()
%5 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %0, %6
%7 = phi i8* [ %9, %6 ], [ %4, %0 ]
%8 = tail call i32 @puts(i8* %7)
%9 = tail call i8* (...) @GetNextToken()
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %6
11: ; preds = %6, %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @TokenizeExpression(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %2, i64 256, i32 1)
%14 = tail call i8* (...) @GetNextToken()
%15 = icmp eq i8* %14, null
br i1 %15, label %21, label %16
16: ; preds = %11, %16
%17 = phi i8* [ %19, %16 ], [ %14, %11 ]
%18 = tail call i32 @puts(i8* %17)
%19 = tail call i8* (...) @GetNextToken()
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %16
21: ; preds = %16, %11
%22 = tail call i32 @free(i8* %2)
%23 = tail call i32 (...) @getchar()
ret i32 0
}