; LLVM IR from sameerkavthekar/garbage-collector :: src (gc)

; 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.gc = type { ptr, i32, %struct.set_t, ptr, ptr, i8 }
%struct.set_t = type { %struct.hash_map }
%struct.hash_map = type { ptr, i32 }
%struct.hash_node = type { ptr, ptr, ptr }
%struct.collectorBlock = type { ptr, ptr, i32, i8 }

@GC = external hidden global %struct.gc, align 8

; 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

declare i32 @search(ptr, i32, ptr noundef) #1

declare ptr @get_map_iter(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @updateReferences(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call ptr @get_map_iter(ptr noundef %12)
  store ptr %13, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %14 = load ptr, ptr getelementptr inbounds (%struct.gc, ptr @GC, i32 0, i32 3), align 8, !tbaa !9
  store ptr %14, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %15

15:                                               ; preds = %58, %1
  %16 = load i32, ptr %5, align 4, !tbaa !14
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.hash_map, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !15
  %20 = icmp slt i32 %16, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %61

22:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !14
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds ptr, ptr %23, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  store ptr %27, ptr %6, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %53, %22
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %57

31:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.hash_node, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = getelementptr inbounds i8, ptr %34, i64 -24
  store ptr %35, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.hash_node, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !18
  store ptr %38, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %53

41:                                               ; preds = %31
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.collectorBlock, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !19
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.hash_node, ptr %45, i32 0, i32 1
  store ptr %44, ptr %46, align 8, !tbaa !16
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.collectorBlock, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !19
  %50 = getelementptr inbounds i8, ptr %49, i64 24
  %51 = ptrtoint ptr %50 to i64
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %51, ptr %52, align 8, !tbaa !21
  br label %53

53:                                               ; preds = %41, %31
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.hash_node, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !23
  store ptr %56, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %28, !llvm.loop !24

57:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %5, align 4, !tbaa !14
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %5, align 4, !tbaa !14
  br label %15, !llvm.loop !26

61:                                               ; preds = %21
  %62 = load ptr, ptr getelementptr inbounds (%struct.gc, ptr @GC, i32 0, i32 3), align 8, !tbaa !9
  store ptr %62, ptr %4, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %115, %61
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %119

66:                                               ; preds = %63
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.collectorBlock, ptr %67, i32 0, i32 3
  %69 = load i8, ptr %68, align 4, !tbaa !27
  %70 = sext i8 %69 to i32
  %71 = icmp eq i32 %70, 1
  br i1 %71, label %72, label %115

72:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i64 24
  store ptr %74, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds i8, ptr %75, i64 24
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.collectorBlock, ptr %77, i32 0, i32 2
  %79 = load i32, ptr %78, align 8, !tbaa !28
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i8, ptr %76, i64 %80
  store ptr %81, ptr %10, align 8, !tbaa !5
  br label %82

82:                                               ; preds = %111, %72
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = icmp ult ptr %83, %84
  br i1 %85, label %86, label %114

86:                                               ; preds = %82
  %87 = load ptr, ptr %9, align 8, !tbaa !5
  %88 = load i64, ptr %87, align 8, !tbaa !21
  %89 = inttoptr i64 %88 to ptr
  %90 = load ptr, ptr getelementptr inbounds (%struct.gc, ptr @GC, i32 0, i32 2), align 8
  %91 = load i32, ptr getelementptr inbounds ({ ptr, i32 }, ptr getelementptr inbounds (%struct.gc, ptr @GC, i32 0, i32 2), i32 0, i32 1), align 8
  %92 = call i32 @search(ptr %90, i32 %91, ptr noundef %89)
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %94, label %111

94:                                               ; preds = %86
  %95 = load ptr, ptr %9, align 8, !tbaa !5
  %96 = load i64, ptr %95, align 8, !tbaa !21
  %97 = inttoptr i64 %96 to ptr
  %98 = icmp ne ptr %97, null
  br i1 %98, label %99, label %110

99:                                               ; preds = %94
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %100 = load ptr, ptr %9, align 8, !tbaa !5
  %101 = load i64, ptr %100, align 8, !tbaa !21
  %102 = inttoptr i64 %101 to ptr
  store ptr %102, ptr %11, align 8, !tbaa !5
  %103 = load ptr, ptr %11, align 8, !tbaa !5
  %104 = getelementptr inbounds i8, ptr %103, i64 -24
  %105 = getelementptr inbounds %struct.collectorBlock, ptr %104, i32 0, i32 1
  %106 = load ptr, ptr %105, align 8, !tbaa !19
  %107 = getelementptr inbounds i8, ptr %106, i64 24
  %108 = ptrtoint ptr %107 to i64
  %109 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %108, ptr %109, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %110

110:                                              ; preds = %99, %94
  br label %111

111:                                              ; preds = %110, %86
  %112 = load ptr, ptr %9, align 8, !tbaa !5
  %113 = getelementptr inbounds i8, ptr %112, i64 1
  store ptr %113, ptr %9, align 8, !tbaa !5
  br label %82, !llvm.loop !29

114:                                              ; preds = %82
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %115

115:                                              ; preds = %114, %66
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.collectorBlock, ptr %116, i32 0, i32 0
  %118 = load ptr, ptr %117, align 8, !tbaa !30
  store ptr %118, ptr %4, align 8, !tbaa !5
  br label %63, !llvm.loop !31

119:                                              ; preds = %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { 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, !6, i64 32}
!10 = !{!"gc", !6, i64 0, !11, i64 8, !12, i64 16, !6, i64 32, !6, i64 40, !7, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !13, i64 0}
!13 = !{!"hash_map", !6, i64 0, !11, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!13, !11, i64 8}
!16 = !{!17, !6, i64 8}
!17 = !{!"hash_node", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!17, !6, i64 0}
!19 = !{!20, !6, i64 8}
!20 = !{!"collectorBlock", !6, i64 0, !6, i64 8, !11, i64 16, !7, i64 20}
!21 = !{!22, !22, i64 0}
!22 = !{!"long", !7, i64 0}
!23 = !{!17, !6, i64 16}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}
!27 = !{!20, !7, i64 20}
!28 = !{!20, !11, i64 16}
!29 = distinct !{!29, !25}
!30 = !{!20, !6, i64 0}
!31 = distinct !{!31, !25}


; 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.gc = type { ptr, i32, %struct.set_t, ptr, ptr, i8 }
%struct.set_t = type { %struct.hash_map }
%struct.hash_map = type { ptr, i32 }

@GC = external hidden local_unnamed_addr global %struct.gc, align 8

declare i32 @search(ptr, i32, ptr noundef) local_unnamed_addr #0

declare ptr @get_map_iter(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @updateReferences(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call ptr @get_map_iter(ptr noundef %0) #2
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph40.preheader, label %.preheader

.lr.ph40.preheader:                               ; preds = %1
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %.lr.ph40

.preheader:                                       ; preds = %._crit_edge, %1
  %.044 = load ptr, ptr getelementptr inbounds (i8, ptr @GC, i64 32), align 8, !tbaa !11
  %.not45 = icmp eq ptr %.044, null
  br i1 %.not45, label %._crit_edge48, label %.lr.ph47

.lr.ph40:                                         ; preds = %.lr.ph40.preheader, %._crit_edge
  %indvars.iv = phi i64 [ 0, %.lr.ph40.preheader ], [ %indvars.iv.next, %._crit_edge ]
  %6 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv
  %.03035 = load ptr, ptr %6, align 8, !tbaa !11
  %.not3436 = icmp eq ptr %.03035, null
  br i1 %.not3436, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph40, %.lr.ph
  %.03037 = phi ptr [ %.030, %.lr.ph ], [ %.03035, %.lr.ph40 ]
  %7 = load ptr, ptr %.03037, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %.03037, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %9, i64 -16
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  store ptr %11, ptr %8, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %11, i64 24
  %13 = ptrtoint ptr %12 to i64
  store i64 %13, ptr %7, align 8, !tbaa !17
  %14 = getelementptr inbounds i8, ptr %.03037, i64 16
  %.030 = load ptr, ptr %14, align 8, !tbaa !11
  %.not34 = icmp eq ptr %.030, null
  br i1 %.not34, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph40
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.lr.ph40, !llvm.loop !21

.lr.ph47:                                         ; preds = %.preheader, %.loopexit
  %.046 = phi ptr [ %.0, %.loopexit ], [ %.044, %.preheader ]
  %15 = getelementptr inbounds i8, ptr %.046, i64 20
  %16 = load i8, ptr %15, align 4, !tbaa !22
  %17 = icmp eq i8 %16, 1
  br i1 %17, label %18, label %.loopexit

18:                                               ; preds = %.lr.ph47
  %19 = getelementptr inbounds i8, ptr %.046, i64 16
  %20 = load i32, ptr %19, align 8, !tbaa !23
  %21 = sext i32 %20 to i64
  %.add = add nsw i64 %21, 24
  %.ptr49 = getelementptr inbounds i8, ptr %.046, i64 %.add
  %22 = icmp sgt i32 %20, 0
  br i1 %22, label %.lr.ph43.preheader, label %.loopexit

.lr.ph43.preheader:                               ; preds = %18
  %.ptr = getelementptr inbounds i8, ptr %.046, i64 24
  br label %.lr.ph43

.lr.ph43:                                         ; preds = %.lr.ph43.preheader, %36
  %.02941 = phi ptr [ %37, %36 ], [ %.ptr, %.lr.ph43.preheader ]
  %23 = load i64, ptr %.02941, align 8, !tbaa !17
  %24 = inttoptr i64 %23 to ptr
  %25 = load ptr, ptr getelementptr inbounds (i8, ptr @GC, i64 16), align 8
  %26 = load i32, ptr getelementptr inbounds (i8, ptr @GC, i64 24), align 8
  %27 = tail call i32 @search(ptr %25, i32 %26, ptr noundef %24) #2
  %.not32 = icmp eq i32 %27, 0
  br i1 %.not32, label %36, label %28

28:                                               ; preds = %.lr.ph43
  %29 = load i64, ptr %.02941, align 8, !tbaa !17
  %.not33 = icmp eq i64 %29, 0
  br i1 %.not33, label %36, label %30

30:                                               ; preds = %28
  %31 = inttoptr i64 %29 to ptr
  %32 = getelementptr inbounds i8, ptr %31, i64 -16
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = getelementptr inbounds i8, ptr %33, i64 24
  %35 = ptrtoint ptr %34 to i64
  store i64 %35, ptr %.02941, align 8, !tbaa !17
  br label %36

36:                                               ; preds = %28, %30, %.lr.ph43
  %37 = getelementptr inbounds i8, ptr %.02941, i64 1
  %38 = icmp ult ptr %37, %.ptr49
  br i1 %38, label %.lr.ph43, label %.loopexit, !llvm.loop !24

.loopexit:                                        ; preds = %36, %18, %.lr.ph47
  %.0 = load ptr, ptr %.046, align 8, !tbaa !11
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge48, label %.lr.ph47, !llvm.loop !25

._crit_edge48:                                    ; preds = %.loopexit, %.preheader
  ret void
}

attributes #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 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, !10, i64 8}
!6 = !{!"hash_map", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"hash_node", !7, i64 0, !7, i64 8, !7, i64 16}
!14 = !{!13, !7, i64 8}
!15 = !{!16, !7, i64 8}
!16 = !{!"collectorBlock", !7, i64 0, !7, i64 8, !10, i64 16, !8, i64 20}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !8, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}
!22 = !{!16, !8, i64 20}
!23 = !{!16, !10, i64 16}
!24 = distinct !{!24, !20}
!25 = distinct !{!25, !20}


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