; LLVM IR from MRPT/mrpt :: 3rdparty/xspublic/xstypes (xsarray)

; 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.XsArray = type { ptr, i64, i64, i64, ptr }
%struct.XsArrayDescriptor = type { i64, ptr, ptr, ptr, 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 uwtable
define dso_local i32 @XsArray_comparePredicate(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %13, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %14, ptr %10, align 8, !tbaa !5
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = icmp eq ptr %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %81

19:                                               ; preds = %3
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.XsArray, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.XsArray, ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !9
  %26 = icmp ne i64 %22, %25
  br i1 %26, label %27, label %37

27:                                               ; preds = %19
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.XsArray, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.XsArray, ptr %31, i32 0, i32 1
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = icmp ult i64 %30, %33
  %35 = zext i1 %34 to i64
  %36 = select i1 %34, i32 -1, i32 1
  store i32 %36, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %81

37:                                               ; preds = %19
  store i64 0, ptr %8, align 8, !tbaa !12
  br label %38

38:                                               ; preds = %77, %37
  %39 = load i64, ptr %8, align 8, !tbaa !12
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.XsArray, ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = icmp ult i64 %39, %42
  br i1 %43, label %44, label %80

44:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.XsArray, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load i64, ptr %8, align 8, !tbaa !12
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.XsArray, ptr %50, i32 0, i32 4
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = getelementptr inbounds %struct.XsArrayDescriptor, ptr %52, i32 0, i32 0
  %54 = load i64, ptr %53, align 8, !tbaa !15
  %55 = mul i64 %49, %54
  %56 = getelementptr inbounds i8, ptr %48, i64 %55
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.XsArray, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = load i64, ptr %8, align 8, !tbaa !12
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.XsArray, ptr %61, i32 0, i32 4
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = getelementptr inbounds %struct.XsArrayDescriptor, ptr %63, i32 0, i32 0
  %65 = load i64, ptr %64, align 8, !tbaa !15
  %66 = mul i64 %60, %65
  %67 = getelementptr inbounds i8, ptr %59, i64 %66
  %68 = call i32 %45(ptr noundef %56, ptr noundef %67)
  store i32 %68, ptr %12, align 4, !tbaa !17
  %69 = load i32, ptr %12, align 4, !tbaa !17
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %73

71:                                               ; preds = %44
  %72 = load i32, ptr %12, align 4, !tbaa !17
  store i32 %72, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %74

73:                                               ; preds = %44
  store i32 0, ptr %11, align 4
  br label %74

74:                                               ; preds = %73, %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %75 = load i32, ptr %11, align 4
  switch i32 %75, label %81 [
    i32 0, label %76
  ]

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76
  %78 = load i64, ptr %8, align 8, !tbaa !12
  %79 = add i64 %78, 1
  store i64 %79, ptr %8, align 8, !tbaa !12
  br label %38, !llvm.loop !19

80:                                               ; preds = %38
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %81

81:                                               ; preds = %80, %74, %27, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %82 = load i32, ptr %4, align 4
  ret i32 %82
}

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, !11, i64 8}
!10 = !{!"XsArray", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!10, !6, i64 32}
!15 = !{!16, !11, i64 0}
!16 = !{!"XsArrayDescriptor", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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: nounwind uwtable
define dso_local i32 @XsArray_comparePredicate(ptr noundef readonly %0, ptr noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, %1
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %.not = icmp eq i64 %7, %9
  br i1 %.not, label %.preheader, label %12

.preheader:                                       ; preds = %5
  %.not32 = icmp eq i64 %7, 0
  br i1 %.not32, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = getelementptr inbounds i8, ptr %1, i64 32
  br label %19

12:                                               ; preds = %5
  %13 = icmp ult i64 %7, %9
  %14 = select i1 %13, i32 -1, i32 1
  br label %.loopexit

15:                                               ; preds = %19
  %16 = add nuw i64 %.02229, 1
  %17 = load i64, ptr %6, align 8, !tbaa !5
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %19, label %.loopexit, !llvm.loop !11

19:                                               ; preds = %.lr.ph, %15
  %.02229 = phi i64 [ 0, %.lr.ph ], [ %16, %15 ]
  %20 = load ptr, ptr %0, align 8, !tbaa !13
  %21 = load ptr, ptr %10, align 8, !tbaa !14
  %22 = load i64, ptr %21, align 8, !tbaa !15
  %23 = mul i64 %22, %.02229
  %24 = getelementptr inbounds i8, ptr %20, i64 %23
  %25 = load ptr, ptr %1, align 8, !tbaa !13
  %26 = load ptr, ptr %11, align 8, !tbaa !14
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = mul i64 %27, %.02229
  %29 = getelementptr inbounds i8, ptr %25, i64 %28
  %30 = tail call i32 %2(ptr noundef %24, ptr noundef %29) #1
  %.not28 = icmp eq i32 %30, 0
  br i1 %.not28, label %15, label %.loopexit

.loopexit:                                        ; preds = %19, %15, %.preheader, %3, %12
  %.2 = phi i32 [ %14, %12 ], [ 0, %3 ], [ 0, %.preheader ], [ %30, %19 ], [ 0, %15 ]
  ret 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 = { 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, !10, i64 8}
!6 = !{!"XsArray", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 32}
!15 = !{!16, !10, i64 0}
!16 = !{!"XsArrayDescriptor", !10, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}


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