; LLVM IR from humz2k/sugaryc :: ext/bdwgc (os_dep)

; 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"

@GC_get_maps.maps_buf = external hidden global ptr, align 8
@GC_get_maps.maps_buf_sz = external hidden global i64, align 8
@.str = external hidden unnamed_addr constant [68 x i8], align 1
@GC_on_abort = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_get_maps() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store i64 4000, ptr %2, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %75, %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  br label %5

5:                                                ; preds = %30, %4
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  %8 = icmp uge i64 %6, %7
  br i1 %8, label %9, label %31

9:                                                ; preds = %5
  %10 = load ptr, ptr @GC_get_maps.maps_buf, align 8, !tbaa !9
  %11 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  call void @GC_scratch_recycle_inner(ptr noundef %10, i64 noundef %11)
  br label %12

12:                                               ; preds = %16, %9
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  %15 = icmp uge i64 %13, %14
  br i1 %15, label %16, label %19

16:                                               ; preds = %12
  %17 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  %18 = mul i64 %17, 2
  store i64 %18, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  br label %12, !llvm.loop !11

19:                                               ; preds = %12
  %20 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  %21 = call ptr @GC_scratch_alloc(i64 noundef %20)
  store ptr %21, ptr @GC_get_maps.maps_buf, align 8, !tbaa !9
  %22 = load ptr, ptr @GC_get_maps.maps_buf, align 8, !tbaa !9
  %23 = icmp eq ptr null, %22
  br i1 %23, label %24, label %30

24:                                               ; preds = %19
  br label %25

25:                                               ; preds = %24
  %26 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  call void (ptr, ...) @GC_log_printf(ptr noundef @.str, i64 noundef %26)
  %27 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  call void %27(ptr noundef @.str.1)
  call void @abort() #6
  unreachable

28:                                               ; No predecessors!
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29, %19
  br label %5, !llvm.loop !13

31:                                               ; preds = %5
  %32 = call i32 (ptr, i32, ...) @open(ptr noundef @.str.2, i32 noundef 0)
  store i32 %32, ptr %3, align 4, !tbaa !14
  %33 = load i32, ptr %3, align 4, !tbaa !14
  %34 = icmp eq i32 -1, %33
  br i1 %34, label %35, label %42

35:                                               ; preds = %31
  br label %36

36:                                               ; preds = %35
  %37 = call ptr @__errno_location() #7
  %38 = load i32, ptr %37, align 4, !tbaa !14
  call void (ptr, ...) @GC_log_printf(ptr noundef @.str.3, i32 noundef %38)
  %39 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  call void %39(ptr noundef @.str.4)
  call void @abort() #6
  unreachable

40:                                               ; No predecessors!
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41, %31
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %62, %42
  %44 = load i32, ptr %3, align 4, !tbaa !14
  %45 = load ptr, ptr @GC_get_maps.maps_buf, align 8, !tbaa !9
  %46 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  %47 = sub i64 %46, 1
  %48 = call i64 @GC_repeat_read(i32 noundef %44, ptr noundef %45, i64 noundef %47)
  store i64 %48, ptr %1, align 8, !tbaa !5
  %49 = load i64, ptr %1, align 8, !tbaa !5
  %50 = icmp slt i64 %49, 0
  br i1 %50, label %51, label %58

51:                                               ; preds = %43
  br label %52

52:                                               ; preds = %51
  %53 = call ptr @__errno_location() #7
  %54 = load i32, ptr %53, align 4, !tbaa !14
  call void (ptr, ...) @GC_log_printf(ptr noundef @.str.5, i32 noundef %54)
  %55 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  call void %55(ptr noundef @.str.6)
  call void @abort() #6
  unreachable

56:                                               ; No predecessors!
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57, %43
  %59 = load i64, ptr %1, align 8, !tbaa !5
  %60 = load i64, ptr %2, align 8, !tbaa !5
  %61 = add i64 %60, %59
  store i64 %61, ptr %2, align 8, !tbaa !5
  br label %62

62:                                               ; preds = %58
  %63 = load i64, ptr %1, align 8, !tbaa !5
  %64 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  %65 = sub i64 %64, 1
  %66 = icmp eq i64 %63, %65
  br i1 %66, label %43, label %67, !llvm.loop !16

67:                                               ; preds = %62
  %68 = load i32, ptr %3, align 4, !tbaa !14
  %69 = call i32 @close(i32 noundef %68)
  %70 = load i64, ptr %2, align 8, !tbaa !5
  %71 = icmp eq i64 0, %70
  br i1 %71, label %72, label %74

72:                                               ; preds = %67
  %73 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  call void %73(ptr noundef @.str.7)
  call void @abort() #6
  unreachable

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

75:                                               ; preds = %74
  %76 = load i64, ptr %2, align 8, !tbaa !5
  %77 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  %78 = icmp uge i64 %76, %77
  br i1 %78, label %4, label %79, !llvm.loop !17

79:                                               ; preds = %75
  %80 = load ptr, ptr @GC_get_maps.maps_buf, align 8, !tbaa !9
  %81 = load i64, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds i8, ptr %80, i64 %81
  store i8 0, ptr %82, align 1, !tbaa !18
  %83 = load ptr, ptr @GC_get_maps.maps_buf, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret ptr %83
}

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

declare void @GC_scratch_recycle_inner(ptr noundef, i64 noundef) #2

declare ptr @GC_scratch_alloc(i64 noundef) #2

declare void @GC_log_printf(ptr noundef, ...) #2

; Function Attrs: noreturn nounwind
declare void @abort() #3

declare i32 @open(ptr noundef, i32 noundef, ...) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

; Function Attrs: nounwind uwtable
declare hidden i64 @GC_repeat_read(i32 noundef, ptr noundef, i64 noundef) #0

declare i32 @close(i32 noundef) #2

; 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 = { "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 willreturn memory(none) "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 = { noreturn nounwind }
attributes #7 = { nounwind willreturn memory(none) }

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

@GC_get_maps.maps_buf = external hidden local_unnamed_addr global ptr, align 8
@GC_get_maps.maps_buf_sz = external hidden local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [68 x i8], align 1
@GC_on_abort = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @GC_get_maps() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %40, %0
  %.0 = phi i64 [ 4000, %0 ], [ %31, %40 ]
  br label %2

2:                                                ; preds = %8, %1
  %3 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  %.not = icmp ult i64 %.0, %3
  br i1 %.not, label %14, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr @GC_get_maps.maps_buf, align 8, !tbaa !9
  tail call void @GC_scratch_recycle_inner(ptr noundef %5, i64 noundef %3) #5
  %GC_get_maps.maps_buf_sz.promoted = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  %.not1922 = icmp ult i64 %.0, %GC_get_maps.maps_buf_sz.promoted
  br i1 %.not1922, label %8, label %.lr.ph

.lr.ph:                                           ; preds = %4, %.lr.ph
  %6 = phi i64 [ %7, %.lr.ph ], [ %GC_get_maps.maps_buf_sz.promoted, %4 ]
  %7 = shl i64 %6, 1
  %.not19 = icmp ult i64 %.0, %7
  br i1 %.not19, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph
  store i64 %7, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %._crit_edge, %4
  %.lcssa = phi i64 [ %7, %._crit_edge ], [ %GC_get_maps.maps_buf_sz.promoted, %4 ]
  %9 = tail call ptr @GC_scratch_alloc(i64 noundef %.lcssa) #5
  store ptr %9, ptr @GC_get_maps.maps_buf, align 8, !tbaa !9
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %2, !llvm.loop !13

11:                                               ; preds = %8
  %12 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  tail call void (ptr, ...) @GC_log_printf(ptr noundef nonnull @.str, i64 noundef %12) #5
  %13 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  tail call void %13(ptr noundef nonnull @.str.1) #5
  tail call void @abort() #6
  unreachable

14:                                               ; preds = %2
  %15 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull @.str.2, i32 noundef 0) #5
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %.preheader.preheader

.preheader.preheader:                             ; preds = %14
  %.pre = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  br label %.preheader

17:                                               ; preds = %14
  %18 = tail call ptr @__errno_location() #7
  %19 = load i32, ptr %18, align 4, !tbaa !14
  tail call void (ptr, ...) @GC_log_printf(ptr noundef nonnull @.str.3, i32 noundef %19) #5
  %20 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  tail call void %20(ptr noundef nonnull @.str.4) #5
  tail call void @abort() #6
  unreachable

.preheader:                                       ; preds = %.preheader.preheader, %30
  %21 = phi i64 [ %32, %30 ], [ %.pre, %.preheader.preheader ]
  %.1 = phi i64 [ %31, %30 ], [ 0, %.preheader.preheader ]
  %22 = load ptr, ptr @GC_get_maps.maps_buf, align 8, !tbaa !9
  %23 = add i64 %21, -1
  %24 = tail call i64 @GC_repeat_read(i32 noundef %15, ptr noundef %22, i64 noundef %23)
  %25 = icmp slt i64 %24, 0
  br i1 %25, label %26, label %30

26:                                               ; preds = %.preheader
  %27 = tail call ptr @__errno_location() #7
  %28 = load i32, ptr %27, align 4, !tbaa !14
  tail call void (ptr, ...) @GC_log_printf(ptr noundef nonnull @.str.5, i32 noundef %28) #5
  %29 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  tail call void %29(ptr noundef nonnull @.str.6) #5
  tail call void @abort() #6
  unreachable

30:                                               ; preds = %.preheader
  %31 = add i64 %24, %.1
  %32 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  %33 = add i64 %32, -1
  %34 = icmp eq i64 %24, %33
  br i1 %34, label %.preheader, label %35, !llvm.loop !16

35:                                               ; preds = %30
  %36 = tail call i32 @close(i32 noundef %15) #5
  %37 = icmp eq i64 %31, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %35
  %39 = load ptr, ptr @GC_on_abort, align 8, !tbaa !9
  tail call void %39(ptr noundef nonnull @.str.7) #5
  tail call void @abort() #6
  unreachable

40:                                               ; preds = %35
  %41 = load i64, ptr @GC_get_maps.maps_buf_sz, align 8, !tbaa !5
  %.not18 = icmp ult i64 %31, %41
  br i1 %.not18, label %42, label %1, !llvm.loop !17

42:                                               ; preds = %40
  %43 = load ptr, ptr @GC_get_maps.maps_buf, align 8, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %43, i64 %31
  store i8 0, ptr %44, align 1, !tbaa !18
  %45 = load ptr, ptr @GC_get_maps.maps_buf, align 8, !tbaa !9
  ret ptr %45
}

declare void @GC_scratch_recycle_inner(ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @GC_scratch_alloc(i64 noundef) local_unnamed_addr #1

declare void @GC_log_printf(ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #2

; Function Attrs: nofree
declare noundef i32 @open(ptr nocapture noundef readonly, i32 noundef, ...) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden i64 @GC_repeat_read(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare i32 @close(i32 noundef) local_unnamed_addr #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 = { "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 = { nofree "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { noreturn nounwind }
attributes #7 = { nounwind willreturn memory(none) }

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


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