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

@GC = external hidden global %struct.gc, align 8
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [59 x i8], align 1

; 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 ptr @get_set_iter(ptr noundef) #1

declare i32 @get_set_size(ptr, i32) #1

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @gc_dump() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %8 = load i8, ptr getelementptr inbounds (%struct.gc, ptr @GC, i32 0, i32 5), align 8, !tbaa !5
  %9 = icmp ne i8 %8, 0
  br i1 %9, label %10, label %31

10:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  %11 = load ptr, ptr getelementptr inbounds (%struct.gc, ptr @GC, i32 0, i32 3), align 8, !tbaa !13
  store ptr %11, ptr %1, align 8, !tbaa !14
  br label %12

12:                                               ; preds = %15, %10
  %13 = load ptr, ptr %1, align 8, !tbaa !14
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %30

15:                                               ; preds = %12
  %16 = load ptr, ptr %1, align 8, !tbaa !14
  %17 = load ptr, ptr %1, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %17, i64 24
  %19 = load ptr, ptr %1, align 8, !tbaa !14
  %20 = getelementptr inbounds %struct.collectorBlock, ptr %19, i32 0, i32 3
  %21 = load i8, ptr %20, align 4, !tbaa !15
  %22 = sext i8 %21 to i32
  %23 = load ptr, ptr %1, align 8, !tbaa !14
  %24 = getelementptr inbounds %struct.collectorBlock, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 8, !tbaa !17
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %16, ptr noundef %18, i32 noundef %22, i32 noundef %25)
  %27 = load ptr, ptr %1, align 8, !tbaa !14
  %28 = getelementptr inbounds %struct.collectorBlock, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  store ptr %29, ptr %1, align 8, !tbaa !14
  br label %12, !llvm.loop !19

30:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  br label %89

31:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %32 = call ptr @get_set_iter(ptr noundef getelementptr inbounds (%struct.gc, ptr @GC, i32 0, i32 2))
  store ptr %32, ptr %2, align 8, !tbaa !14
  %33 = load ptr, ptr %2, align 8, !tbaa !14
  %34 = icmp ne ptr %33, null
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 1, ptr %3, align 4
  br label %86

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !21
  br label %37

37:                                               ; preds = %82, %36
  %38 = load i32, ptr %4, align 4, !tbaa !21
  %39 = load ptr, ptr getelementptr inbounds (%struct.gc, ptr @GC, i32 0, i32 2), align 8
  %40 = load i32, ptr getelementptr inbounds ({ ptr, i32 }, ptr getelementptr inbounds (%struct.gc, ptr @GC, i32 0, i32 2), i32 0, i32 1), align 8
  %41 = call i32 @get_set_size(ptr %39, i32 %40)
  %42 = icmp slt i32 %38, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %37
  store i32 4, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %85

44:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %45 = load ptr, ptr %2, align 8, !tbaa !14
  %46 = load i32, ptr %4, align 4, !tbaa !21
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds ptr, ptr %45, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  store ptr %49, ptr %5, align 8, !tbaa !14
  br label %50

50:                                               ; preds = %53, %44
  %51 = load ptr, ptr %5, align 8, !tbaa !14
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %81

53:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %54 = load ptr, ptr %5, align 8, !tbaa !14
  %55 = getelementptr inbounds %struct.hash_node, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !22
  %57 = getelementptr inbounds i8, ptr %56, i64 -24
  store ptr %57, ptr %6, align 8, !tbaa !14
  %58 = load ptr, ptr %6, align 8, !tbaa !14
  %59 = load ptr, ptr %5, align 8, !tbaa !14
  %60 = getelementptr inbounds %struct.hash_node, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !22
  %62 = load ptr, ptr %5, align 8, !tbaa !14
  %63 = getelementptr inbounds %struct.hash_node, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !22
  %65 = getelementptr inbounds i8, ptr %64, i64 -24
  %66 = getelementptr inbounds %struct.collectorBlock, ptr %65, i32 0, i32 3
  %67 = load i8, ptr %66, align 4, !tbaa !15
  %68 = sext i8 %67 to i32
  %69 = icmp eq i32 %68, 1
  %70 = zext i1 %69 to i32
  %71 = load ptr, ptr %5, align 8, !tbaa !14
  %72 = getelementptr inbounds %struct.hash_node, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !22
  %74 = getelementptr inbounds i8, ptr %73, i64 -24
  %75 = getelementptr inbounds %struct.collectorBlock, ptr %74, i32 0, i32 2
  %76 = load i32, ptr %75, align 8, !tbaa !17
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %58, ptr noundef %61, i32 noundef %70, i32 noundef %76)
  %78 = load ptr, ptr %5, align 8, !tbaa !14
  %79 = getelementptr inbounds %struct.hash_node, ptr %78, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !24
  store ptr %80, ptr %5, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %50, !llvm.loop !25

81:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %4, align 4, !tbaa !21
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %4, align 4, !tbaa !21
  br label %37, !llvm.loop !26

85:                                               ; preds = %43
  store i32 0, ptr %3, align 4
  br label %86

86:                                               ; preds = %85, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %87 = load i32, ptr %3, align 4
  switch i32 %87, label %91 [
    i32 0, label %88
    i32 1, label %90
  ]

88:                                               ; preds = %86
  br label %89

89:                                               ; preds = %88, %30
  br label %90

90:                                               ; preds = %89, %86
  ret void

91:                                               ; preds = %86
  unreachable
}

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


; 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 global %struct.gc, align 8
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [59 x i8], align 1

declare ptr @get_set_iter(ptr noundef) local_unnamed_addr #0

declare i32 @get_set_size(ptr, i32) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @gc_dump() local_unnamed_addr #2 {
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %2 = load i8, ptr getelementptr inbounds (i8, ptr @GC, i64 48), align 8, !tbaa !5
  %.not = icmp eq i8 %2, 0
  br i1 %.not, label %10, label %.preheader23

.preheader23:                                     ; preds = %0
  %.025 = load ptr, ptr getelementptr inbounds (i8, ptr @GC, i64 32), align 8, !tbaa !13
  %.not2226 = icmp eq ptr %.025, null
  br i1 %.not2226, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader23, %.lr.ph
  %.027 = phi ptr [ %.0, %.lr.ph ], [ %.025, %.preheader23 ]
  %3 = getelementptr inbounds i8, ptr %.027, i64 24
  %4 = getelementptr inbounds i8, ptr %.027, i64 20
  %5 = load i8, ptr %4, align 4, !tbaa !14
  %6 = sext i8 %5 to i32
  %7 = getelementptr inbounds i8, ptr %.027, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !16
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %.027, ptr noundef nonnull %3, i32 noundef %6, i32 noundef %8)
  %.0 = load ptr, ptr %.027, align 8, !tbaa !13
  %.not22 = icmp eq ptr %.0, null
  br i1 %.not22, label %.loopexit, label %.lr.ph, !llvm.loop !17

10:                                               ; preds = %0
  %11 = tail call ptr @get_set_iter(ptr noundef nonnull getelementptr inbounds (i8, ptr @GC, i64 16)) #3
  %.not20 = icmp eq ptr %11, null
  br i1 %.not20, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %10
  %12 = load ptr, ptr getelementptr inbounds (i8, ptr @GC, i64 16), align 8
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @GC, i64 24), align 8
  %14 = tail call i32 @get_set_size(ptr %12, i32 %13) #3
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph33, label %.loopexit

.lr.ph33:                                         ; preds = %.preheader, %._crit_edge
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 0, %.preheader ]
  %16 = getelementptr inbounds ptr, ptr %11, i64 %indvars.iv
  %.01728 = load ptr, ptr %16, align 8, !tbaa !13
  %.not2129 = icmp eq ptr %.01728, null
  br i1 %.not2129, label %._crit_edge, label %.lr.ph31

.lr.ph31:                                         ; preds = %.lr.ph33, %.lr.ph31
  %.01730 = phi ptr [ %.017, %.lr.ph31 ], [ %.01728, %.lr.ph33 ]
  %17 = getelementptr inbounds i8, ptr %.01730, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %18, i64 -24
  %20 = getelementptr inbounds i8, ptr %18, i64 -4
  %21 = load i8, ptr %20, align 4, !tbaa !14
  %22 = icmp eq i8 %21, 1
  %23 = zext i1 %22 to i32
  %24 = getelementptr inbounds i8, ptr %18, i64 -8
  %25 = load i32, ptr %24, align 8, !tbaa !16
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %19, ptr noundef %18, i32 noundef %23, i32 noundef %25)
  %27 = getelementptr inbounds i8, ptr %.01730, i64 16
  %.017 = load ptr, ptr %27, align 8, !tbaa !13
  %.not21 = icmp eq ptr %.017, null
  br i1 %.not21, label %._crit_edge, label %.lr.ph31, !llvm.loop !21

._crit_edge:                                      ; preds = %.lr.ph31, %.lr.ph33
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %28 = load ptr, ptr getelementptr inbounds (i8, ptr @GC, i64 16), align 8
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @GC, i64 24), align 8
  %30 = tail call i32 @get_set_size(ptr %28, i32 %29) #3
  %31 = sext i32 %30 to i64
  %32 = icmp slt i64 %indvars.iv.next, %31
  br i1 %32, label %.lr.ph33, label %.loopexit, !llvm.loop !22

.loopexit:                                        ; preds = %.lr.ph, %._crit_edge, %.preheader23, %.preheader, %10
  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 = { nofree nounwind "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, !8, i64 48}
!6 = !{!"gc", !7, i64 0, !10, i64 8, !11, i64 16, !7, i64 32, !7, i64 40, !8, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !12, i64 0}
!12 = !{!"hash_map", !7, i64 0, !10, i64 8}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !8, i64 20}
!15 = !{!"collectorBlock", !7, i64 0, !7, i64 8, !10, i64 16, !8, i64 20}
!16 = !{!15, !10, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !7, i64 8}
!20 = !{!"hash_node", !7, i64 0, !7, i64 8, !7, i64 16}
!21 = distinct !{!21, !18}
!22 = distinct !{!22, !18}


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