; LLVM IR from avaxar/ccgc :: ccgc (ccgc_free)

; 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.Block = type { i64, i8, i8, [6 x i8], [0 x i8] }

@page = external hidden global [65536 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [72 x i8], align 1
@__PRETTY_FUNCTION__.ccgc_free = external hidden unnamed_addr constant [23 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [32 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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @ccgc_free(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  br label %66

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Block, ptr %10, i64 -1
  store ptr %11, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp uge ptr %12, @page
  br i1 %13, label %14, label %18

14:                                               ; preds = %9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = icmp ult ptr %15, getelementptr inbounds (i8, ptr getelementptr inbounds (i8, ptr @page, i64 65536), i64 -16)
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  br label %19

18:                                               ; preds = %14, %9
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 97, ptr noundef @__PRETTY_FUNCTION__.ccgc_free) #4
  unreachable

19:                                               ; preds = %17
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Block, ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %30

24:                                               ; preds = %19
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Block, ptr %25, i32 0, i32 1
  %27 = load i8, ptr %26, align 8, !tbaa !13, !range !14, !noundef !15
  %28 = trunc i8 %27 to i1
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  br label %31

30:                                               ; preds = %24, %19
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 101, ptr noundef @__PRETTY_FUNCTION__.ccgc_free) #4
  unreachable

31:                                               ; preds = %29
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Block, ptr %32, i32 0, i32 1
  store i8 0, ptr %33, align 8, !tbaa !13
  br label %34

34:                                               ; preds = %64, %31
  br label %35

35:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Block, ptr %36, i32 0, i32 4
  %38 = getelementptr inbounds [0 x i8], ptr %37, i64 0, i64 0
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Block, ptr %39, i32 0, i32 0
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %38, i64 %41
  store ptr %42, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = icmp uge ptr %43, getelementptr inbounds (i8, ptr @page, i64 65536)
  br i1 %44, label %45, label %46

45:                                               ; preds = %35
  store i32 3, ptr %5, align 4
  br label %62

46:                                               ; preds = %35
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Block, ptr %47, i32 0, i32 1
  %49 = load i8, ptr %48, align 8, !tbaa !13, !range !14, !noundef !15
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %52

51:                                               ; preds = %46
  store i32 3, ptr %5, align 4
  br label %62

52:                                               ; preds = %46
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Block, ptr %53, i32 0, i32 0
  %55 = load i64, ptr %54, align 8, !tbaa !9
  %56 = add i64 16, %55
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Block, ptr %57, i32 0, i32 0
  %59 = load i64, ptr %58, align 8, !tbaa !9
  %60 = add i64 %59, %56
  store i64 %60, ptr %58, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %52
  store i32 0, ptr %5, align 4
  br label %62

62:                                               ; preds = %61, %51, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %63 = load i32, ptr %5, align 4
  switch i32 %63, label %67 [
    i32 0, label %64
    i32 3, label %65
  ]

64:                                               ; preds = %62
  br label %34

65:                                               ; preds = %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %66

66:                                               ; preds = %65, %8
  ret void

67:                                               ; preds = %62
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8, !12, i64 9, !7, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{i8 0, i8 2}
!15 = !{}


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

@page = external hidden global [65536 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [72 x i8], align 1
@__PRETTY_FUNCTION__.ccgc_free = external hidden unnamed_addr constant [23 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @ccgc_free(ptr noundef %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.thread, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 -16
  %5 = icmp uge ptr %4, @page
  %6 = icmp ult ptr %4, getelementptr inbounds (i8, ptr @page, i64 65520)
  %or.cond = select i1 %5, i1 %6, i1 false
  br i1 %or.cond, label %8, label %7

7:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 97, ptr noundef nonnull @__PRETTY_FUNCTION__.ccgc_free) #2
  unreachable

8:                                                ; preds = %3
  %9 = load i64, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %14, label %10

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %0, i64 -8
  %12 = load i8, ptr %11, align 8, !tbaa !11, !range !12, !noundef !13
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %15, label %14

14:                                               ; preds = %10, %8
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 101, ptr noundef nonnull @__PRETTY_FUNCTION__.ccgc_free) #2
  unreachable

15:                                               ; preds = %10
  store i8 0, ptr %11, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %0, i64 %9
  %.not1720 = icmp ult ptr %16, getelementptr inbounds (i8, ptr @page, i64 65536)
  br i1 %.not1720, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %15, %22
  %17 = phi ptr [ %26, %22 ], [ %16, %15 ]
  %18 = phi i64 [ %25, %22 ], [ %9, %15 ]
  %19 = getelementptr inbounds i8, ptr %17, i64 8
  %20 = load i8, ptr %19, align 8, !tbaa !11, !range !12, !noundef !13
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %.thread, label %22

22:                                               ; preds = %.lr.ph
  %23 = load i64, ptr %17, align 8, !tbaa !5
  %24 = add i64 %18, 16
  %25 = add i64 %24, %23
  store i64 %25, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %0, i64 %25
  %.not17 = icmp ult ptr %26, getelementptr inbounds (i8, ptr @page, i64 65536)
  br i1 %.not17, label %.lr.ph, label %.thread

.thread:                                          ; preds = %22, %.lr.ph, %15, %1
  ret void
}

attributes #0 = { 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 #1 = { 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 #2 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 9, !8, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{i8 0, i8 2}
!13 = !{}


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