; LLVM IR from recrsn/tinydb :: database (parse_query_literal)

; 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.table_info = type { [32 x i8], i32, [32 x %struct.field], i64 }
%struct.field = type { [32 x i8], i64, i32 }
%struct.literal = type { i32, [2048 x i8], ptr, i32 }
%struct.table = type { %struct.table_info, i8, ptr, ptr }

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #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) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @table_find_field(ptr noundef byval(%struct.table_info) align 8, ptr noundef) #3

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

; Function Attrs: nounwind uwtable
define dso_local void @parse_query_literal(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 0
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = sext i8 %13 to i32
  %15 = icmp eq i32 %14, 34
  br i1 %15, label %29, label %16

16:                                               ; preds = %4
  %17 = call ptr @__ctype_b_loc() #5
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 0
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %22 = sext i8 %21 to i32
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i16, ptr %18, i64 %23
  %25 = load i16, ptr %24, align 2, !tbaa !12
  %26 = zext i16 %25 to i32
  %27 = and i32 %26, 2048
  %28 = icmp ne i32 %27, 0
  br label %29

29:                                               ; preds = %16, %4
  %30 = phi i1 [ true, %4 ], [ %28, %16 ]
  %31 = zext i1 %30 to i64
  %32 = select i1 %30, i32 0, i32 1
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.literal, ptr %33, i32 0, i32 0
  store i32 %32, ptr %34, align 8, !tbaa !14
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.literal, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !14
  %38 = icmp eq i32 %37, 1
  br i1 %38, label %39, label %72

39:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %68, %39
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %71

45:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %46, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.table, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = call i32 @table_find_field(ptr noundef byval(%struct.table_info) align 8 %51, ptr noundef %52)
  store i32 %53, ptr %10, align 4, !tbaa !9
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = icmp ne i32 %54, -1
  br i1 %55, label %56, label %67

56:                                               ; preds = %45
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds ptr, ptr %57, i64 %59
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.literal, ptr %62, i32 0, i32 2
  store ptr %61, ptr %63, align 8, !tbaa !16
  %64 = load i32, ptr %10, align 4, !tbaa !9
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.literal, ptr %65, i32 0, i32 3
  store i32 %64, ptr %66, align 8, !tbaa !17
  br label %67

67:                                               ; preds = %56, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %9, align 4, !tbaa !9
  br label %40, !llvm.loop !18

71:                                               ; preds = %44
  br label %72

72:                                               ; preds = %71, %29
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.literal, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 8, !tbaa !14
  %76 = icmp eq i32 %75, 0
  br i1 %76, label %77, label %98

77:                                               ; preds = %72
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds i8, ptr %78, i64 0
  %80 = load i8, ptr %79, align 1, !tbaa !11
  %81 = sext i8 %80 to i32
  %82 = icmp eq i32 %81, 34
  br i1 %82, label %83, label %98

83:                                               ; preds = %77
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.literal, ptr %84, i32 0, i32 1
  %86 = getelementptr inbounds [2048 x i8], ptr %85, i64 0, i64 0
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds i8, ptr %87, i64 1
  %89 = call ptr @strcpy(ptr noundef %86, ptr noundef %88) #6
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.literal, ptr %90, i32 0, i32 1
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.literal, ptr %92, i32 0, i32 1
  %94 = getelementptr inbounds [2048 x i8], ptr %93, i64 0, i64 0
  %95 = call i64 @strlen(ptr noundef %94) #7
  %96 = sub i64 %95, 1
  %97 = getelementptr inbounds [2048 x i8], ptr %91, i64 0, i64 %96
  store i8 0, ptr %97, align 1, !tbaa !11
  br label %104

98:                                               ; preds = %77, %72
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.literal, ptr %99, i32 0, i32 1
  %101 = getelementptr inbounds [2048 x i8], ptr %100, i64 0, i64 0
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = call ptr @strcpy(ptr noundef %101, ptr noundef %102) #6
  br label %104

104:                                              ; preds = %98, %83
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(none) "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) "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 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 #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 willreturn memory(none) }
attributes #6 = { nounwind }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"", !10, i64 0, !7, i64 4, !6, i64 2056, !10, i64 2064}
!16 = !{!15, !6, i64 2056}
!17 = !{!15, !10, i64 2064}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.table_info = type { [32 x i8], i32, [32 x %struct.field], i64 }
%struct.field = type { [32 x i8], i64, i32 }

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @table_find_field(ptr noundef byval(%struct.table_info) align 8, ptr noundef) local_unnamed_addr #2

; 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: nounwind uwtable
define dso_local void @parse_query_literal(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = load i8, ptr %1, align 1, !tbaa !5
  %6 = icmp eq i8 %5, 34
  br i1 %6, label %.thread, label %7

.thread:                                          ; preds = %4
  store i32 0, ptr %0, align 8, !tbaa !8
  br label %.thread28

7:                                                ; preds = %4
  %8 = tail call ptr @__ctype_b_loc() #4
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = sext i8 %5 to i64
  %11 = getelementptr inbounds i16, ptr %9, i64 %10
  %12 = load i16, ptr %11, align 2, !tbaa !13
  %13 = and i16 %12, 2048
  %14 = icmp eq i16 %13, 0
  %15 = zext i1 %14 to i32
  store i32 %15, ptr %0, align 8, !tbaa !8
  br i1 %14, label %.preheader, label %.thread28

.preheader:                                       ; preds = %7
  %16 = icmp sgt i32 %3, 0
  br i1 %16, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %.preheader
  %17 = getelementptr inbounds i8, ptr %0, i64 2056
  %18 = getelementptr inbounds i8, ptr %0, i64 2064
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %19

19:                                               ; preds = %.lr.ph, %25
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %25 ]
  %20 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = tail call i32 @table_find_field(ptr noundef byval(%struct.table_info) align 8 %21, ptr noundef nonnull %1)
  %.not25 = icmp eq i32 %22, -1
  br i1 %.not25, label %25, label %23

23:                                               ; preds = %19
  %24 = load ptr, ptr %20, align 8, !tbaa !12
  store ptr %24, ptr %17, align 8, !tbaa !15
  store i32 %22, ptr %18, align 8, !tbaa !16
  br label %25

25:                                               ; preds = %23, %19
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %19, !llvm.loop !17

._crit_edge:                                      ; preds = %25
  %.pr.pre = load i32, ptr %0, align 8, !tbaa !8
  %26 = icmp eq i32 %.pr.pre, 0
  br i1 %26, label %.thread28, label %._crit_edge.thread

.thread28:                                        ; preds = %7, %.thread, %._crit_edge
  %27 = load i8, ptr %1, align 1, !tbaa !5
  %28 = icmp eq i8 %27, 34
  br i1 %28, label %29, label %._crit_edge.thread

29:                                               ; preds = %.thread28
  %30 = getelementptr inbounds i8, ptr %0, i64 4
  %31 = getelementptr inbounds i8, ptr %1, i64 1
  %32 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %30, ptr noundef nonnull dereferenceable(1) %31) #5
  %33 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %30) #6
  %34 = add i64 %33, -1
  %35 = getelementptr inbounds [2048 x i8], ptr %30, i64 0, i64 %34
  store i8 0, ptr %35, align 1, !tbaa !5
  br label %38

._crit_edge.thread:                               ; preds = %.preheader, %.thread28, %._crit_edge
  %36 = getelementptr inbounds i8, ptr %0, i64 4
  %37 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %36, ptr noundef nonnull dereferenceable(1) %1) #5
  br label %38

38:                                               ; preds = %._crit_edge.thread, %29
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 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 #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 = { nounwind willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"", !10, i64 0, !6, i64 4, !11, i64 2056, !10, i64 2064}
!10 = !{!"int", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !6, i64 0}
!15 = !{!9, !11, i64 2056}
!16 = !{!9, !10, i64 2064}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass