; 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
declare dso_local i32 @XMap_Hash(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @XMap_Remove(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %15, label %12

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %12, %2
  store i32 -4, ptr %3, align 4
  br label %97

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call i32 @XMap_Hash(ptr noundef %17, ptr noundef %18)
  store i32 %19, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp eq i32 %20, -6
  br i1 %21, label %22, label %24

22:                                               ; preds = %16
  %23 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %23, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %96

24:                                               ; preds = %16
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %92, %24
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 32
  br i1 %27, label %28, label %95

28:                                               ; preds = %25
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.XMap, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.XMapPair, ptr %31, i64 %33
  %35 = getelementptr inbounds %struct.XMapPair, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !14
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %84

38:                                               ; preds = %28
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.XMap, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %struct.XMapPair, ptr %41, i64 %43
  %45 = getelementptr inbounds %struct.XMapPair, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = call i32 @strcmp(ptr noundef %46, ptr noundef %47) #4
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %83, label %50

50:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.XMap, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds %struct.XMapPair, ptr %53, i64 %55
  store ptr %56, ptr %9, align 8, !tbaa !5
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.XMap, ptr %57, i32 0, i32 4
  %59 = load i64, ptr %58, align 8, !tbaa !17
  %60 = icmp ne i64 %59, 0
  br i1 %60, label %61, label %66

61:                                               ; preds = %50
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.XMap, ptr %62, i32 0, i32 4
  %64 = load i64, ptr %63, align 8, !tbaa !17
  %65 = add i64 %64, -1
  store i64 %65, ptr %63, align 8, !tbaa !17
  br label %66

66:                                               ; preds = %61, %50
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.XMap, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !18
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %76

71:                                               ; preds = %66
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.XMap, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !18
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  call void %74(ptr noundef %75)
  br label %76

76:                                               ; preds = %71, %66
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.XMapPair, ptr %77, i32 0, i32 2
  store i32 0, ptr %78, align 8, !tbaa !14
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.XMapPair, ptr %79, i32 0, i32 1
  store ptr null, ptr %80, align 8, !tbaa !19
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.XMapPair, ptr %81, i32 0, i32 0
  store ptr null, ptr %82, align 8, !tbaa !16
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %96

83:                                               ; preds = %38
  br label %84

84:                                               ; preds = %83, %28
  %85 = load i32, ptr %7, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.XMap, ptr %87, i32 0, i32 3
  %89 = load i64, ptr %88, align 8, !tbaa !20
  %90 = trunc i64 %89 to i32
  %91 = srem i32 %86, %90
  store i32 %91, ptr %7, align 4, !tbaa !9
  br label %92

92:                                               ; preds = %84
  %93 = load i32, ptr %6, align 4, !tbaa !9
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %6, align 4, !tbaa !9
  br label %25, !llvm.loop !21

95:                                               ; preds = %25
  store i32 -5, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %96

96:                                               ; preds = %95, %76, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %97

97:                                               ; preds = %96, %15
  %98 = load i32, ptr %3, align 4
  ret i32 %98
}

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 = { nounwind }
attributes #4 = { 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, !6, i64 8}
!12 = !{!"XMap", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 32, !10, i64 40}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !10, i64 16}
!15 = !{!"XMapPair", !6, i64 0, !6, i64 8, !10, i64 16}
!16 = !{!15, !6, i64 0}
!17 = !{!12, !13, i64 32}
!18 = !{!12, !6, i64 0}
!19 = !{!15, !6, i64 8}
!20 = !{!12, !13, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"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
declare dso_local i32 @XMap_Hash(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -6, 2) i32 @XMap_Remove(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %.loopexit, label %5

5:                                                ; preds = %2
  %6 = tail call i32 @XMap_Hash(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %7 = icmp eq i32 %6, -6
  br i1 %7, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  br label %11

11:                                               ; preds = %.preheader, %28
  %.02640 = phi i32 [ %6, %.preheader ], [ %32, %28 ]
  %.02739 = phi i32 [ 0, %.preheader ], [ %33, %28 ]
  %12 = sext i32 %.02640 to i64
  %13 = getelementptr inbounds %struct.XMapPair, ptr %9, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %15 = load i32, ptr %14, align 8, !tbaa !12
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %28, label %16

16:                                               ; preds = %11
  %17 = load ptr, ptr %13, align 8, !tbaa !14
  %18 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %17, ptr noundef nonnull dereferenceable(1) %1) #3
  %.not34 = icmp eq i32 %18, 0
  br i1 %.not34, label %19, label %28

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %.not35 = icmp eq i64 %21, 0
  br i1 %.not35, label %24, label %22

22:                                               ; preds = %19
  %23 = add i64 %21, -1
  store i64 %23, ptr %20, align 8, !tbaa !15
  br label %24

24:                                               ; preds = %22, %19
  %25 = load ptr, ptr %0, align 8, !tbaa !16
  %.not36 = icmp eq ptr %25, null
  br i1 %.not36, label %27, label %26

26:                                               ; preds = %24
  tail call void %25(ptr noundef nonnull %13) #4
  br label %27

27:                                               ; preds = %26, %24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %13, i8 0, i64 20, i1 false)
  br label %.loopexit

28:                                               ; preds = %16, %11
  %29 = add nsw i32 %.02640, 1
  %30 = load i64, ptr %10, align 8, !tbaa !17
  %31 = trunc i64 %30 to i32
  %32 = srem i32 %29, %31
  %33 = add nuw nsw i32 %.02739, 1
  %exitcond.not = icmp eq i32 %33, 32
  br i1 %exitcond.not, label %.loopexit, label %11, !llvm.loop !18

.loopexit:                                        ; preds = %28, %27, %5, %2
  %.1 = phi i32 [ -4, %2 ], [ 1, %27 ], [ -6, %5 ], [ -5, %28 ]
  ret i32 %.1
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind willreturn memory(read) }
attributes #4 = { 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, !7, i64 8}
!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 = !{!13, !11, i64 16}
!13 = !{!"XMapPair", !7, i64 0, !7, i64 8, !11, i64 16}
!14 = !{!13, !7, i64 0}
!15 = !{!6, !10, i64 32}
!16 = !{!6, !7, i64 0}
!17 = !{!6, !10, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass