; 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.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 }

@.str.36 = external hidden unnamed_addr constant [21 x i8], align 1

; 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 hidden i32 @sqlite3MisuseError(i32 noundef) #1

; 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
declare hidden i32 @sqlite3FindDbName(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @sqlite3ErrorWithMsg(ptr noundef, i32 noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare hidden void @sqlite3Error(ptr noundef, i32 noundef) #1

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

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

18:                                               ; preds = %5
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 -1, ptr %19, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %18, %5
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %25

23:                                               ; preds = %20
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 -1, ptr %24, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %23, %20
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %31, label %28

28:                                               ; preds = %25
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = icmp sgt i32 %29, 3
  br i1 %30, label %31, label %33

31:                                               ; preds = %28, %25
  %32 = call i32 @sqlite3MisuseError(i32 noundef 183623)
  store i32 %32, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %85

33:                                               ; preds = %28
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.sqlite3, ptr %34, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  call void @sqlite3_mutex_enter(ptr noundef %36)
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %49

39:                                               ; preds = %33
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 0
  %42 = load i8, ptr %41, align 1, !tbaa !19
  %43 = sext i8 %42 to i32
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %49

45:                                               ; preds = %39
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = call i32 @sqlite3FindDbName(ptr noundef %46, ptr noundef %47)
  store i32 %48, ptr %13, align 4, !tbaa !9
  br label %50

49:                                               ; preds = %39, %33
  store i32 12, ptr %13, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %49, %45
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = icmp slt i32 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %50
  store i32 1, ptr %12, align 4, !tbaa !9
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, i32, ptr, ...) @sqlite3ErrorWithMsg(ptr noundef %54, i32 noundef 1, ptr noundef @.str.36, ptr noundef %55)
  br label %68

56:                                               ; preds = %50
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.sqlite3, ptr %57, i32 0, i32 78
  %59 = getelementptr inbounds %struct.BusyHandler, ptr %58, i32 0, i32 2
  store i32 0, ptr %59, align 8, !tbaa !20
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load i32, ptr %13, align 4, !tbaa !9
  %62 = load i32, ptr %9, align 4, !tbaa !9
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = call i32 @sqlite3Checkpoint(ptr noundef %60, i32 noundef %61, i32 noundef %62, ptr noundef %63, ptr noundef %64)
  store i32 %65, ptr %12, align 4, !tbaa !9
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load i32, ptr %12, align 4, !tbaa !9
  call void @sqlite3Error(ptr noundef %66, i32 noundef %67)
  br label %68

68:                                               ; preds = %56, %53
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = load i32, ptr %12, align 4, !tbaa !9
  %71 = call i32 @sqlite3ApiExit(ptr noundef %69, i32 noundef %70)
  store i32 %71, ptr %12, align 4, !tbaa !9
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.sqlite3, ptr %72, i32 0, i32 37
  %74 = load i32, ptr %73, align 8, !tbaa !21
  %75 = icmp eq i32 %74, 0
  br i1 %75, label %76, label %80

76:                                               ; preds = %68
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.sqlite3, ptr %77, i32 0, i32 64
  store i32 0, ptr %15, align 4, !tbaa !9
  %79 = load i32, ptr %15, align 4
  store atomic volatile i32 %79, ptr %78 monotonic, align 8
  br label %80

80:                                               ; preds = %76, %68
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.sqlite3, ptr %81, i32 0, i32 3
  %83 = load ptr, ptr %82, align 8, !tbaa !11
  call void @sqlite3_mutex_leave(ptr noundef %83)
  %84 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %84, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %85

85:                                               ; preds = %80, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %86 = load i32, ptr %6, align 4
  ret i32 %86
}

; Function Attrs: nounwind uwtable
declare hidden i32 @sqlite3Checkpoint(ptr noundef, i32 noundef, i32 noundef, ptr noundef, 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 24}
!12 = !{!"sqlite3", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !13, i64 48, !13, i64 56, !13, 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, !13, i64 120, !13, i64 128, !7, i64 136, !10, i64 184, !14, 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, !15, i64 408, !6, i64 504, !6, i64 512, !6, i64 520, !6, i64 528, !10, i64 536, !10, i64 540, !17, i64 544, !6, i64 568, !6, i64 576, !6, i64 584, !17, i64 592, !17, i64 616, !18, i64 640, !7, i64 664, !6, i64 728, !10, i64 736, !10, i64 740, !10, i64 744, !10, i64 748, !13, i64 752, !13, i64 760, !6, i64 768, !6, i64 776}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"sqlite3InitInfo", !10, i64 0, !7, i64 4, !7, i64 5, !10, i64 6, !10, i64 6, !10, i64 6, !6, i64 8}
!15 = !{!"Lookaside", !10, i64 0, !16, i64 4, !16, 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}
!16 = !{!"short", !7, i64 0}
!17 = !{!"Hash", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!18 = !{!"BusyHandler", !6, i64 0, !6, i64 8, !10, i64 16}
!19 = !{!7, !7, i64 0}
!20 = !{!12, !10, i64 656}
!21 = !{!12, !10, i64 208}


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

@.str.36 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden i32 @sqlite3MisuseError(i32 noundef) local_unnamed_addr #0

; 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
declare hidden i32 @sqlite3FindDbName(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @sqlite3ErrorWithMsg(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @sqlite3Error(ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3_wal_checkpoint_v2(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %7, label %6

6:                                                ; preds = %5
  store i32 -1, ptr %3, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %6, %5
  %.not36 = icmp eq ptr %4, null
  br i1 %.not36, label %9, label %8

8:                                                ; preds = %7
  store i32 -1, ptr %4, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %8, %7
  %or.cond = icmp ugt i32 %2, 3
  br i1 %or.cond, label %10, label %12

10:                                               ; preds = %9
  %11 = tail call i32 @sqlite3MisuseError(i32 noundef 183623)
  br label %32

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  tail call void @sqlite3_mutex_enter(ptr noundef %14)
  %.not37 = icmp eq ptr %1, null
  br i1 %.not37, label %.thread, label %15

15:                                               ; preds = %12
  %16 = load i8, ptr %1, align 1, !tbaa !18
  %.not38 = icmp eq i8 %16, 0
  br i1 %.not38, label %.thread, label %17

17:                                               ; preds = %15
  %18 = tail call i32 @sqlite3FindDbName(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %.thread

20:                                               ; preds = %17
  tail call void (ptr, i32, ptr, ...) @sqlite3ErrorWithMsg(ptr noundef nonnull %0, i32 noundef 1, ptr noundef nonnull @.str.36, ptr noundef nonnull %1)
  br label %23

.thread:                                          ; preds = %12, %15, %17
  %.03040 = phi i32 [ %18, %17 ], [ 12, %15 ], [ 12, %12 ]
  %21 = getelementptr inbounds i8, ptr %0, i64 656
  store i32 0, ptr %21, align 8, !tbaa !19
  %22 = tail call i32 @sqlite3Checkpoint(ptr noundef nonnull %0, i32 noundef %.03040, i32 noundef %2, ptr noundef %3, ptr noundef %4)
  tail call void @sqlite3Error(ptr noundef nonnull %0, i32 noundef %22)
  br label %23

23:                                               ; preds = %.thread, %20
  %.031 = phi i32 [ 1, %20 ], [ %22, %.thread ]
  %24 = tail call i32 @sqlite3ApiExit(ptr noundef nonnull %0, i32 noundef %.031)
  %25 = getelementptr inbounds i8, ptr %0, i64 208
  %26 = load i32, ptr %25, align 8, !tbaa !20
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %23
  %29 = getelementptr inbounds i8, ptr %0, i64 400
  store atomic volatile i32 0, ptr %29 monotonic, align 8
  br label %30

30:                                               ; preds = %28, %23
  %31 = load ptr, ptr %13, align 8, !tbaa !9
  tail call void @sqlite3_mutex_leave(ptr noundef %31)
  br label %32

32:                                               ; preds = %30, %10
  %.0 = phi i32 [ %11, %10 ], [ %24, %30 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @sqlite3Checkpoint(ptr noundef, i32 noundef, i32 noundef, ptr noundef, 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 24}
!10 = !{!"sqlite3", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !6, i64 40, !6, i64 44, !12, i64 48, !12, i64 56, !12, i64 64, !6, i64 72, !6, i64 76, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, 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, !6, i64 116, !12, i64 120, !12, i64 128, !7, i64 136, !6, i64 184, !13, i64 192, !6, i64 208, !6, i64 212, !6, i64 216, !6, i64 220, !6, i64 224, !6, i64 228, !11, i64 232, !7, i64 240, !11, i64 248, !11, i64 256, !11, i64 264, !11, i64 272, !11, i64 280, !11, i64 288, !11, i64 296, !11, i64 304, !11, i64 312, !11, i64 320, !11, i64 328, !11, i64 336, !11, i64 344, !11, i64 352, !11, i64 360, !11, i64 368, !11, i64 376, !11, i64 384, !11, i64 392, !7, i64 400, !14, i64 408, !11, i64 504, !11, i64 512, !11, i64 520, !11, i64 528, !6, i64 536, !6, i64 540, !16, i64 544, !11, i64 568, !11, i64 576, !11, i64 584, !16, i64 592, !16, i64 616, !17, i64 640, !7, i64 664, !11, i64 728, !6, i64 736, !6, i64 740, !6, i64 744, !6, i64 748, !12, i64 752, !12, i64 760, !11, i64 768, !11, i64 776}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"sqlite3InitInfo", !6, i64 0, !7, i64 4, !7, i64 5, !6, i64 6, !6, i64 6, !6, i64 6, !11, i64 8}
!14 = !{!"Lookaside", !6, i64 0, !15, i64 4, !15, i64 6, !7, i64 8, !6, i64 12, !7, i64 16, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88}
!15 = !{!"short", !7, i64 0}
!16 = !{!"Hash", !6, i64 0, !6, i64 4, !11, i64 8, !11, i64 16}
!17 = !{!"BusyHandler", !11, i64 0, !11, i64 8, !6, i64 16}
!18 = !{!7, !7, i64 0}
!19 = !{!10, !6, i64 656}
!20 = !{!10, !6, i64 208}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass