; LLVM IR from humz2k/sugaryc :: ext/bdwgc/cord/cordbscs.ll_CORD (prev)

; 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.CORD_Pos = type { i64, i32, ptr, i64, i64, [49 x %struct.CORD_pe], [8 x i8] }
%struct.CORD_pe = type { ptr, i64 }

; 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: nounwind uwtable
declare hidden void @CORD_extend_path(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @CORD__prev(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.CORD_Pos, ptr %6, i64 0
  %8 = getelementptr inbounds %struct.CORD_Pos, ptr %7, i32 0, i32 5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.CORD_Pos, ptr %9, i64 0
  %11 = getelementptr inbounds %struct.CORD_Pos, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [49 x %struct.CORD_pe], ptr %8, i64 0, i64 %13
  store ptr %14, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.CORD_Pos, ptr %15, i64 0
  %17 = getelementptr inbounds %struct.CORD_Pos, ptr %16, i32 0, i32 0
  %18 = load i64, ptr %17, align 8, !tbaa !13
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %24

20:                                               ; preds = %1
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.CORD_Pos, ptr %21, i64 0
  %23 = getelementptr inbounds %struct.CORD_Pos, ptr %22, i32 0, i32 1
  store i32 1431655765, ptr %23, align 8, !tbaa !9
  store i32 1, ptr %4, align 4
  br label %82

24:                                               ; preds = %1
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.CORD_Pos, ptr %25, i64 0
  %27 = getelementptr inbounds %struct.CORD_Pos, ptr %26, i32 0, i32 0
  %28 = load i64, ptr %27, align 8, !tbaa !13
  %29 = add i64 %28, -1
  store i64 %29, ptr %27, align 8, !tbaa !13
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.CORD_Pos, ptr %30, i64 0
  %32 = getelementptr inbounds %struct.CORD_Pos, ptr %31, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !13
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.CORD_pe, ptr %34, i32 0, i32 1
  %36 = load i64, ptr %35, align 8, !tbaa !14
  %37 = icmp uge i64 %33, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %24
  store i32 1, ptr %4, align 4
  br label %82

39:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.CORD_Pos, ptr %40, i64 0
  %42 = getelementptr inbounds %struct.CORD_Pos, ptr %41, i32 0, i32 5
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.CORD_Pos, ptr %43, i64 0
  %45 = getelementptr inbounds %struct.CORD_Pos, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 8, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [49 x %struct.CORD_pe], ptr %42, i64 0, i64 %47
  store ptr %48, ptr %5, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %67, %39
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.CORD_Pos, ptr %50, i64 0
  %52 = getelementptr inbounds %struct.CORD_Pos, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 8, !tbaa !9
  %54 = icmp sgt i32 %53, 0
  br i1 %54, label %55, label %65

55:                                               ; preds = %49
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.CORD_pe, ptr %56, i64 0
  %58 = getelementptr inbounds %struct.CORD_pe, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !14
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.CORD_pe, ptr %60, i64 -1
  %62 = getelementptr inbounds %struct.CORD_pe, ptr %61, i32 0, i32 1
  %63 = load i64, ptr %62, align 8, !tbaa !14
  %64 = icmp eq i64 %59, %63
  br label %65

65:                                               ; preds = %55, %49
  %66 = phi i1 [ false, %49 ], [ %64, %55 ]
  br i1 %66, label %67, label %75

67:                                               ; preds = %65
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.CORD_Pos, ptr %68, i64 0
  %70 = getelementptr inbounds %struct.CORD_Pos, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %70, align 8, !tbaa !9
  %72 = add nsw i32 %71, -1
  store i32 %72, ptr %70, align 8, !tbaa !9
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.CORD_pe, ptr %73, i32 -1
  store ptr %74, ptr %5, align 8, !tbaa !5
  br label %49, !llvm.loop !16

75:                                               ; preds = %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.CORD_Pos, ptr %76, i64 0
  %78 = getelementptr inbounds %struct.CORD_Pos, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 8, !tbaa !9
  %80 = add nsw i32 %79, -1
  store i32 %80, ptr %78, align 8, !tbaa !9
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  call void @CORD_extend_path(ptr noundef %81)
  store i32 0, ptr %4, align 4
  br label %82

82:                                               ; preds = %75, %38, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  %83 = load i32, ptr %4, align 4
  switch i32 %83, label %85 [
    i32 0, label %84
    i32 1, label %84
  ]

84:                                               ; preds = %82, %82
  ret void

85:                                               ; preds = %82
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !12, i64 8}
!10 = !{!"CORD_Pos", !11, i64 0, !12, i64 8, !6, i64 16, !11, i64 24, !11, i64 32, !7, i64 40, !7, i64 824}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!15, !11, i64 8}
!15 = !{!"CORD_pe", !6, i64 0, !11, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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.CORD_pe = type { ptr, i64 }

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

; Function Attrs: nounwind uwtable
define dso_local void @CORD__prev(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i64, ptr %0, align 8, !tbaa !5
  %5 = icmp eq i64 %4, 0
  br i1 %5, label %6, label %7

6:                                                ; preds = %1
  store i32 1431655765, ptr %3, align 8, !tbaa !12
  br label %27

7:                                                ; preds = %1
  %8 = load i32, ptr %3, align 8, !tbaa !12
  %9 = sext i32 %8 to i64
  %10 = add i64 %4, -1
  store i64 %10, ptr %0, align 8, !tbaa !5
  %11 = getelementptr inbounds [49 x %struct.CORD_pe], ptr %2, i64 0, i64 %9, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %.not = icmp ult i64 %10, %12
  br i1 %.not, label %13, label %27

13:                                               ; preds = %7
  %14 = icmp sgt i32 %8, 0
  br i1 %14, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %13
  %15 = getelementptr inbounds [49 x %struct.CORD_pe], ptr %2, i64 0, i64 %9
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %22
  %.018 = phi ptr [ %23, %22 ], [ %15, %.lr.ph.preheader ]
  %16 = phi i32 [ %24, %22 ], [ %8, %.lr.ph.preheader ]
  %17 = getelementptr inbounds i8, ptr %.018, i64 8
  %18 = load i64, ptr %17, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %.018, i64 -8
  %20 = load i64, ptr %19, align 8, !tbaa !13
  %21 = icmp eq i64 %18, %20
  br i1 %21, label %22, label %.critedge

22:                                               ; preds = %.lr.ph
  %23 = getelementptr inbounds i8, ptr %.018, i64 -16
  %24 = add nsw i32 %16, -1
  %25 = icmp sgt i32 %16, 1
  br i1 %25, label %.lr.ph, label %.critedge, !llvm.loop !15

.critedge:                                        ; preds = %.lr.ph, %22, %13
  %.lcssa = phi i32 [ %8, %13 ], [ 0, %22 ], [ %16, %.lr.ph ]
  %26 = add nsw i32 %.lcssa, -1
  store i32 %26, ptr %3, align 8, !tbaa !12
  tail call void @CORD_extend_path(ptr noundef nonnull %0)
  br label %27

27:                                               ; preds = %7, %.critedge, %6
  ret void
}

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

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


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