; LLVM IR from QAQdev/mini-sql-engine :: src/parser (syntax_tree)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.SyntaxNode = type { i32, i32, i32, i32, ptr, ptr, ptr }
%struct.SyntaxNodeList = type { ptr, ptr }

@minisql_parser_debug_node_count_ = external global i32, align 4
@minisql_parser_line_no_ = external global i32, align 4
@minisql_parser_column_no_ = external global i32, align 4
@minisql_parser_syntax_node_list_ = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @CreateSyntaxNode(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %9 = call noalias ptr @malloc(i64 noundef 40) #6
  store ptr %9, ptr %5, align 8, !tbaa !9
  %10 = load i32, ptr @minisql_parser_debug_node_count_, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @minisql_parser_debug_node_count_, align 4, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.SyntaxNode, ptr %12, i32 0, i32 0
  store i32 %10, ptr %13, align 8, !tbaa !11
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.SyntaxNode, ptr %15, i32 0, i32 1
  store i32 %14, ptr %16, align 4, !tbaa !13
  %17 = load i32, ptr @minisql_parser_line_no_, align 4, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.SyntaxNode, ptr %18, i32 0, i32 2
  store i32 %17, ptr %19, align 8, !tbaa !14
  %20 = load i32, ptr @minisql_parser_column_no_, align 4, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.SyntaxNode, ptr %21, i32 0, i32 3
  store i32 %20, ptr %22, align 4, !tbaa !15
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.SyntaxNode, ptr %23, i32 0, i32 4
  store ptr null, ptr %24, align 8, !tbaa !16
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.SyntaxNode, ptr %25, i32 0, i32 5
  store ptr null, ptr %26, align 8, !tbaa !17
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %74

29:                                               ; preds = %2
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 5
  br i1 %31, label %32, label %54

32:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %33 = load ptr, ptr %4, align 8, !tbaa !9
  %34 = call i64 @strlen(ptr noundef %33) #7
  %35 = sub i64 %34, 1
  store i64 %35, ptr %6, align 8, !tbaa !18
  %36 = load i64, ptr %6, align 8, !tbaa !18
  %37 = call noalias ptr @malloc(i64 noundef %36) #6
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.SyntaxNode, ptr %38, i32 0, i32 6
  store ptr %37, ptr %39, align 8, !tbaa !20
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.SyntaxNode, ptr %40, i32 0, i32 6
  %42 = load ptr, ptr %41, align 8, !tbaa !20
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %43, i64 1
  %45 = load i64, ptr %6, align 8, !tbaa !18
  %46 = sub i64 %45, 1
  %47 = call ptr @strncpy(ptr noundef %42, ptr noundef %44, i64 noundef %46) #5
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.SyntaxNode, ptr %48, i32 0, i32 6
  %50 = load ptr, ptr %49, align 8, !tbaa !20
  %51 = load i64, ptr %6, align 8, !tbaa !18
  %52 = sub i64 %51, 1
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  store i8 0, ptr %53, align 1, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %73

54:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %55 = load ptr, ptr %4, align 8, !tbaa !9
  %56 = call i64 @strlen(ptr noundef %55) #7
  %57 = add i64 %56, 1
  store i64 %57, ptr %7, align 8, !tbaa !18
  %58 = load i64, ptr %7, align 8, !tbaa !18
  %59 = call noalias ptr @malloc(i64 noundef %58) #6
  %60 = load ptr, ptr %5, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.SyntaxNode, ptr %60, i32 0, i32 6
  store ptr %59, ptr %61, align 8, !tbaa !20
  %62 = load ptr, ptr %5, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.SyntaxNode, ptr %62, i32 0, i32 6
  %64 = load ptr, ptr %63, align 8, !tbaa !20
  %65 = load ptr, ptr %4, align 8, !tbaa !9
  %66 = call ptr @strcpy(ptr noundef %64, ptr noundef %65) #5
  %67 = load ptr, ptr %5, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.SyntaxNode, ptr %67, i32 0, i32 6
  %69 = load ptr, ptr %68, align 8, !tbaa !20
  %70 = load i64, ptr %7, align 8, !tbaa !18
  %71 = sub i64 %70, 1
  %72 = getelementptr inbounds i8, ptr %69, i64 %71
  store i8 0, ptr %72, align 1, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %73

73:                                               ; preds = %54, %32
  br label %77

74:                                               ; preds = %2
  %75 = load ptr, ptr %5, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.SyntaxNode, ptr %75, i32 0, i32 6
  store ptr null, ptr %76, align 8, !tbaa !20
  br label %77

77:                                               ; preds = %74, %73
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %78 = call noalias ptr @malloc(i64 noundef 16) #6
  store ptr %78, ptr %8, align 8, !tbaa !9
  %79 = load ptr, ptr %5, align 8, !tbaa !9
  %80 = load ptr, ptr %8, align 8, !tbaa !9
  %81 = getelementptr inbounds %struct.SyntaxNodeList, ptr %80, i32 0, i32 1
  store ptr %79, ptr %81, align 8, !tbaa !22
  %82 = load ptr, ptr @minisql_parser_syntax_node_list_, align 8, !tbaa !9
  %83 = icmp eq ptr %82, null
  br i1 %83, label %84, label %88

84:                                               ; preds = %77
  %85 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %85, ptr @minisql_parser_syntax_node_list_, align 8, !tbaa !9
  %86 = load ptr, ptr %8, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.SyntaxNodeList, ptr %86, i32 0, i32 0
  store ptr null, ptr %87, align 8, !tbaa !24
  br label %93

88:                                               ; preds = %77
  %89 = load ptr, ptr @minisql_parser_syntax_node_list_, align 8, !tbaa !9
  %90 = load ptr, ptr %8, align 8, !tbaa !9
  %91 = getelementptr inbounds %struct.SyntaxNodeList, ptr %90, i32 0, i32 0
  store ptr %89, ptr %91, align 8, !tbaa !24
  %92 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %92, ptr @minisql_parser_syntax_node_list_, align 8, !tbaa !9
  br label %93

93:                                               ; preds = %88, %84
  %94 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %94
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #4

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(0) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind willreturn memory(read) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { nounwind willreturn memory(read) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"SyntaxNode", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !10, i64 16, !10, i64 24, !10, i64 32}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !6, i64 12}
!16 = !{!12, !10, i64 16}
!17 = !{!12, !10, i64 24}
!18 = !{!19, !19, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!12, !10, i64 32}
!21 = !{!7, !7, i64 0}
!22 = !{!23, !10, i64 8}
!23 = !{!"SyntaxNodeList", !10, i64 0, !10, i64 8}
!24 = !{!23, !10, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@minisql_parser_debug_node_count_ = external local_unnamed_addr global i32, align 4
@minisql_parser_line_no_ = external local_unnamed_addr global i32, align 4
@minisql_parser_column_no_ = external local_unnamed_addr global i32, align 4
@minisql_parser_syntax_node_list_ = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree nounwind willreturn uwtable
define dso_local noundef ptr @CreateSyntaxNode(i32 noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #5
  %4 = load i32, ptr @minisql_parser_debug_node_count_, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  store i32 %5, ptr @minisql_parser_debug_node_count_, align 4, !tbaa !5
  store i32 %4, ptr %3, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %0, ptr %6, align 4, !tbaa !12
  %7 = load i32, ptr @minisql_parser_line_no_, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 %7, ptr %8, align 8, !tbaa !13
  %9 = load i32, ptr @minisql_parser_column_no_, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %3, i64 12
  store i32 %9, ptr %10, align 4, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %3, i64 16
  %.not = icmp eq ptr %1, null
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %11, i8 0, i64 16, i1 false)
  br i1 %.not, label %28, label %12

12:                                               ; preds = %2
  %13 = icmp eq i32 %0, 5
  %14 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #6
  %15 = getelementptr inbounds i8, ptr %3, i64 32
  br i1 %13, label %16, label %23

16:                                               ; preds = %12
  %17 = add i64 %14, -1
  %18 = tail call noalias ptr @malloc(i64 noundef %17) #5
  store ptr %18, ptr %15, align 8, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %1, i64 1
  %20 = add i64 %14, -2
  %21 = tail call ptr @strncpy(ptr noundef %18, ptr noundef nonnull %19, i64 noundef %20) #7
  %22 = getelementptr inbounds i8, ptr %18, i64 %20
  store i8 0, ptr %22, align 1, !tbaa !16
  br label %30

23:                                               ; preds = %12
  %24 = add i64 %14, 1
  %25 = tail call noalias ptr @malloc(i64 noundef %24) #5
  store ptr %25, ptr %15, align 8, !tbaa !15
  %26 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %25, ptr noundef nonnull dereferenceable(1) %1) #7
  %27 = getelementptr inbounds i8, ptr %25, i64 %14
  store i8 0, ptr %27, align 1, !tbaa !16
  br label %30

28:                                               ; preds = %2
  %29 = getelementptr inbounds i8, ptr %3, i64 32
  store ptr null, ptr %29, align 8, !tbaa !15
  br label %30

30:                                               ; preds = %16, %23, %28
  %31 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #5
  %32 = getelementptr inbounds i8, ptr %31, i64 8
  store ptr %3, ptr %32, align 8, !tbaa !17
  %33 = load ptr, ptr @minisql_parser_syntax_node_list_, align 8, !tbaa !19
  store ptr %31, ptr @minisql_parser_syntax_node_list_, align 8
  store ptr %33, ptr %31, align 8
  ret ptr %3
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { mustprogress nofree nounwind willreturn uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"SyntaxNode", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !11, i64 16, !11, i64 24, !11, i64 32}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !6, i64 4}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !6, i64 12}
!15 = !{!10, !11, i64 32}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !11, i64 8}
!18 = !{!"SyntaxNodeList", !11, i64 0, !11, i64 8}
!19 = !{!11, !11, i64 0}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MemCpyOptPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass