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

; 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
declare dso_local ptr @sqlite3_malloc64(i64 noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @sqlite3_create_filename(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call i64 @strlen(ptr noundef %17) #5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = call i64 @strlen(ptr noundef %19) #5
  %21 = add i64 %18, %20
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = call i64 @strlen(ptr noundef %22) #5
  %24 = add i64 %21, %23
  %25 = add i64 %24, 10
  store i64 %25, ptr %12, align 8, !tbaa !11
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %41, %5
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = mul nsw i32 %28, 2
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %31, label %44

31:                                               ; preds = %26
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = load i32, ptr %13, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds ptr, ptr %32, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = call i64 @strlen(ptr noundef %36) #5
  %38 = add i64 %37, 1
  %39 = load i64, ptr %12, align 8, !tbaa !11
  %40 = add i64 %39, %38
  store i64 %40, ptr %12, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %31
  %42 = load i32, ptr %13, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %13, align 4, !tbaa !9
  br label %26, !llvm.loop !13

44:                                               ; preds = %26
  %45 = load i64, ptr %12, align 8, !tbaa !11
  %46 = call ptr @sqlite3_malloc64(i64 noundef %45)
  store ptr %46, ptr %15, align 8, !tbaa !5
  store ptr %46, ptr %14, align 8, !tbaa !5
  %47 = load ptr, ptr %15, align 8, !tbaa !5
  %48 = icmp eq ptr %47, null
  br i1 %48, label %49, label %50

49:                                               ; preds = %44
  store ptr null, ptr %6, align 8
  store i32 1, ptr %16, align 4
  br label %88

50:                                               ; preds = %44
  %51 = load ptr, ptr %15, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 1 %51, i8 0, i64 4, i1 false)
  %52 = load ptr, ptr %15, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 4
  store ptr %53, ptr %15, align 8, !tbaa !5
  %54 = load ptr, ptr %15, align 8, !tbaa !5
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = call ptr @appendText(ptr noundef %54, ptr noundef %55)
  store ptr %56, ptr %15, align 8, !tbaa !5
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %70, %50
  %58 = load i32, ptr %13, align 4, !tbaa !9
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = mul nsw i32 %59, 2
  %61 = icmp slt i32 %58, %60
  br i1 %61, label %62, label %73

62:                                               ; preds = %57
  %63 = load ptr, ptr %15, align 8, !tbaa !5
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = load i32, ptr %13, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds ptr, ptr %64, i64 %66
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = call ptr @appendText(ptr noundef %63, ptr noundef %68)
  store ptr %69, ptr %15, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %62
  %71 = load i32, ptr %13, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %13, align 4, !tbaa !9
  br label %57, !llvm.loop !15

73:                                               ; preds = %57
  %74 = load ptr, ptr %15, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i32 1
  store ptr %75, ptr %15, align 8, !tbaa !5
  store i8 0, ptr %74, align 1, !tbaa !16
  %76 = load ptr, ptr %15, align 8, !tbaa !5
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = call ptr @appendText(ptr noundef %76, ptr noundef %77)
  store ptr %78, ptr %15, align 8, !tbaa !5
  %79 = load ptr, ptr %15, align 8, !tbaa !5
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = call ptr @appendText(ptr noundef %79, ptr noundef %80)
  store ptr %81, ptr %15, align 8, !tbaa !5
  %82 = load ptr, ptr %15, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i32 1
  store ptr %83, ptr %15, align 8, !tbaa !5
  store i8 0, ptr %82, align 1, !tbaa !16
  %84 = load ptr, ptr %15, align 8, !tbaa !5
  %85 = getelementptr inbounds i8, ptr %84, i32 1
  store ptr %85, ptr %15, align 8, !tbaa !5
  store i8 0, ptr %84, align 1, !tbaa !16
  %86 = load ptr, ptr %14, align 8, !tbaa !5
  %87 = getelementptr inbounds i8, ptr %86, i64 4
  store ptr %87, ptr %6, align 8
  store i32 1, ptr %16, align 4
  br label %88

88:                                               ; preds = %73, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %89 = load ptr, ptr %6, align 8
  ret ptr %89
}

; Function Attrs: nounwind uwtable
declare hidden ptr @appendText(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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!7, !7, i64 0}


; 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
declare dso_local ptr @sqlite3_malloc64(i64 noundef) 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
define dso_local noundef ptr @sqlite3_create_filename(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 {
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %8 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #3
  %9 = add i64 %6, 10
  %10 = add i64 %9, %7
  %11 = add i64 %10, %8
  %12 = shl i32 %3, 1
  %13 = icmp sgt i32 %3, 0
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %smax = tail call i32 @llvm.smax.i32(i32 %12, i32 1)
  %wide.trip.count = zext nneg i32 %smax to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.03134 = phi i64 [ %11, %.lr.ph.preheader ], [ %18, %.lr.ph ]
  %14 = getelementptr inbounds ptr, ptr %4, i64 %indvars.iv
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %15) #3
  %17 = add i64 %.03134, 1
  %18 = add i64 %17, %16
  %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 %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.031.lcssa = phi i64 [ %11, %5 ], [ %18, %.lr.ph ]
  %19 = tail call ptr @sqlite3_malloc64(i64 noundef %.031.lcssa)
  %20 = icmp eq ptr %19, null
  br i1 %20, label %31, label %21

21:                                               ; preds = %._crit_edge
  store i32 0, ptr %19, align 1
  %22 = getelementptr inbounds i8, ptr %19, i64 4
  %23 = tail call ptr @appendText(ptr noundef nonnull %22, ptr noundef %0)
  br i1 %13, label %.lr.ph40.preheader, label %._crit_edge41

.lr.ph40.preheader:                               ; preds = %21
  %smax48 = tail call i32 @llvm.smax.i32(i32 %12, i32 1)
  %wide.trip.count49 = zext nneg i32 %smax48 to i64
  br label %.lr.ph40

.lr.ph40:                                         ; preds = %.lr.ph40.preheader, %.lr.ph40
  %indvars.iv45 = phi i64 [ 0, %.lr.ph40.preheader ], [ %indvars.iv.next46, %.lr.ph40 ]
  %.038 = phi ptr [ %23, %.lr.ph40.preheader ], [ %26, %.lr.ph40 ]
  %24 = getelementptr inbounds ptr, ptr %4, i64 %indvars.iv45
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = tail call ptr @appendText(ptr noundef %.038, ptr noundef %25)
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %exitcond50.not = icmp eq i64 %indvars.iv.next46, %wide.trip.count49
  br i1 %exitcond50.not, label %._crit_edge41, label %.lr.ph40, !llvm.loop !11

._crit_edge41:                                    ; preds = %.lr.ph40, %21
  %.0.lcssa = phi ptr [ %23, %21 ], [ %26, %.lr.ph40 ]
  %27 = getelementptr inbounds i8, ptr %.0.lcssa, i64 1
  store i8 0, ptr %.0.lcssa, align 1, !tbaa !12
  %28 = tail call ptr @appendText(ptr noundef nonnull %27, ptr noundef %1)
  %29 = tail call ptr @appendText(ptr noundef %28, ptr noundef %2)
  %30 = getelementptr inbounds i8, ptr %29, i64 1
  store i8 0, ptr %29, align 1, !tbaa !12
  store i8 0, ptr %30, align 1, !tbaa !12
  br label %31

31:                                               ; preds = %._crit_edge, %._crit_edge41
  %.029 = phi ptr [ %22, %._crit_edge41 ], [ null, %._crit_edge ]
  ret ptr %.029
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!7, !7, i64 0}


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