; LLVM IR from eProsima/Fast-DDS :: src/cpp/rtps/persistence (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.Vdbe = type { ptr, ptr, ptr, ptr, i16, i32, i32, i32, i32, i32, i64, i32, i64, i64, i64, i64, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, ptr, ptr, ptr, i64, i16, i16, i8, i8, i8, i8, i16, i32, i32, [9 x i32], ptr, ptr, ptr, ptr, i32, i32, ptr, ptr }
%struct.sqlite3 = type { ptr, ptr, ptr, ptr, ptr, i32, i32, i64, i64, i64, i32, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i64, i64, [12 x i32], i32, %struct.sqlite3InitInfo, i32, i32, i32, i32, i32, i32, ptr, %union.anon, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %union.anon.0, %struct.Lookaside, ptr, ptr, ptr, ptr, i32, i32, %struct.Hash, ptr, ptr, ptr, %struct.Hash, %struct.Hash, %struct.BusyHandler, [2 x %struct.Db], ptr, i32, i32, i32, i32, i64, i64, ptr, ptr }
%struct.sqlite3InitInfo = type { i32, i8, i8, i8, ptr }
%union.anon = type { ptr }
%union.anon.0 = type { double }
%struct.Lookaside = type { i32, i16, i16, i8, i32, [3 x i32], ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.Hash = type { i32, i32, ptr, ptr }
%struct.BusyHandler = type { ptr, ptr, i32 }
%struct.Db = type { ptr, ptr, i8, i8, ptr }
%struct.sqlite3_value = type { %union.MemValue, ptr, i32, i16, i8, i8, ptr, i32, i32, ptr, ptr }
%union.MemValue = type { double }

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

; Function Attrs: nounwind uwtable
declare dso_local void @sqlite3_mutex_enter(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @sqlite3_mutex_leave(ptr noundef) #1

; 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 i32 @sqlite3_clear_bindings(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %7, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.Vdbe, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.sqlite3, ptr %10, i32 0, i32 3
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  call void @sqlite3_mutex_enter(ptr noundef %13)
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %35, %1
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Vdbe, ptr %16, i32 0, i32 4
  %18 = load i16, ptr %17, align 8, !tbaa !21
  %19 = sext i16 %18 to i32
  %20 = icmp slt i32 %15, %19
  br i1 %20, label %21, label %38

21:                                               ; preds = %14
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Vdbe, ptr %22, i32 0, i32 19
  %24 = load ptr, ptr %23, align 8, !tbaa !22
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %struct.sqlite3_value, ptr %24, i64 %26
  call void @sqlite3VdbeMemRelease(ptr noundef %27)
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Vdbe, ptr %28, i32 0, i32 19
  %30 = load ptr, ptr %29, align 8, !tbaa !22
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds %struct.sqlite3_value, ptr %30, i64 %32
  %34 = getelementptr inbounds %struct.sqlite3_value, ptr %33, i32 0, i32 3
  store i16 1, ptr %34, align 4, !tbaa !23
  br label %35

35:                                               ; preds = %21
  %36 = load i32, ptr %3, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %3, align 4, !tbaa !9
  br label %14, !llvm.loop !25

38:                                               ; preds = %14
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Vdbe, ptr %39, i32 0, i32 43
  %41 = load i32, ptr %40, align 4, !tbaa !27
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %49

43:                                               ; preds = %38
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Vdbe, ptr %44, i32 0, i32 34
  %46 = load i16, ptr %45, align 8
  %47 = and i16 %46, -4
  %48 = or i16 %47, 1
  store i16 %48, ptr %45, align 8
  br label %49

49:                                               ; preds = %43, %38
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  call void @sqlite3_mutex_leave(ptr noundef %50)
  %51 = load i32, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %51
}

; Function Attrs: nounwind uwtable
declare hidden void @sqlite3VdbeMemRelease(ptr 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 0}
!12 = !{!"Vdbe", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !14, i64 56, !10, i64 64, !14, i64 72, !14, i64 80, !14, i64 88, !14, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !10, i64 144, !10, i64 148, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !14, i64 184, !13, i64 192, !13, i64 194, !7, i64 196, !7, i64 197, !7, i64 198, !7, i64 199, !10, i64 200, !10, i64 200, !10, i64 200, !10, i64 200, !10, i64 200, !10, i64 200, !10, i64 201, !10, i64 204, !10, i64 208, !7, i64 212, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !10, i64 280, !10, i64 284, !6, i64 288, !6, i64 296}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!16, !6, i64 24}
!16 = !{!"sqlite3", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !14, i64 48, !14, i64 56, !14, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !7, i64 100, !7, i64 101, !7, i64 102, !7, i64 103, !7, i64 104, !7, i64 105, !7, i64 106, !7, i64 107, !7, i64 108, !7, i64 109, !7, i64 110, !7, i64 111, !7, i64 112, !7, i64 113, !10, i64 116, !14, i64 120, !14, i64 128, !7, i64 136, !10, i64 184, !17, i64 192, !10, i64 208, !10, i64 212, !10, i64 216, !10, i64 220, !10, i64 224, !10, i64 228, !6, i64 232, !7, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !7, i64 400, !18, i64 408, !6, i64 504, !6, i64 512, !6, i64 520, !6, i64 528, !10, i64 536, !10, i64 540, !19, i64 544, !6, i64 568, !6, i64 576, !6, i64 584, !19, i64 592, !19, i64 616, !20, i64 640, !7, i64 664, !6, i64 728, !10, i64 736, !10, i64 740, !10, i64 744, !10, i64 748, !14, i64 752, !14, i64 760, !6, i64 768, !6, i64 776}
!17 = !{!"sqlite3InitInfo", !10, i64 0, !7, i64 4, !7, i64 5, !10, i64 6, !10, i64 6, !10, i64 6, !6, i64 8}
!18 = !{!"Lookaside", !10, i64 0, !13, i64 4, !13, i64 6, !7, i64 8, !10, i64 12, !7, i64 16, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!19 = !{!"Hash", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!20 = !{!"BusyHandler", !6, i64 0, !6, i64 8, !10, i64 16}
!21 = !{!12, !13, i64 32}
!22 = !{!12, !6, i64 128}
!23 = !{!24, !13, i64 20}
!24 = !{!"sqlite3_value", !7, i64 0, !6, i64 8, !10, i64 16, !13, i64 20, !7, i64 22, !7, i64 23, !6, i64 24, !10, i64 32, !10, i64 36, !6, i64 40, !6, i64 48}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!12, !10, i64 284}


; 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.sqlite3_value = type { %union.MemValue, ptr, i32, i16, i8, i8, ptr, i32, i32, ptr, ptr }
%union.MemValue = type { double }

; Function Attrs: nounwind uwtable
declare dso_local void @sqlite3_mutex_enter(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @sqlite3_mutex_leave(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @sqlite3_clear_bindings(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !13
  tail call void @sqlite3_mutex_enter(ptr noundef %4)
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load i16, ptr %5, align 8, !tbaa !19
  %7 = icmp sgt i16 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 128
  %.pre = load ptr, ptr %8, align 8, !tbaa !20
  br label %9

9:                                                ; preds = %.lr.ph, %9
  %10 = phi ptr [ %.pre, %.lr.ph ], [ %12, %9 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %9 ]
  %11 = getelementptr inbounds %struct.sqlite3_value, ptr %10, i64 %indvars.iv
  tail call void @sqlite3VdbeMemRelease(ptr noundef %11)
  %12 = load ptr, ptr %8, align 8, !tbaa !20
  %13 = getelementptr inbounds %struct.sqlite3_value, ptr %12, i64 %indvars.iv, i32 3
  store i16 1, ptr %13, align 4, !tbaa !21
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = load i16, ptr %5, align 8, !tbaa !19
  %15 = sext i16 %14 to i64
  %16 = icmp slt i64 %indvars.iv.next, %15
  br i1 %16, label %9, label %._crit_edge, !llvm.loop !23

._crit_edge:                                      ; preds = %9, %1
  %17 = getelementptr inbounds i8, ptr %0, i64 284
  %18 = load i32, ptr %17, align 4, !tbaa !25
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %24, label %19

19:                                               ; preds = %._crit_edge
  %20 = getelementptr inbounds i8, ptr %0, i64 200
  %21 = load i16, ptr %20, align 8
  %22 = and i16 %21, -4
  %23 = or disjoint i16 %22, 1
  store i16 %23, ptr %20, align 8
  br label %24

24:                                               ; preds = %19, %._crit_edge
  tail call void @sqlite3_mutex_leave(ptr noundef %4)
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare hidden void @sqlite3VdbeMemRelease(ptr 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" }

!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 0}
!6 = !{!"Vdbe", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !12, i64 56, !11, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !11, i64 144, !11, i64 148, !7, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !12, i64 184, !10, i64 192, !10, i64 194, !8, i64 196, !8, i64 197, !8, i64 198, !8, i64 199, !11, i64 200, !11, i64 200, !11, i64 200, !11, i64 200, !11, i64 200, !11, i64 200, !11, i64 201, !11, i64 204, !11, i64 208, !8, i64 212, !7, i64 248, !7, i64 256, !7, i64 264, !7, i64 272, !11, i64 280, !11, i64 284, !7, i64 288, !7, i64 296}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!14, !7, i64 24}
!14 = !{!"sqlite3", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !11, i64 40, !11, i64 44, !12, i64 48, !12, i64 56, !12, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !8, i64 100, !8, i64 101, !8, i64 102, !8, i64 103, !8, i64 104, !8, i64 105, !8, i64 106, !8, i64 107, !8, i64 108, !8, i64 109, !8, i64 110, !8, i64 111, !8, i64 112, !8, i64 113, !11, i64 116, !12, i64 120, !12, i64 128, !8, i64 136, !11, i64 184, !15, i64 192, !11, i64 208, !11, i64 212, !11, i64 216, !11, i64 220, !11, i64 224, !11, i64 228, !7, i64 232, !8, i64 240, !7, i64 248, !7, i64 256, !7, i64 264, !7, i64 272, !7, i64 280, !7, i64 288, !7, i64 296, !7, i64 304, !7, i64 312, !7, i64 320, !7, i64 328, !7, i64 336, !7, i64 344, !7, i64 352, !7, i64 360, !7, i64 368, !7, i64 376, !7, i64 384, !7, i64 392, !8, i64 400, !16, i64 408, !7, i64 504, !7, i64 512, !7, i64 520, !7, i64 528, !11, i64 536, !11, i64 540, !17, i64 544, !7, i64 568, !7, i64 576, !7, i64 584, !17, i64 592, !17, i64 616, !18, i64 640, !8, i64 664, !7, i64 728, !11, i64 736, !11, i64 740, !11, i64 744, !11, i64 748, !12, i64 752, !12, i64 760, !7, i64 768, !7, i64 776}
!15 = !{!"sqlite3InitInfo", !11, i64 0, !8, i64 4, !8, i64 5, !11, i64 6, !11, i64 6, !11, i64 6, !7, i64 8}
!16 = !{!"Lookaside", !11, i64 0, !10, i64 4, !10, i64 6, !8, i64 8, !11, i64 12, !8, i64 16, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88}
!17 = !{!"Hash", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 16}
!18 = !{!"BusyHandler", !7, i64 0, !7, i64 8, !11, i64 16}
!19 = !{!6, !10, i64 32}
!20 = !{!6, !7, i64 128}
!21 = !{!22, !10, i64 20}
!22 = !{!"sqlite3_value", !8, i64 0, !7, i64 8, !11, i64 16, !10, i64 20, !8, i64 22, !8, i64 23, !7, i64 24, !11, i64 32, !11, i64 36, !7, i64 40, !7, i64 48}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!6, !11, i64 284}


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