; LLVM IR from seppo0010/rlite :: src (rlite)

; 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.rlite = type { i64, i64, i32, ptr, i64, i64, i64, ptr, i32, i32, i32, i32, ptr, i64, i64, ptr, i64, i64, ptr, 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_ensure_pages(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_create_db(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call i32 @rl_ensure_pages(ptr noundef %5)
  store i32 %6, ptr %3, align 4, !tbaa !9
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = icmp ne i32 0, %7
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  br label %81

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.rlite, ptr %11, i32 0, i32 5
  store i64 1, ptr %12, align 8, !tbaa !11
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.rlite, ptr %13, i32 0, i32 0
  store i64 1, ptr %14, align 8, !tbaa !14
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.rlite, ptr %15, i32 0, i32 4
  store i64 1, ptr %16, align 8, !tbaa !15
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.rlite, ptr %17, i32 0, i32 1
  store i64 1, ptr %18, align 8, !tbaa !16
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.rlite, ptr %19, i32 0, i32 10
  store i32 0, ptr %20, align 8, !tbaa !17
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.rlite, ptr %21, i32 0, i32 9
  store i32 0, ptr %22, align 4, !tbaa !18
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.rlite, ptr %23, i32 0, i32 11
  store i32 16, ptr %24, align 4, !tbaa !19
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.rlite, ptr %25, i32 0, i32 2
  store i32 16, ptr %26, align 8, !tbaa !20
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.rlite, ptr %27, i32 0, i32 11
  %29 = load i32, ptr %28, align 4, !tbaa !19
  %30 = add nsw i32 %29, 6
  %31 = sext i32 %30 to i64
  %32 = mul i64 8, %31
  %33 = call noalias ptr @malloc(i64 noundef %32) #4
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.rlite, ptr %34, i32 0, i32 12
  store ptr %33, ptr %35, align 8, !tbaa !21
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.rlite, ptr %36, i32 0, i32 12
  %38 = load ptr, ptr %37, align 8, !tbaa !21
  %39 = icmp ne ptr %38, null
  br i1 %39, label %41, label %40

40:                                               ; preds = %10
  store i32 4, ptr %3, align 4, !tbaa !9
  br label %81

41:                                               ; preds = %10
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.rlite, ptr %42, i32 0, i32 11
  %44 = load i32, ptr %43, align 4, !tbaa !19
  %45 = add nsw i32 %44, 6
  %46 = sext i32 %45 to i64
  %47 = mul i64 8, %46
  %48 = call noalias ptr @malloc(i64 noundef %47) #4
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.rlite, ptr %49, i32 0, i32 3
  store ptr %48, ptr %50, align 8, !tbaa !22
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.rlite, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !22
  %54 = icmp ne ptr %53, null
  br i1 %54, label %56, label %55

55:                                               ; preds = %41
  store i32 4, ptr %3, align 4, !tbaa !9
  br label %81

56:                                               ; preds = %41
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %77, %56
  %58 = load i32, ptr %4, align 4, !tbaa !9
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.rlite, ptr %59, i32 0, i32 11
  %61 = load i32, ptr %60, align 4, !tbaa !19
  %62 = add nsw i32 %61, 6
  %63 = icmp slt i32 %58, %62
  br i1 %63, label %64, label %80

64:                                               ; preds = %57
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.rlite, ptr %65, i32 0, i32 12
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  %68 = load i32, ptr %4, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i64, ptr %67, i64 %69
  store i64 0, ptr %70, align 8, !tbaa !23
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.rlite, ptr %71, i32 0, i32 3
  %73 = load ptr, ptr %72, align 8, !tbaa !22
  %74 = load i32, ptr %4, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i64, ptr %73, i64 %75
  store i64 0, ptr %76, align 8, !tbaa !23
  br label %77

77:                                               ; preds = %64
  %78 = load i32, ptr %4, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %4, align 4, !tbaa !9
  br label %57, !llvm.loop !24

80:                                               ; preds = %57
  br label %81

81:                                               ; preds = %80, %55, %40, %9
  %82 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %82
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 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 #3 = { nounwind }
attributes #4 = { nounwind allocsize(0) }

!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, !13, i64 40}
!12 = !{!"rlite", !13, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !6, i64 80, !13, i64 88, !13, i64 96, !6, i64 104, !13, i64 112, !13, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 0}
!15 = !{!12, !13, i64 32}
!16 = !{!12, !13, i64 8}
!17 = !{!12, !10, i64 72}
!18 = !{!12, !10, i64 68}
!19 = !{!12, !10, i64 76}
!20 = !{!12, !10, i64 16}
!21 = !{!12, !6, i64 80}
!22 = !{!12, !6, i64 24}
!23 = !{!13, !13, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; 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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_ensure_pages(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_create_db(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i32 @rl_ensure_pages(ptr noundef %0)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %3, label %.loopexit

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 1, ptr %4, align 8, !tbaa !5
  store i64 1, ptr %0, align 8, !tbaa !12
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 1, ptr %5, align 8, !tbaa !13
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 1, ptr %6, align 8, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %0, i64 72
  store i32 0, ptr %7, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %0, i64 68
  store i32 0, ptr %8, align 4, !tbaa !16
  %9 = getelementptr inbounds i8, ptr %0, i64 76
  store i32 16, ptr %9, align 4, !tbaa !17
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 16, ptr %10, align 8, !tbaa !18
  %11 = tail call noalias dereferenceable_or_null(176) ptr @malloc(i64 noundef 176) #4
  %12 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr %11, ptr %12, align 8, !tbaa !19
  %.not25 = icmp eq ptr %11, null
  br i1 %.not25, label %.loopexit, label %13

13:                                               ; preds = %3
  %calloc = tail call dereferenceable_or_null(176) ptr @calloc(i64 1, i64 176)
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %calloc, ptr %14, align 8, !tbaa !20
  %.not26 = icmp eq ptr %calloc, null
  br i1 %.not26, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %13
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(176) %11, i8 0, i64 176, i1 false), !tbaa !21
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.preheader, %13, %3, %1
  %.023 = phi i32 [ %2, %1 ], [ 4, %3 ], [ 4, %13 ], [ 0, %.preheader.preheader ]
  ret i32 %.023
}

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

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #4 = { nounwind allocsize(0) }

!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 40}
!6 = !{!"rlite", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !11, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !11, i64 80, !7, i64 88, !7, i64 96, !11, i64 104, !7, i64 112, !7, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 32}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !10, i64 72}
!16 = !{!6, !10, i64 68}
!17 = !{!6, !10, i64 76}
!18 = !{!6, !10, i64 16}
!19 = !{!6, !11, i64 80}
!20 = !{!6, !11, i64 24}
!21 = !{!7, !7, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass