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

16:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %83

17:                                               ; preds = %2
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.XsArray, ptr %18, i32 0, i32 1
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.XsArray, ptr %21, i32 0, i32 1
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = icmp ne i64 %20, %23
  br i1 %24, label %25, label %35

25:                                               ; preds = %17
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.XsArray, ptr %26, i32 0, i32 1
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.XsArray, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = icmp ult i64 %28, %31
  %33 = zext i1 %32 to i64
  %34 = select i1 %32, i32 -1, i32 1
  store i32 %34, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %83

35:                                               ; preds = %17
  store i64 0, ptr %6, align 8, !tbaa !12
  br label %36

36:                                               ; preds = %79, %35
  %37 = load i64, ptr %6, align 8, !tbaa !12
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.XsArray, ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = icmp ult i64 %37, %40
  br i1 %41, label %42, label %82

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

73:                                               ; preds = %42
  %74 = load i32, ptr %10, align 4, !tbaa !18
  store i32 %74, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %76

75:                                               ; preds = %42
  store i32 0, ptr %9, align 4
  br label %76

76:                                               ; preds = %75, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %77 = load i32, ptr %9, align 4
  switch i32 %77, label %83 [
    i32 0, label %78
  ]

78:                                               ; preds = %76
  br label %79

79:                                               ; preds = %78
  %80 = load i64, ptr %6, align 8, !tbaa !12
  %81 = add i64 %80, 1
  store i64 %81, ptr %6, align 8, !tbaa !12
  br label %36, !llvm.loop !20

82:                                               ; preds = %36
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %83

83:                                               ; preds = %82, %76, %25, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %84 = load i32, ptr %3, align 4
  ret i32 %84
}

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 32}
!14 = !{!15, !6, i64 48}
!15 = !{!"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}
!16 = !{!10, !6, i64 0}
!17 = !{!15, !11, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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_compare(ptr noundef readonly %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, %1
  br i1 %3, label %.loopexit, label %4

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

.preheader:                                       ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %.not32 = icmp eq i64 %6, 0
  br i1 %.not32, label %.loopexit, label %.lr.ph

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

11:                                               ; preds = %4
  %12 = icmp ult i64 %6, %8
  %13 = select i1 %12, i32 -1, i32 1
  br label %.loopexit

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

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

.loopexit:                                        ; preds = %18, %14, %.preheader, %2, %11
  %.2 = phi i32 [ %13, %11 ], [ 0, %2 ], [ 0, %.preheader ], [ %31, %18 ], [ 0, %14 ]
  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 32}
!14 = !{!15, !7, i64 48}
!15 = !{!"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}
!16 = !{!6, !7, i64 0}
!17 = !{!15, !10, i64 0}


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