; 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_GetHash(ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XMap_Put(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 i32, align 4
  %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 = icmp eq ptr %11, null
  br i1 %12, label %16, label %13

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

16:                                               ; preds = %13, %3
  store i32 -4, ptr %4, align 4
  br label %67

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = call i32 @XMap_GetHash(ptr noundef %18, ptr noundef %19)
  store i32 %20, ptr %8, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %37, %17
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = icmp eq i32 %22, -3
  br i1 %23, label %24, label %38

24:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = call i32 @XMap_Realloc(ptr noundef %25)
  store i32 %26, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %24
  %30 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %30, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %35

31:                                               ; preds = %24
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = call i32 @XMap_GetHash(ptr noundef %32, ptr noundef %33)
  store i32 %34, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %10, align 4
  br label %35

35:                                               ; preds = %31, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %36 = load i32, ptr %10, align 4
  switch i32 %36, label %66 [
    i32 0, label %37
  ]

37:                                               ; preds = %35
  br label %21, !llvm.loop !11

38:                                               ; preds = %21
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.XMap, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.XMapPair, ptr %42, i64 %44
  %46 = getelementptr inbounds %struct.XMapPair, ptr %45, i32 0, i32 1
  store ptr %39, ptr %46, align 8, !tbaa !16
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.XMap, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct.XMapPair, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct.XMapPair, ptr %53, i32 0, i32 0
  store ptr %47, ptr %54, align 8, !tbaa !18
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.XMap, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !13
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds %struct.XMapPair, ptr %57, i64 %59
  %61 = getelementptr inbounds %struct.XMapPair, ptr %60, i32 0, i32 2
  store i32 1, ptr %61, align 8, !tbaa !19
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.XMap, ptr %62, i32 0, i32 4
  %64 = load i64, ptr %63, align 8, !tbaa !20
  %65 = add i64 %64, 1
  store i64 %65, ptr %63, align 8, !tbaa !20
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %66

66:                                               ; preds = %38, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %67

67:                                               ; preds = %66, %16
  %68 = load i32, ptr %4, align 4
  ret i32 %68
}

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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 8}
!14 = !{!"XMap", !6, i64 0, !6, i64 8, !6, i64 16, !15, i64 24, !15, i64 32, !10, i64 40}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !6, i64 8}
!17 = !{!"XMapPair", !6, i64 0, !6, i64 8, !10, i64 16}
!18 = !{!17, !6, i64 0}
!19 = !{!17, !10, i64 16}
!20 = !{!14, !15, i64 32}


; 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_GetHash(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

6:                                                ; preds = %3
  %7 = tail call i32 @XMap_GetHash(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %8 = icmp eq i32 %7, -3
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6, %11
  %9 = tail call i32 @XMap_Realloc(ptr noundef %0)
  %10 = icmp sgt i32 %9, -1
  br i1 %10, label %11, label %.thread

11:                                               ; preds = %.lr.ph
  %12 = tail call i32 @XMap_GetHash(ptr noundef %0, ptr noundef %1)
  %13 = icmp eq i32 %12, -3
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %11, %6
  %.022.lcssa = phi i32 [ %7, %6 ], [ %12, %11 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !7
  %16 = sext i32 %.022.lcssa to i64
  %17 = getelementptr inbounds %struct.XMapPair, ptr %15, i64 %16, i32 1
  store ptr %2, ptr %17, align 8, !tbaa !14
  %18 = getelementptr inbounds %struct.XMapPair, ptr %15, i64 %16
  store ptr %1, ptr %18, align 8, !tbaa !16
  %19 = getelementptr inbounds %struct.XMapPair, ptr %15, i64 %16, i32 2
  store i32 1, ptr %19, align 8, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  %21 = load i64, ptr %20, align 8, !tbaa !18
  %22 = add i64 %21, 1
  store i64 %22, ptr %20, align 8, !tbaa !18
  br label %.thread

.thread:                                          ; preds = %.lr.ph, %._crit_edge, %3
  %.3 = phi i32 [ -4, %3 ], [ 1, %._crit_edge ], [ %9, %.lr.ph ]
  ret i32 %.3
}

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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 8}
!8 = !{!"XMap", !9, i64 0, !9, i64 8, !9, i64 16, !12, i64 24, !12, i64 32, !13, i64 40}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!"int", !10, i64 0}
!14 = !{!15, !9, i64 8}
!15 = !{!"XMapPair", !9, i64 0, !9, i64 8, !13, i64 16}
!16 = !{!15, !9, i64 0}
!17 = !{!15, !13, i64 16}
!18 = !{!8, !12, i64 32}


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