; 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.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

@GC = external hidden global %struct.gc, align 8
@__rsp = external hidden global ptr, 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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @getRoots() #3 {
  %1 = alloca [1 x %struct.__jmp_buf_tag], align 16
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 200, ptr %1) #5
  %5 = getelementptr inbounds [1 x %struct.__jmp_buf_tag], ptr %1, i64 0, i64 0
  %6 = call i32 @_setjmp(ptr noundef %5) #6
  %7 = call ptr asm sideeffect "movq %rsp, $0", "=r,~{dirflag},~{fpsr},~{flags}"() #5, !srcloc !5
  store ptr %7, ptr @__rsp, align 8, !tbaa !6
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %8 = call noalias ptr @malloc(i64 noundef 16) #7
  store ptr %8, ptr %2, align 8, !tbaa !6
  %9 = load ptr, ptr %2, align 8, !tbaa !6
  call void @initMap(ptr noundef %9, i32 noundef 16)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %10 = load ptr, ptr @__rsp, align 8, !tbaa !6
  store ptr %10, ptr %3, align 8, !tbaa !6
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %11 = load ptr, ptr @GC, align 8, !tbaa !10
  store ptr %11, ptr %4, align 8, !tbaa !6
  br label %12

12:                                               ; preds = %31, %0
  %13 = load ptr, ptr %3, align 8, !tbaa !6
  %14 = load ptr, ptr %4, align 8, !tbaa !6
  %15 = icmp ult ptr %13, %14
  br i1 %15, label %16, label %34

16:                                               ; preds = %12
  %17 = load ptr, ptr %3, align 8, !tbaa !6
  %18 = load i64, ptr %17, align 8, !tbaa !15
  %19 = inttoptr i64 %18 to ptr
  %20 = load ptr, ptr getelementptr inbounds (%struct.gc, ptr @GC, i32 0, i32 2), align 8
  %21 = load i32, ptr getelementptr inbounds ({ ptr, i32 }, ptr getelementptr inbounds (%struct.gc, ptr @GC, i32 0, i32 2), i32 0, i32 1), align 8
  %22 = call i32 @search(ptr %20, i32 %21, ptr noundef %19)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %31

24:                                               ; preds = %16
  %25 = load ptr, ptr %2, align 8, !tbaa !6
  %26 = load ptr, ptr %3, align 8, !tbaa !6
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = inttoptr i64 %27 to ptr
  %29 = load ptr, ptr %3, align 8, !tbaa !6
  %30 = call i32 @add_node(ptr noundef %25, ptr noundef %28, ptr noundef %29)
  br label %31

31:                                               ; preds = %24, %16
  %32 = load ptr, ptr %3, align 8, !tbaa !6
  %33 = getelementptr inbounds i8, ptr %32, i32 1
  store ptr %33, ptr %3, align 8, !tbaa !6
  br label %12, !llvm.loop !17

34:                                               ; preds = %12
  %35 = load ptr, ptr %2, align 8, !tbaa !6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 200, ptr %1) #5
  ret ptr %35
}

; Function Attrs: nounwind returns_twice
declare i32 @_setjmp(ptr noundef) #4

declare void @initMap(ptr noundef, i32 noundef) #1

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

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 allocsize(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 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 #4 = { nounwind returns_twice "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 #5 = { nounwind }
attributes #6 = { nounwind returns_twice }
attributes #7 = { nounwind allocsize(0) }

!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 = !{i64 2147922647}
!6 = !{!7, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"gc", !7, i64 0, !12, i64 8, !13, i64 16, !7, i64 32, !7, i64 40, !8, i64 48}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !14, i64 0}
!14 = !{!"hash_map", !7, i64 0, !12, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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.gc = type { ptr, i32, %struct.set_t, ptr, ptr, i8 }
%struct.set_t = type { %struct.hash_map }
%struct.hash_map = type { ptr, i32 }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @getRoots() local_unnamed_addr #3 {
  %1 = alloca [1 x %struct.__jmp_buf_tag], align 16
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %1) #5
  %2 = call i32 @_setjmp(ptr noundef nonnull %1) #6
  %3 = call ptr asm sideeffect "movq %rsp, $0", "=r,~{dirflag},~{fpsr},~{flags}"() #5, !srcloc !5
  store ptr %3, ptr @__rsp, align 8, !tbaa !6
  %4 = call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #7
  call void @initMap(ptr noundef %4, i32 noundef 16) #5
  %5 = load ptr, ptr @__rsp, align 8, !tbaa !6
  %6 = load ptr, ptr @GC, align 8, !tbaa !10
  %7 = icmp ult ptr %5, %6
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %17
  %.09 = phi ptr [ %18, %17 ], [ %5, %0 ]
  %8 = load i64, ptr %.09, align 8, !tbaa !15
  %9 = inttoptr i64 %8 to ptr
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @GC, i64 16), align 8
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @GC, i64 24), align 8
  %12 = call i32 @search(ptr %10, i32 %11, ptr noundef %9) #5
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %17, label %13

13:                                               ; preds = %.lr.ph
  %14 = load i64, ptr %.09, align 8, !tbaa !15
  %15 = inttoptr i64 %14 to ptr
  %16 = call i32 @add_node(ptr noundef %4, ptr noundef %15, ptr noundef nonnull %.09) #5
  br label %17

17:                                               ; preds = %13, %.lr.ph
  %18 = getelementptr inbounds i8, ptr %.09, i64 1
  %exitcond.not = icmp eq ptr %18, %6
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %17, %0
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %1) #5
  ret ptr %4
}

; Function Attrs: nounwind returns_twice
declare i32 @_setjmp(ptr noundef) local_unnamed_addr #4

declare void @initMap(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @add_node(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 #4 = { nounwind returns_twice "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 #5 = { nounwind }
attributes #6 = { nounwind returns_twice }
attributes #7 = { nounwind allocsize(0) }

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


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