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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%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>
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    0xe31(%rip),%rdi
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
mov    $0x3,%edx
mov    %edx,%esi
call   1060 <substr@plt>
lea    0xe27(%rip),%rdi
call   10a0 <gettype@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <puts@plt>
lea    0xe13(%rip),%rdi
call   10a0 <gettype@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1080 <charchange@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe65(%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>
mov    %r14,%rdi
mov    $0x5,%esi
call   1090 <firstn@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1040 <firstn2@plt>
mov    %rax,%rbx
lea    0xe4a(%rip),%rdi
mov    %rax,%rsi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
mov    $0x3,%esi
mov    $0x3,%edx
call   1060 <substr@plt>
lea    0xe3c(%rip),%rdi
call   10a0 <gettype@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
lea    0xe2d(%rip),%rdi
call   10a0 <gettype@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1080 <charchange@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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