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

; 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"

@minisql_parser_line_no_ = external dso_local global i32, align 4
@minisql_parser_column_no_ = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @MinisqlParserMovePos(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i8, align 1
  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) #3
  store i64 0, ptr %5, align 8, !tbaa !11
  br label %7

7:                                                ; preds = %31, %2
  %8 = load i64, ptr %5, align 8, !tbaa !11
  %9 = load ptr, ptr %4, align 8, !tbaa !9
  %10 = call i64 @strlen(ptr noundef %9) #4
  %11 = icmp ult i64 %8, %10
  br i1 %11, label %12, label %34

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !9
  %14 = load i64, ptr %5, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %13, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !13
  store i8 %16, ptr %6, align 1, !tbaa !13
  %17 = load i8, ptr %6, align 1, !tbaa !13
  %18 = sext i8 %17 to i32
  switch i32 %18, label %28 [
    i32 10, label %19
    i32 9, label %22
  ]

19:                                               ; preds = %12
  store i32 0, ptr @minisql_parser_column_no_, align 4, !tbaa !5
  %20 = load i32, ptr @minisql_parser_line_no_, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @minisql_parser_line_no_, align 4, !tbaa !5
  br label %31

22:                                               ; preds = %12
  %23 = load i32, ptr @minisql_parser_column_no_, align 4, !tbaa !5
  %24 = srem i32 %23, 4
  %25 = sub nsw i32 4, %24
  %26 = load i32, ptr @minisql_parser_column_no_, align 4, !tbaa !5
  %27 = add nsw i32 %26, %25
  store i32 %27, ptr @minisql_parser_column_no_, align 4, !tbaa !5
  br label %31

28:                                               ; preds = %12
  %29 = load i32, ptr @minisql_parser_column_no_, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @minisql_parser_column_no_, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %28, %22, %19
  %32 = load i64, ptr %5, align 8, !tbaa !11
  %33 = add i64 %32, 1
  store i64 %33, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  br label %7, !llvm.loop !14

34:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

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

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

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 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 #3 = { nounwind }
attributes #4 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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_line_no_ = external dso_local local_unnamed_addr global i32, align 4
@minisql_parser_column_no_ = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nofree nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local void @MinisqlParserMovePos(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %char0 = load i8, ptr %1, align 1
  %.not = icmp eq i8 %char0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %minisql_parser_line_no_.promoted = load i32, ptr @minisql_parser_line_no_, align 4, !tbaa !5
  %minisql_parser_column_no_.promoted = load i32, ptr @minisql_parser_column_no_, align 4, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %14
  %.05 = phi i64 [ %17, %14 ], [ 0, %.lr.ph.preheader ]
  %3 = phi i32 [ %16, %14 ], [ %minisql_parser_column_no_.promoted, %.lr.ph.preheader ]
  %4 = phi i32 [ %15, %14 ], [ %minisql_parser_line_no_.promoted, %.lr.ph.preheader ]
  %5 = getelementptr inbounds i8, ptr %1, i64 %.05
  %6 = load i8, ptr %5, align 1, !tbaa !9
  switch i8 %6, label %12 [
    i8 10, label %7
    i8 9, label %9
  ]

7:                                                ; preds = %.lr.ph
  store i32 0, ptr @minisql_parser_column_no_, align 4, !tbaa !5
  %8 = add nsw i32 %4, 1
  store i32 %8, ptr @minisql_parser_line_no_, align 4, !tbaa !5
  br label %14

9:                                                ; preds = %.lr.ph
  %10 = srem i32 %3, 4
  %reass.sub = add i32 %3, 4
  %11 = sub i32 %reass.sub, %10
  store i32 %11, ptr @minisql_parser_column_no_, align 4, !tbaa !5
  br label %14

12:                                               ; preds = %.lr.ph
  %13 = add nsw i32 %3, 1
  store i32 %13, ptr @minisql_parser_column_no_, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %12, %9, %7
  %15 = phi i32 [ %4, %12 ], [ %4, %9 ], [ %8, %7 ]
  %16 = phi i32 [ %13, %12 ], [ %11, %9 ], [ 0, %7 ]
  %17 = add nuw i64 %.05, 1
  %18 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #2
  %19 = icmp ult i64 %17, %18
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %14, %2
  ret void
}

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

attributes #0 = { nofree nounwind memory(readwrite, argmem: read, inaccessiblemem: none) 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 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 #2 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass