; LLVM IR from humz2k/sugaryc :: ext/bdwgc/extra (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_arrays = type { i64, i64, i64, ptr, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i64, i64, i64, ptr, ptr, i64, i32, i64, i64, i64, %struct.dl_hashtbl_s, %struct.dl_hashtbl_s, %struct.fnlz_roots_s, i32, ptr, i64, i64, i32, i64, i64, i64, ptr, [64 x ptr], [8 x i8], [64 x ptr], [129 x ptr], [129 x ptr], [129 x ptr], [2049 x i64], [129 x ptr], [4096 x i8], [4096 x i64], [4096 x i64], ptr, [2048 x %struct.roots], [512 x %struct.exclusion], [2048 x ptr] }
%struct.dl_hashtbl_s = type { ptr, i64, i32 }
%struct.fnlz_roots_s = type { ptr, ptr }
%struct.roots = type { ptr, ptr, ptr, i32 }
%struct.exclusion = type { ptr, ptr }
%struct.GC_hblk_s = type { [4096 x i8] }
%struct.hblkhdr = type { ptr, ptr, ptr, i8, i8, i16, i64, i64, ptr, i64, [5 x i64] }

@GC_all_interior_pointers = external dso_local global i32, align 4
@GC_arrays = external dso_local global %struct._GC_arrays, align 8
@GC_is_initialized = external hidden global i32, align 4
@GC_is_valid_displacement_print_proc = external dso_local 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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: nounwind uwtable
declare dso_local void @GC_init() #2

; Function Attrs: nounwind uwtable
declare hidden ptr @GC_find_header(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_is_valid_displacement(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load i32, ptr @GC_is_initialized, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = call i64 @llvm.expect.i64(i64 %11, i64 1)
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %1
  call void @GC_init()
  br label %15

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

18:                                               ; preds = %15
  store ptr null, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %104

19:                                               ; preds = %15
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = ptrtoint ptr %20 to i64
  %22 = inttoptr i64 %21 to ptr
  %23 = call ptr @GC_find_header(ptr noundef %22)
  store ptr %23, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = icmp eq ptr null, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %19
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %27, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %104

28:                                               ; preds = %19
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = ptrtoint ptr %29 to i64
  %31 = and i64 %30, -4096
  %32 = inttoptr i64 %31 to ptr
  store ptr %32, ptr %7, align 8, !tbaa !5
  %33 = load i32, ptr @GC_all_interior_pointers, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %49

35:                                               ; preds = %28
  br label %36

36:                                               ; preds = %40, %35
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = ptrtoint ptr %37 to i64
  %39 = icmp ule i64 %38, 4095
  br i1 %39, label %40, label %48

40:                                               ; preds = %36
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = ptrtoint ptr %42 to i64
  %44 = sub i64 0, %43
  %45 = getelementptr inbounds %struct.GC_hblk_s, ptr %41, i64 %44
  store ptr %45, ptr %7, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = call ptr @GC_find_header(ptr noundef %46)
  store ptr %47, ptr %4, align 8, !tbaa !5
  br label %36, !llvm.loop !11

48:                                               ; preds = %36
  br label %55

49:                                               ; preds = %28
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = ptrtoint ptr %50 to i64
  %52 = icmp ule i64 %51, 4095
  br i1 %52, label %53, label %54

53:                                               ; preds = %49
  br label %100

54:                                               ; preds = %49
  br label %55

55:                                               ; preds = %54, %48
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.hblkhdr, ptr %56, i32 0, i32 6
  %58 = load i64, ptr %57, align 8, !tbaa !13
  store i64 %58, ptr %8, align 8, !tbaa !17
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = ptrtoint ptr %59 to i64
  %61 = and i64 %60, 4095
  store i64 %61, ptr %5, align 8, !tbaa !17
  %62 = load i64, ptr %5, align 8, !tbaa !17
  %63 = load i64, ptr %8, align 8, !tbaa !17
  %64 = urem i64 %62, %63
  store i64 %64, ptr %6, align 8, !tbaa !17
  %65 = load i64, ptr %8, align 8, !tbaa !17
  %66 = icmp ugt i64 %65, 2048
  br i1 %66, label %67, label %75

67:                                               ; preds = %55
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = ptrtoint ptr %68 to i64
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = ptrtoint ptr %70 to i64
  %72 = load i64, ptr %8, align 8, !tbaa !17
  %73 = add i64 %71, %72
  %74 = icmp uge i64 %69, %73
  br i1 %74, label %97, label %75

75:                                               ; preds = %67, %55
  %76 = load i64, ptr %6, align 8, !tbaa !17
  %77 = getelementptr inbounds [4096 x i8], ptr getelementptr inbounds (%struct._GC_arrays, ptr @GC_arrays, i32 0, i32 55), i64 0, i64 %76
  %78 = load i8, ptr %77, align 1, !tbaa !18
  %79 = icmp ne i8 %78, 0
  br i1 %79, label %80, label %97

80:                                               ; preds = %75
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = ptrtoint ptr %81 to i64
  %83 = load i64, ptr %8, align 8, !tbaa !17
  %84 = load i64, ptr %6, align 8, !tbaa !17
  %85 = sub i64 %83, %84
  %86 = add i64 %82, %85
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.GC_hblk_s, ptr %87, i64 1
  %89 = ptrtoint ptr %88 to i64
  %90 = icmp ugt i64 %86, %89
  br i1 %90, label %91, label %98

91:                                               ; preds = %80
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.GC_hblk_s, ptr %92, i64 1
  %94 = call ptr @GC_find_header(ptr noundef %93)
  %95 = ptrtoint ptr %94 to i64
  %96 = icmp ule i64 %95, 4095
  br i1 %96, label %98, label %97

97:                                               ; preds = %91, %75, %67
  br label %100

98:                                               ; preds = %91, %80
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %99, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %104

100:                                              ; preds = %97, %53
  %101 = load ptr, ptr @GC_is_valid_displacement_print_proc, align 8, !tbaa !5
  %102 = load ptr, ptr %3, align 8, !tbaa !5
  call void %101(ptr noundef %102)
  %103 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %103, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %104

104:                                              ; preds = %100, %98, %26, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %105 = load ptr, ptr %2, align 8
  ret ptr %105
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !16, i64 32}
!14 = !{!"hblkhdr", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !7, i64 25, !15, i64 26, !16, i64 32, !16, i64 40, !6, i64 48, !16, i64 56, !7, i64 64}
!15 = !{!"short", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!7, !7, i64 0}


; 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_arrays = type { i64, i64, i64, ptr, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i64, i64, i64, ptr, ptr, i64, i32, i64, i64, i64, %struct.dl_hashtbl_s, %struct.dl_hashtbl_s, %struct.fnlz_roots_s, i32, ptr, i64, i64, i32, i64, i64, i64, ptr, [64 x ptr], [8 x i8], [64 x ptr], [129 x ptr], [129 x ptr], [129 x ptr], [2049 x i64], [129 x ptr], [4096 x i8], [4096 x i64], [4096 x i64], ptr, [2048 x %struct.roots], [512 x %struct.exclusion], [2048 x ptr] }
%struct.dl_hashtbl_s = type { ptr, i64, i32 }
%struct.fnlz_roots_s = type { ptr, ptr }
%struct.roots = type { ptr, ptr, ptr, i32 }
%struct.exclusion = type { ptr, ptr }
%struct.GC_hblk_s = type { [4096 x i8] }

@GC_all_interior_pointers = external dso_local local_unnamed_addr global i32, align 4
@GC_arrays = external dso_local local_unnamed_addr global %struct._GC_arrays, align 8
@GC_is_initialized = external hidden local_unnamed_addr global i32, align 4
@GC_is_valid_displacement_print_proc = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @GC_init() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden ptr @GC_find_header(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @GC_is_valid_displacement(ptr noundef returned %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @GC_is_initialized, align 4, !tbaa !5
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %3, label %4, !prof !9

3:                                                ; preds = %1
  tail call void @GC_init()
  br label %4

4:                                                ; preds = %3, %1
  %5 = icmp eq ptr %0, null
  br i1 %5, label %42, label %6

6:                                                ; preds = %4
  %7 = ptrtoint ptr %0 to i64
  %8 = tail call ptr @GC_find_header(ptr noundef nonnull %0)
  %9 = icmp eq ptr %8, null
  br i1 %9, label %42, label %10

10:                                               ; preds = %6
  %11 = and i64 %7, -4096
  %12 = inttoptr i64 %11 to ptr
  %13 = load i32, ptr @GC_all_interior_pointers, align 4, !tbaa !5
  %.not34 = icmp eq i32 %13, 0
  %14 = icmp ult ptr %8, inttoptr (i64 4096 to ptr)
  br i1 %.not34, label %20, label %.preheader

.preheader:                                       ; preds = %10
  br i1 %14, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.02739 = phi ptr [ %17, %.lr.ph ], [ %12, %.preheader ]
  %.02838 = phi ptr [ %18, %.lr.ph ], [ %8, %.preheader ]
  %15 = ptrtoint ptr %.02838 to i64
  %16 = sub nsw i64 0, %15
  %17 = getelementptr inbounds %struct.GC_hblk_s, ptr %.02739, i64 %16
  %18 = tail call ptr @GC_find_header(ptr noundef %17)
  %19 = icmp ult ptr %18, inttoptr (i64 4096 to ptr)
  br i1 %19, label %.lr.ph, label %.loopexit, !llvm.loop !10

20:                                               ; preds = %10
  br i1 %14, label %40, label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %20
  %.129 = phi ptr [ %8, %20 ], [ %8, %.preheader ], [ %18, %.lr.ph ]
  %.1 = phi ptr [ %12, %20 ], [ %12, %.preheader ], [ %17, %.lr.ph ]
  %21 = getelementptr inbounds i8, ptr %.129, i64 32
  %22 = load i64, ptr %21, align 8, !tbaa !12
  %23 = and i64 %7, 4095
  %24 = urem i64 %23, %22
  %25 = icmp ult i64 %22, 2049
  %26 = ptrtoint ptr %.1 to i64
  %27 = add i64 %22, %26
  %.not35 = icmp ugt i64 %27, %7
  %or.cond = or i1 %25, %.not35
  br i1 %or.cond, label %28, label %40

28:                                               ; preds = %.loopexit
  %29 = getelementptr inbounds [4096 x i8], ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 21960), i64 0, i64 %24
  %30 = load i8, ptr %29, align 1, !tbaa !17
  %.not36 = icmp eq i8 %30, 0
  br i1 %.not36, label %40, label %31

31:                                               ; preds = %28
  %32 = add i64 %22, %7
  %33 = sub i64 %32, %24
  %34 = getelementptr inbounds i8, ptr %.1, i64 4096
  %35 = ptrtoint ptr %34 to i64
  %36 = icmp ugt i64 %33, %35
  br i1 %36, label %37, label %42

37:                                               ; preds = %31
  %38 = tail call ptr @GC_find_header(ptr noundef nonnull %34)
  %39 = icmp ult ptr %38, inttoptr (i64 4096 to ptr)
  br i1 %39, label %42, label %40

40:                                               ; preds = %.loopexit, %28, %37, %20
  %41 = load ptr, ptr @GC_is_valid_displacement_print_proc, align 8, !tbaa !18
  tail call void %41(ptr noundef nonnull %0) #1
  br label %42

42:                                               ; preds = %31, %37, %6, %4, %40
  ret ptr %0
}

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !16, i64 32}
!13 = !{!"hblkhdr", !14, i64 0, !14, i64 8, !14, i64 16, !7, i64 24, !7, i64 25, !15, i64 26, !16, i64 32, !16, i64 40, !14, i64 48, !16, i64 56, !7, i64 64}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!14, !14, i64 0}


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