; LLVM IR from gigimushroom/DatabaseBackendEngine :: src/sqlite (sqlite3)

; 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.sqlite3_context = type { ptr, ptr, ptr, ptr, i32, i32, i8, i8, i8, [1 x ptr] }
%struct.Vdbe = type <{ ptr, ptr, ptr, ptr, i16, [2 x i8], i32, i32, i32, i32, i32, i32, i32, i32, [4 x i8], i64, i64, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i32, i16, i8, i8, i8, i16, i8, i32, i32, [7 x i32], ptr, ptr, ptr, ptr, i32, i32, ptr, ptr }>
%struct.AuxData = type { i32, i32, ptr, 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @sqlite3_set_auxdata(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.sqlite3_context, ptr %12, i32 0, i32 3
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  store ptr %14, ptr %10, align 8, !tbaa !5
  %15 = load ptr, ptr %10, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Vdbe, ptr %15, i32 0, i32 46
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  store ptr %17, ptr %9, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %40, %4
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %44

21:                                               ; preds = %18
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.AuxData, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !17
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp eq i32 %24, %25
  br i1 %26, label %27, label %39

27:                                               ; preds = %21
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.AuxData, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !19
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.sqlite3_context, ptr %31, i32 0, i32 4
  %33 = load i32, ptr %32, align 8, !tbaa !20
  %34 = icmp eq i32 %30, %33
  br i1 %34, label %38, label %35

35:                                               ; preds = %27
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %35, %27
  br label %44

39:                                               ; preds = %35, %21
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.AuxData, ptr %41, i32 0, i32 4
  %43 = load ptr, ptr %42, align 8, !tbaa !21
  store ptr %43, ptr %9, align 8, !tbaa !5
  br label %18, !llvm.loop !22

44:                                               ; preds = %38, %18
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %83

47:                                               ; preds = %44
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Vdbe, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !24
  %51 = call ptr @sqlite3DbMallocZero(ptr noundef %50, i64 noundef 32)
  store ptr %51, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %55, label %54

54:                                               ; preds = %47
  br label %103

55:                                               ; preds = %47
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.sqlite3_context, ptr %56, i32 0, i32 4
  %58 = load i32, ptr %57, align 8, !tbaa !20
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.AuxData, ptr %59, i32 0, i32 0
  store i32 %58, ptr %60, align 8, !tbaa !19
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.AuxData, ptr %62, i32 0, i32 1
  store i32 %61, ptr %63, align 4, !tbaa !17
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.Vdbe, ptr %64, i32 0, i32 46
  %66 = load ptr, ptr %65, align 8, !tbaa !13
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.AuxData, ptr %67, i32 0, i32 4
  store ptr %66, ptr %68, align 8, !tbaa !21
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.Vdbe, ptr %70, i32 0, i32 46
  store ptr %69, ptr %71, align 8, !tbaa !13
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.sqlite3_context, ptr %72, i32 0, i32 7
  %74 = load i8, ptr %73, align 1, !tbaa !25
  %75 = zext i8 %74 to i32
  %76 = icmp eq i32 %75, 0
  br i1 %76, label %77, label %82

77:                                               ; preds = %55
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.sqlite3_context, ptr %78, i32 0, i32 5
  store i32 0, ptr %79, align 4, !tbaa !26
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.sqlite3_context, ptr %80, i32 0, i32 7
  store i8 1, ptr %81, align 1, !tbaa !25
  br label %82

82:                                               ; preds = %77, %55
  br label %96

83:                                               ; preds = %44
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.AuxData, ptr %84, i32 0, i32 3
  %86 = load ptr, ptr %85, align 8, !tbaa !27
  %87 = icmp ne ptr %86, null
  br i1 %87, label %88, label %95

88:                                               ; preds = %83
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.AuxData, ptr %89, i32 0, i32 3
  %91 = load ptr, ptr %90, align 8, !tbaa !27
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.AuxData, ptr %92, i32 0, i32 2
  %94 = load ptr, ptr %93, align 8, !tbaa !28
  call void %91(ptr noundef %94)
  br label %95

95:                                               ; preds = %88, %83
  br label %96

96:                                               ; preds = %95, %82
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.AuxData, ptr %98, i32 0, i32 2
  store ptr %97, ptr %99, align 8, !tbaa !28
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  %101 = load ptr, ptr %9, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.AuxData, ptr %101, i32 0, i32 3
  store ptr %100, ptr %102, align 8, !tbaa !27
  store i32 1, ptr %11, align 4
  br label %110

103:                                              ; preds = %54
  %104 = load ptr, ptr %8, align 8, !tbaa !5
  %105 = icmp ne ptr %104, null
  br i1 %105, label %106, label %109

106:                                              ; preds = %103
  %107 = load ptr, ptr %8, align 8, !tbaa !5
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  call void %107(ptr noundef %108)
  br label %109

109:                                              ; preds = %106, %103
  store i32 0, ptr %11, align 4
  br label %110

110:                                              ; preds = %109, %96
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %111 = load i32, ptr %11, align 4
  switch i32 %111, label %113 [
    i32 0, label %112
    i32 1, label %112
  ]

112:                                              ; preds = %110, %110
  ret void

113:                                              ; preds = %110
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden ptr @sqlite3DbMallocZero(ptr noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"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 = !{!12, !6, i64 24}
!12 = !{!"sqlite3_context", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !7, i64 40, !7, i64 41, !7, i64 42, !7, i64 48}
!13 = !{!14, !6, i64 280}
!14 = !{!"Vdbe", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !15, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !16, i64 72, !16, i64 80, !16, i64 88, !16, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !16, i64 176, !10, i64 184, !15, i64 188, !7, i64 190, !7, i64 191, !7, i64 192, !10, i64 193, !10, i64 193, !10, i64 193, !10, i64 193, !10, i64 193, !10, i64 193, !10, i64 193, !10, i64 194, !10, i64 196, !10, i64 200, !7, i64 204, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !10, i64 264, !10, i64 268, !6, i64 272, !6, i64 280}
!15 = !{!"short", !7, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = !{!18, !10, i64 4}
!18 = !{!"AuxData", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !6, i64 24}
!19 = !{!18, !10, i64 0}
!20 = !{!12, !10, i64 32}
!21 = !{!18, !6, i64 24}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!14, !6, i64 0}
!25 = !{!12, !7, i64 41}
!26 = !{!12, !10, i64 36}
!27 = !{!18, !6, i64 16}
!28 = !{!18, !6, i64 8}


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

; Function Attrs: nounwind uwtable
define dso_local void @sqlite3_set_auxdata(ptr nocapture noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 280
  %.041 = load ptr, ptr %7, align 8, !tbaa !11
  %cond42 = icmp eq ptr %.041, null
  br i1 %cond42, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = icmp slt i32 %1, 0
  br i1 %9, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %13
  %.043.us = phi ptr [ %.0.us, %13 ], [ %.041, %.lr.ph ]
  %10 = getelementptr inbounds i8, ptr %.043.us, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = icmp eq i32 %11, %1
  br i1 %12, label %.split.us, label %13

13:                                               ; preds = %.lr.ph.split.us
  %14 = getelementptr inbounds i8, ptr %.043.us, i64 24
  %.0.us = load ptr, ptr %14, align 8, !tbaa !11
  %cond.us = icmp eq ptr %.0.us, null
  br i1 %cond.us, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !14

.lr.ph.split:                                     ; preds = %.lr.ph, %22
  %.043 = phi ptr [ %.0, %22 ], [ %.041, %.lr.ph ]
  %15 = getelementptr inbounds i8, ptr %.043, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = icmp eq i32 %16, %1
  br i1 %17, label %18, label %22

18:                                               ; preds = %.lr.ph.split
  %19 = load i32, ptr %.043, align 8, !tbaa !16
  %20 = load i32, ptr %8, align 8, !tbaa !17
  %21 = icmp eq i32 %19, %20
  br i1 %21, label %.split.us, label %22

22:                                               ; preds = %.lr.ph.split, %18
  %23 = getelementptr inbounds i8, ptr %.043, i64 24
  %.0 = load ptr, ptr %23, align 8, !tbaa !11
  %cond = icmp eq ptr %.0, null
  br i1 %cond, label %._crit_edge, label %.lr.ph.split, !llvm.loop !14

._crit_edge:                                      ; preds = %22, %13, %4
  %24 = load ptr, ptr %6, align 8, !tbaa !18
  %25 = tail call ptr @sqlite3DbMallocZero(ptr noundef %24, i64 noundef 32)
  %.not38 = icmp eq ptr %25, null
  br i1 %.not38, label %45, label %26

26:                                               ; preds = %._crit_edge
  %27 = getelementptr inbounds i8, ptr %0, i64 32
  %28 = load i32, ptr %27, align 8, !tbaa !17
  store i32 %28, ptr %25, align 8, !tbaa !16
  %29 = getelementptr inbounds i8, ptr %25, i64 4
  store i32 %1, ptr %29, align 4, !tbaa !12
  %30 = load ptr, ptr %7, align 8, !tbaa !22
  %31 = getelementptr inbounds i8, ptr %25, i64 24
  store ptr %30, ptr %31, align 8, !tbaa !23
  store ptr %25, ptr %7, align 8, !tbaa !22
  %32 = getelementptr inbounds i8, ptr %0, i64 41
  %33 = load i8, ptr %32, align 1, !tbaa !24
  %34 = icmp eq i8 %33, 0
  br i1 %34, label %35, label %42

35:                                               ; preds = %26
  %36 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 0, ptr %36, align 4, !tbaa !25
  store i8 1, ptr %32, align 1, !tbaa !24
  br label %42

.split.us:                                        ; preds = %18, %.lr.ph.split.us
  %.us-phi = phi ptr [ %.043.us, %.lr.ph.split.us ], [ %.043, %18 ]
  %37 = getelementptr inbounds i8, ptr %.us-phi, i64 16
  %38 = load ptr, ptr %37, align 8, !tbaa !26
  %.not37 = icmp eq ptr %38, null
  br i1 %.not37, label %42, label %39

39:                                               ; preds = %.split.us
  %40 = getelementptr inbounds i8, ptr %.us-phi, i64 8
  %41 = load ptr, ptr %40, align 8, !tbaa !27
  tail call void %38(ptr noundef %41) #1
  br label %42

42:                                               ; preds = %.split.us, %39, %26, %35
  %.1 = phi ptr [ %25, %35 ], [ %25, %26 ], [ %.us-phi, %39 ], [ %.us-phi, %.split.us ]
  %43 = getelementptr inbounds i8, ptr %.1, i64 8
  store ptr %2, ptr %43, align 8, !tbaa !27
  %44 = getelementptr inbounds i8, ptr %.1, i64 16
  store ptr %3, ptr %44, align 8, !tbaa !26
  br label %47

45:                                               ; preds = %._crit_edge
  %.not39 = icmp eq ptr %3, null
  br i1 %.not39, label %47, label %46

46:                                               ; preds = %45
  tail call void %3(ptr noundef %2) #1
  br label %47

47:                                               ; preds = %45, %46, %42
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden ptr @sqlite3DbMallocZero(ptr noundef, i64 noundef) local_unnamed_addr #0

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 = { 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, !7, i64 24}
!6 = !{!"sqlite3_context", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36, !8, i64 40, !8, i64 41, !8, i64 42, !8, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 4}
!13 = !{!"AuxData", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 16, !7, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!13, !10, i64 0}
!17 = !{!6, !10, i64 32}
!18 = !{!19, !7, i64 0}
!19 = !{!"Vdbe", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !20, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !21, i64 72, !21, i64 80, !21, i64 88, !21, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !7, i64 160, !7, i64 168, !21, i64 176, !10, i64 184, !20, i64 188, !8, i64 190, !8, i64 191, !8, i64 192, !10, i64 193, !10, i64 193, !10, i64 193, !10, i64 193, !10, i64 193, !10, i64 193, !10, i64 193, !10, i64 194, !10, i64 196, !10, i64 200, !8, i64 204, !7, i64 232, !7, i64 240, !7, i64 248, !7, i64 256, !10, i64 264, !10, i64 268, !7, i64 272, !7, i64 280}
!20 = !{!"short", !8, i64 0}
!21 = !{!"long long", !8, i64 0}
!22 = !{!19, !7, i64 280}
!23 = !{!13, !7, i64 24}
!24 = !{!6, !8, i64 41}
!25 = !{!6, !10, i64 36}
!26 = !{!13, !7, i64 16}
!27 = !{!13, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass