; LLVM IR from ryanlayer/giggle :: test/unit (test_bpt)

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

; 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
define dso_local void @decrement_repair(i32 noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %33, %3
  %9 = load i32, ptr %7, align 4, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.bpt_node, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds i32, ptr %12, i64 5
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp ult i32 %9, %14
  br i1 %15, label %16, label %36

16:                                               ; preds = %8
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.bpt_node, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds i32, ptr %19, i64 6
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %20, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sub i32 %24, 1
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.bpt_node, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = getelementptr inbounds i32, ptr %28, i64 6
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr %29, i64 %31
  store i32 %25, ptr %32, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %16
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = add i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !5
  br label %8, !llvm.loop !13

36:                                               ; preds = %8
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %62, %36
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.bpt_node, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = getelementptr inbounds i32, ptr %41, i64 5
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = icmp ult i32 %38, %43
  br i1 %44, label %45, label %65

45:                                               ; preds = %37
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.bpt_node, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  %49 = getelementptr inbounds i32, ptr %48, i64 6
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %49, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add i32 %53, 1
  %55 = load ptr, ptr %6, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.bpt_node, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds i32, ptr %57, i64 6
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  store i32 %54, ptr %61, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %45
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = add i32 %63, 1
  store i32 %64, ptr %7, align 4, !tbaa !5
  br label %37, !llvm.loop !15

65:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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 = !{!"int", !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 = !{!12, !10, i64 0}
!12 = !{!"bpt_node", !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @decrement_repair(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 20
  %6 = load i32, ptr %5, align 4, !tbaa !10
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %7 = getelementptr inbounds i8, ptr %4, i64 24
  %wide.trip.count = zext i32 %6 to i64
  %min.iters.check = icmp ult i32 %6, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 4294967288
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %8 = getelementptr inbounds i32, ptr %7, i64 %index
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %wide.load = load <4 x i32>, ptr %8, align 4, !tbaa !10
  %wide.load21 = load <4 x i32>, ptr %9, align 4, !tbaa !10
  %10 = add <4 x i32> %wide.load, <i32 -1, i32 -1, i32 -1, i32 -1>
  %11 = add <4 x i32> %wide.load21, <i32 -1, i32 -1, i32 -1, i32 -1>
  store <4 x i32> %10, ptr %8, align 4, !tbaa !10
  store <4 x i32> %11, ptr %9, align 4, !tbaa !10
  %index.next = add nuw i64 %index, 8
  %12 = icmp eq i64 %index.next, %n.vec
  br i1 %12, label %middle.block, label %vector.body, !llvm.loop !12

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.preheader, label %scalar.ph.preheader

.preheader:                                       ; preds = %scalar.ph, %middle.block, %3
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 20
  %15 = load i32, ptr %14, align 4, !tbaa !10
  %.not16 = icmp eq i32 %15, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph15

.lr.ph15:                                         ; preds = %.preheader
  %16 = getelementptr inbounds i8, ptr %13, i64 24
  %17 = zext i32 %15 to i64
  %min.iters.check24 = icmp ult i32 %15, 8
  br i1 %min.iters.check24, label %scalar.ph23.preheader, label %vector.ph25

scalar.ph23.preheader:                            ; preds = %middle.block22, %.lr.ph15
  %indvars.iv18.ph = phi i64 [ 0, %.lr.ph15 ], [ %n.vec27, %middle.block22 ]
  br label %scalar.ph23

vector.ph25:                                      ; preds = %.lr.ph15
  %n.vec27 = and i64 %17, 4294967288
  br label %vector.body29

vector.body29:                                    ; preds = %vector.body29, %vector.ph25
  %index30 = phi i64 [ 0, %vector.ph25 ], [ %index.next33, %vector.body29 ]
  %18 = getelementptr inbounds i32, ptr %16, i64 %index30
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %wide.load31 = load <4 x i32>, ptr %18, align 4, !tbaa !10
  %wide.load32 = load <4 x i32>, ptr %19, align 4, !tbaa !10
  %20 = add <4 x i32> %wide.load31, <i32 1, i32 1, i32 1, i32 1>
  %21 = add <4 x i32> %wide.load32, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %20, ptr %18, align 4, !tbaa !10
  store <4 x i32> %21, ptr %19, align 4, !tbaa !10
  %index.next33 = add nuw i64 %index30, 8
  %22 = icmp eq i64 %index.next33, %n.vec27
  br i1 %22, label %middle.block22, label %vector.body29, !llvm.loop !16

middle.block22:                                   ; preds = %vector.body29
  %cmp.n34 = icmp eq i64 %n.vec27, %17
  br i1 %cmp.n34, label %._crit_edge, label %scalar.ph23.preheader

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %23 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !10
  %25 = add i32 %24, -1
  store i32 %25, ptr %23, align 4, !tbaa !10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %scalar.ph, !llvm.loop !17

scalar.ph23:                                      ; preds = %scalar.ph23.preheader, %scalar.ph23
  %indvars.iv18 = phi i64 [ %indvars.iv.next19, %scalar.ph23 ], [ %indvars.iv18.ph, %scalar.ph23.preheader ]
  %26 = getelementptr inbounds i32, ptr %16, i64 %indvars.iv18
  %27 = load i32, ptr %26, align 4, !tbaa !10
  %28 = add i32 %27, 1
  store i32 %28, ptr %26, align 4, !tbaa !10
  %indvars.iv.next19 = add nuw nsw i64 %indvars.iv18, 1
  %29 = icmp ult i64 %indvars.iv.next19, %17
  br i1 %29, label %scalar.ph23, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %scalar.ph23, %middle.block22, %.preheader
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = !{!"bpt_node", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = distinct !{!12, !13, !14, !15}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = distinct !{!16, !13, !14, !15}
!17 = distinct !{!17, !13, !15, !14}
!18 = distinct !{!18, !13, !15, !14}


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