; LLVM IR from kala13x/libxutils :: src/data (map)

; 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.XMap = type { ptr, ptr, ptr, i64, i64, i32 }
%struct.XMapPair = type { ptr, ptr, i32 }

; 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 @XMap_Iterate(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 i32, align 4
  %10 = 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
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call i32 @XMap_UsedSize(ptr noundef %11)
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  br label %54

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %49, %15
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.XMap, ptr %18, i32 0, i32 3
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = icmp ult i64 %17, %20
  br i1 %21, label %22, label %52

22:                                               ; preds = %16
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.XMap, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.XMapPair, ptr %25, i64 %26
  %28 = getelementptr inbounds %struct.XMapPair, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !15
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %48

31:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.XMap, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.XMapPair, ptr %35, i64 %36
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = call i32 %32(ptr noundef %37, ptr noundef %38)
  store i32 %39, ptr %9, align 4, !tbaa !17
  %40 = load i32, ptr %9, align 4, !tbaa !17
  %41 = icmp ne i32 %40, 1
  br i1 %41, label %42, label %44

42:                                               ; preds = %31
  %43 = load i32, ptr %9, align 4, !tbaa !17
  store i32 %43, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %45

44:                                               ; preds = %31
  store i32 0, ptr %10, align 4
  br label %45

45:                                               ; preds = %44, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %46 = load i32, ptr %10, align 4
  switch i32 %46, label %53 [
    i32 0, label %47
  ]

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47, %22
  br label %49

49:                                               ; preds = %48
  %50 = load i64, ptr %8, align 8, !tbaa !9
  %51 = add i64 %50, 1
  store i64 %51, ptr %8, align 8, !tbaa !9
  br label %16, !llvm.loop !18

52:                                               ; preds = %16
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %53

53:                                               ; preds = %52, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %54

54:                                               ; preds = %53, %14
  %55 = load i32, ptr %4, align 4
  ret i32 %55
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @XMap_UsedSize(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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"XMap", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 32, !13, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !13, i64 16}
!16 = !{!"XMapPair", !6, i64 0, !6, i64 8, !13, i64 16}
!17 = !{!13, !13, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.XMapPair = type { ptr, ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @XMap_Iterate(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @XMap_UsedSize(ptr noundef %0)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not21 = icmp eq i64 %6, 0
  br i1 %.not21, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  br label %8

8:                                                ; preds = %.lr.ph, %16
  %9 = phi i64 [ %6, %.lr.ph ], [ %17, %16 ]
  %.01418 = phi i64 [ 0, %.lr.ph ], [ %18, %16 ]
  %10 = load ptr, ptr %7, align 8, !tbaa !12
  %11 = getelementptr inbounds %struct.XMapPair, ptr %10, i64 %.01418
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %.not16 = icmp eq i32 %13, 0
  br i1 %.not16, label %16, label %14

14:                                               ; preds = %8
  %15 = tail call i32 %1(ptr noundef nonnull %11, ptr noundef %2) #1
  %.not17 = icmp eq i32 %15, 1
  br i1 %.not17, label %._crit_edge, label %.loopexit

._crit_edge:                                      ; preds = %14
  %.pre = load i64, ptr %5, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %._crit_edge, %8
  %17 = phi i64 [ %.pre, %._crit_edge ], [ %9, %8 ]
  %18 = add nuw i64 %.01418, 1
  %19 = icmp ult i64 %18, %17
  br i1 %19, label %8, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %16, %14, %.preheader, %3
  %.4 = phi i32 [ 0, %3 ], [ 1, %.preheader ], [ 1, %16 ], [ %15, %14 ]
  ret i32 %.4
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @XMap_UsedSize(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" }
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 24}
!6 = !{!"XMap", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !11, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !11, i64 16}
!14 = !{!"XMapPair", !7, i64 0, !7, i64 8, !11, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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