#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*/ charchange(char *);
int /*<<< orphan*/ firstn(char *, int);
char *firstn2(char *, int);
int /*<<< orphan*/ free(char *);
char *gettype(char *);
int /*<<< orphan*/ lookahead(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ substr(char *, int, int);
int /*<<< orphan*/ tokenise(char *);
int main() {
  char *foo = "select _col1, col2, colC from test where city = \"Auckland\";";
  lookahead(foo, 1);
  lookahead(foo, 2);
  lookahead(foo, 3);
  charchange("\"Auckland\" ; ");
  charchange("  ;  ");
  firstn(foo, 5);
  char *str = firstn2(foo, 5);
  printf("First 5 chars of foo: %s \n", str);
  char *str2 = firstn2(foo, 15);
  printf("First 15 chars of foo: %s \n", str2);
  free(str);
  free(str2);
  substr(foo, 3, 3);
  char *bar;
  bar = gettype("test");
  puts(bar);
  char *baz;
  baz = gettype("*");
  puts(baz);
  tokenise(foo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10b0 <lookahead@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   10b0 <lookahead@plt>
mov    -0x10(%rbp),%rdi
mov    $0x3,%esi
call   10b0 <lookahead@plt>
lea    0xe51(%rip),%rdi
call   1080 <charchange@plt>
lea    0xe53(%rip),%rdi
call   1080 <charchange@plt>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
call   1090 <firstn@plt>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
call   1040 <firstn2@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0xf,%esi
call   1040 <firstn2@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe22(%rip),%rdi
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
mov    $0x3,%edx
mov    %edx,%esi
call   1060 <substr@plt>
lea    0xe10(%rip),%rdi
call   10a0 <gettype@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <puts@plt>
lea    0xdfc(%rip),%rdi
call   10a0 <gettype@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <puts@plt>
mov    -0x10(%rbp),%rdi
call   10c0 <tokenise@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xe54(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%esi
call   10b0 <lookahead@plt>
mov    %r14,%rdi
mov    $0x2,%esi
call   10b0 <lookahead@plt>
mov    %r14,%rdi
mov    $0x3,%esi
call   10b0 <lookahead@plt>
lea    0xe62(%rip),%rdi
call   1080 <charchange@plt>
lea    0xe64(%rip),%rdi
call   1080 <charchange@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1090 <firstn@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1040 <firstn2@plt>
mov    %rax,%r15
lea    0xe41(%rip),%rdi
mov    %rax,%rsi
call   1070 <printf@plt>
mov    %r14,%rdi
mov    $0xf,%esi
call   1040 <firstn2@plt>
mov    %rax,%rbx
lea    0xe3d(%rip),%rdi
mov    %rax,%rsi
call   1070 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
mov    $0x3,%esi
mov    $0x3,%edx
call   1060 <substr@plt>
lea    0xe28(%rip),%rdi
call   10a0 <gettype@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
lea    0xe19(%rip),%rdi
call   10a0 <gettype@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   10c0 <tokenise@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [60 x i8] c"select _col1, col2, colC from test where city = \22Auckland\22;\00"
@.str.1 = [14 x i8] c"\22Auckland\22 ; \00"
@.str.2 = [6 x i8] c" ; \00"
@.str.3 = [27 x i8] c"First 5 chars of foo: %s \0A\00"
@.str.4 = [28 x i8] c"First 15 chars of foo: %s \0A\00"
@.str.5 = [5 x i8] c"test\00"
@.str.6 = [2 x i8] c"*\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @lookahead(i8* %7, i32 1)
%9 = load i8*, i8** %2
%10 = call i32 @lookahead(i8* %9, i32 2)
%11 = load i8*, i8** %2
%12 = call i32 @lookahead(i8* %11, i32 3)
%13 = call i32 @charchange(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @charchange(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%15 = load i8*, i8** %2
%16 = call i32 @firstn(i8* %15, i32 5)
%17 = load i8*, i8** %2
%18 = call i8* @firstn2(i8* %17, i32 5)
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %2
%22 = call i8* @firstn2(i8* %21, i32 15)
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %3
%26 = call i32 @free(i8* %25)
%27 = load i8*, i8** %4
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %2
%30 = call i32 @substr(i8* %29, i32 3, i32 3)
%31 = call i8* @gettype(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = call i32 @puts(i8* %32)
%34 = call i8* @gettype(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %34, i8** %6
%35 = load i8*, i8** %6
%36 = call i32 @puts(i8* %35)
%37 = load i8*, i8** %2
%38 = call i32 @tokenise(i8* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [60 x i8] c"select _col1, col2, colC from test where city = \22Auckland\22;\00"
@.str.1 = [14 x i8] c"\22Auckland\22 ; \00"
@.str.2 = [6 x i8] c" ; \00"
@.str.3 = [27 x i8] c"First 5 chars of foo: %s \0A\00"
@.str.4 = [28 x i8] c"First 15 chars of foo: %s \0A\00"
@.str.5 = [5 x i8] c"test\00"
@.str.6 = [2 x i8] c"*\00"
define i32 @main() {
%1 = tail call i32 @lookahead(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 1)
%2 = tail call i32 @lookahead(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 2)
%3 = tail call i32 @lookahead(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 3)
%4 = tail call i32 @charchange(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @charchange(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @firstn(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 5)
%7 = tail call i8* @firstn2(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 5)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%9 = tail call i8* @firstn2(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 15)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%11 = tail call i32 @free(i8* %7)
%12 = tail call i32 @free(i8* %9)
%13 = tail call i32 @substr(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 3, i32 3)
%14 = tail call i8* @gettype(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) %14)
%16 = tail call i8* @gettype(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%17 = tail call i32 @puts(i8* dereferenceable(1) %16)
%18 = tail call i32 @tokenise(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
ret i32 0
}