; 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_index_info = type { i32, ptr, i32, ptr, ptr, i32, ptr, i32, i32, double, i64, i32, i64 }
%struct.sqlite3_index_constraint = type { i32, i8, i8, i32 }
%struct.HiddenIndexInfo = type { ptr, ptr, i32, i32, i32, [1 x ptr] }
%struct.WhereTerm = type { ptr, ptr, i16, i16, i16, i8, i8, i32, i32, %union.anon.16, i64, i64 }
%union.anon.16 = type { ptr }
%struct.Expr = type { i8, i8, i8, i32, %union.anon.1, ptr, ptr, %union.anon.2, i32, i32, i16, i16, %union.anon.3, ptr, %union.anon.4 }
%union.anon.1 = type { ptr }
%union.anon.2 = type { ptr }
%union.anon.3 = type { i32 }
%union.anon.4 = type { ptr }
%struct.CollSeq = type { ptr, i8, ptr, ptr, ptr }

@sqlite3StrBINARY = external hidden constant [7 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: 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 ptr @sqlite3_vtab_collation(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.sqlite3_index_info, ptr %10, i64 1
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store ptr null, ptr %6, align 8, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = icmp sge i32 %12, 0
  br i1 %13, label %14, label %56

14:                                               ; preds = %2
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.sqlite3_index_info, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = icmp slt i32 %15, %18
  br i1 %19, label %20, label %56

20:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.sqlite3_index_info, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds %struct.sqlite3_index_constraint, ptr %23, i64 %25
  %27 = getelementptr inbounds %struct.sqlite3_index_constraint, ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 4, !tbaa !16
  store i32 %28, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.HiddenIndexInfo, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = call ptr @termFromWhereClause(ptr noundef %31, i32 noundef %32)
  %34 = getelementptr inbounds %struct.WhereTerm, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  store ptr %35, ptr %9, align 8, !tbaa !5
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Expr, ptr %36, i32 0, i32 5
  %38 = load ptr, ptr %37, align 8, !tbaa !23
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %46

40:                                               ; preds = %20
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.HiddenIndexInfo, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !25
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = call ptr @sqlite3ExprCompareCollSeq(ptr noundef %43, ptr noundef %44)
  store ptr %45, ptr %7, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %40, %20
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %53

49:                                               ; preds = %46
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.CollSeq, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !26
  br label %54

53:                                               ; preds = %46
  br label %54

54:                                               ; preds = %53, %49
  %55 = phi ptr [ %52, %49 ], [ @sqlite3StrBINARY, %53 ]
  store ptr %55, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %56

56:                                               ; preds = %54, %14, %2
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret ptr %57
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @sqlite3ExprCompareCollSeq(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, !10, i64 0}
!12 = !{!"sqlite3_index_info", !10, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !10, i64 56, !10, i64 60, !13, i64 64, !14, i64 72, !10, i64 80, !14, i64 88}
!13 = !{!"double", !7, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!17, !10, i64 8}
!17 = !{!"sqlite3_index_constraint", !10, i64 0, !7, i64 4, !7, i64 5, !10, i64 8}
!18 = !{!19, !6, i64 0}
!19 = !{!"HiddenIndexInfo", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !7, i64 32}
!20 = !{!21, !6, i64 0}
!21 = !{!"WhereTerm", !6, i64 0, !6, i64 8, !22, i64 16, !22, i64 18, !22, i64 20, !7, i64 22, !7, i64 23, !10, i64 24, !10, i64 28, !7, i64 32, !14, i64 40, !14, i64 48}
!22 = !{!"short", !7, i64 0}
!23 = !{!24, !6, i64 16}
!24 = !{!"Expr", !7, i64 0, !7, i64 1, !7, i64 2, !10, i64 4, !7, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !22, i64 48, !22, i64 50, !7, i64 52, !6, i64 56, !7, i64 64}
!25 = !{!19, !6, i64 8}
!26 = !{!27, !6, i64 0}
!27 = !{!"CollSeq", !6, i64 0, !7, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}


; 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_index_constraint = type { i32, i8, i8, i32 }

@sqlite3StrBINARY = external hidden constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @sqlite3_vtab_collation(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 96
  %4 = icmp sgt i32 %1, -1
  br i1 %4, label %5, label %.thread

5:                                                ; preds = %2
  %6 = load i32, ptr %0, align 8, !tbaa !5
  %7 = icmp sgt i32 %6, %1
  br i1 %7, label %8, label %.thread

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = zext nneg i32 %1 to i64
  %12 = getelementptr inbounds %struct.sqlite3_index_constraint, ptr %10, i64 %11, i32 3
  %13 = load i32, ptr %12, align 4, !tbaa !14
  %14 = load ptr, ptr %3, align 8, !tbaa !16
  %15 = tail call ptr @termFromWhereClause(ptr noundef %14, i32 noundef %13)
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !21
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %.thread, label %19

19:                                               ; preds = %8
  %20 = getelementptr inbounds i8, ptr %0, i64 104
  %21 = load ptr, ptr %20, align 8, !tbaa !23
  %22 = tail call ptr @sqlite3ExprCompareCollSeq(ptr noundef %21, ptr noundef nonnull %16)
  %.not15 = icmp eq ptr %22, null
  br i1 %.not15, label %.thread, label %23

23:                                               ; preds = %19
  %24 = load ptr, ptr %22, align 8, !tbaa !24
  br label %.thread

.thread:                                          ; preds = %8, %23, %19, %5, %2
  %.0 = phi ptr [ null, %5 ], [ null, %2 ], [ %24, %23 ], [ @sqlite3StrBINARY, %19 ], [ @sqlite3StrBINARY, %8 ]
  ret ptr %.0
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @sqlite3ExprCompareCollSeq(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, !7, i64 0}
!6 = !{!"sqlite3_index_info", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !10, i64 48, !7, i64 56, !7, i64 60, !11, i64 64, !12, i64 72, !7, i64 80, !12, i64 88}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!6, !10, i64 8}
!14 = !{!15, !7, i64 8}
!15 = !{!"sqlite3_index_constraint", !7, i64 0, !8, i64 4, !8, i64 5, !7, i64 8}
!16 = !{!17, !10, i64 0}
!17 = !{!"HiddenIndexInfo", !10, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !8, i64 32}
!18 = !{!19, !10, i64 0}
!19 = !{!"WhereTerm", !10, i64 0, !10, i64 8, !20, i64 16, !20, i64 18, !20, i64 20, !8, i64 22, !8, i64 23, !7, i64 24, !7, i64 28, !8, i64 32, !12, i64 40, !12, i64 48}
!20 = !{!"short", !8, i64 0}
!21 = !{!22, !10, i64 16}
!22 = !{!"Expr", !8, i64 0, !8, i64 1, !8, i64 2, !7, i64 4, !8, i64 8, !10, i64 16, !10, i64 24, !8, i64 32, !7, i64 40, !7, i64 44, !20, i64 48, !20, i64 50, !8, i64 52, !10, i64 56, !8, i64 64}
!23 = !{!17, !10, i64 8}
!24 = !{!25, !10, i64 0}
!25 = !{!"CollSeq", !10, i64 0, !8, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}


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