; LLVM IR from masyagin1998/GCI :: src/garbage-collector (ptrs-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.PTRS_MAP = type { ptr, i64, i64 }
%struct.PTRS_MAP_ELEM = type { ptr, ptr }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @ptrs_map_set(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %14

11:                                               ; preds = %3
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef @.str) #4
  call void @exit(i32 noundef 1) #5
  unreachable

14:                                               ; preds = %3
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %40, %14
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.PTRS_MAP, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = icmp ult i64 %16, %19
  br i1 %20, label %21, label %43

21:                                               ; preds = %15
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.PTRS_MAP, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.PTRS_MAP_ELEM, ptr %24, i64 %25
  %27 = getelementptr inbounds %struct.PTRS_MAP_ELEM, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = icmp eq ptr %28, %29
  br i1 %30, label %31, label %39

31:                                               ; preds = %21
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.PTRS_MAP, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.PTRS_MAP_ELEM, ptr %35, i64 %36
  %38 = getelementptr inbounds %struct.PTRS_MAP_ELEM, ptr %37, i32 0, i32 1
  store ptr %32, ptr %38, align 8, !tbaa !16
  store i32 1, ptr %8, align 4
  br label %77

39:                                               ; preds = %21
  br label %40

40:                                               ; preds = %39
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = add i64 %41, 1
  store i64 %42, ptr %7, align 8, !tbaa !9
  br label %15, !llvm.loop !17

43:                                               ; preds = %15
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.PTRS_MAP, ptr %44, i32 0, i32 1
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.PTRS_MAP, ptr %47, i32 0, i32 2
  %49 = load i64, ptr %48, align 8, !tbaa !19
  %50 = icmp eq i64 %46, %49
  br i1 %50, label %51, label %54

51:                                               ; preds = %43
  %52 = load ptr, ptr @stderr, align 8, !tbaa !5
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str.1) #4
  call void @exit(i32 noundef 1) #5
  unreachable

54:                                               ; preds = %43
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.PTRS_MAP, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.PTRS_MAP, ptr %59, i32 0, i32 1
  %61 = load i64, ptr %60, align 8, !tbaa !11
  %62 = getelementptr inbounds %struct.PTRS_MAP_ELEM, ptr %58, i64 %61
  %63 = getelementptr inbounds %struct.PTRS_MAP_ELEM, ptr %62, i32 0, i32 0
  store ptr %55, ptr %63, align 8, !tbaa !14
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.PTRS_MAP, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.PTRS_MAP, ptr %68, i32 0, i32 1
  %70 = load i64, ptr %69, align 8, !tbaa !11
  %71 = getelementptr inbounds %struct.PTRS_MAP_ELEM, ptr %67, i64 %70
  %72 = getelementptr inbounds %struct.PTRS_MAP_ELEM, ptr %71, i32 0, i32 1
  store ptr %64, ptr %72, align 8, !tbaa !16
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.PTRS_MAP, ptr %73, i32 0, i32 1
  %75 = load i64, ptr %74, align 8, !tbaa !11
  %76 = add i64 %75, 1
  store i64 %76, ptr %74, align 8, !tbaa !11
  store i32 0, ptr %8, align 4
  br label %77

77:                                               ; preds = %54, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %78 = load i32, ptr %8, align 4
  switch i32 %78, label %80 [
    i32 0, label %79
    i32 1, label %79
  ]

79:                                               ; preds = %77, %77
  ret void

80:                                               ; preds = %77
  unreachable
}

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { noreturn 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 #4 = { nounwind }
attributes #5 = { noreturn 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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"PTRS_MAP", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"PTRS_MAP_ELEM", !6, i64 0, !6, i64 8}
!16 = !{!15, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !10, i64 16}


; 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.PTRS_MAP_ELEM = type { ptr, ptr }

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @ptrs_map_set(ptr nocapture noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %1, null
  br i1 %4, label %8, label %.preheader

.preheader:                                       ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %7 = load ptr, ptr %0, align 8, !tbaa !11
  br label %13

8:                                                ; preds = %3
  %9 = load ptr, ptr @stderr, align 8, !tbaa !12
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str) #3
  tail call void @exit(i32 noundef 1) #4
  unreachable

11:                                               ; preds = %13
  %12 = add nuw i64 %.024, 1
  %exitcond.not = icmp eq i64 %12, %6
  br i1 %exitcond.not, label %._crit_edge, label %13, !llvm.loop !13

13:                                               ; preds = %.lr.ph, %11
  %.024 = phi i64 [ 0, %.lr.ph ], [ %12, %11 ]
  %14 = getelementptr inbounds %struct.PTRS_MAP_ELEM, ptr %7, i64 %.024
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = icmp eq ptr %15, %1
  br i1 %16, label %17, label %11

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr %2, ptr %18, align 8, !tbaa !17
  br label %30

._crit_edge:                                      ; preds = %11, %.preheader
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load i64, ptr %19, align 8, !tbaa !18
  %21 = icmp eq i64 %6, %20
  br i1 %21, label %22, label %25

22:                                               ; preds = %._crit_edge
  %23 = load ptr, ptr @stderr, align 8, !tbaa !12
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str.1) #3
  tail call void @exit(i32 noundef 1) #4
  unreachable

25:                                               ; preds = %._crit_edge
  %26 = load ptr, ptr %0, align 8, !tbaa !11
  %27 = getelementptr inbounds %struct.PTRS_MAP_ELEM, ptr %26, i64 %6
  store ptr %1, ptr %27, align 8, !tbaa !15
  %28 = getelementptr inbounds %struct.PTRS_MAP_ELEM, ptr %26, i64 %6, i32 1
  store ptr %2, ptr %28, align 8, !tbaa !17
  %29 = add i64 %6, 1
  store i64 %29, ptr %5, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %25, %17
  ret void
}

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #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 = { 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 = { noreturn 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 #3 = { cold nounwind }
attributes #4 = { noreturn 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 = !{!"PTRS_MAP", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !7, i64 0}
!16 = !{!"PTRS_MAP_ELEM", !7, i64 0, !7, i64 8}
!17 = !{!16, !7, i64 8}
!18 = !{!6, !10, i64 16}


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