; LLVM IR from mianzhi/fosolvers :: src/libfosolvers/otGrid (otree)

; 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.node = type { ptr, [8 x ptr], i32 }

; 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 dso_local void @getNode(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @nBinDigits(i64 noundef) #1

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

11:                                               ; preds = %3
  br label %12

12:                                               ; preds = %19, %11
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.node, ptr %14, i32 0, i32 1
  %16 = getelementptr inbounds [8 x ptr], ptr %15, i64 0, i64 0
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %29

19:                                               ; preds = %12
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = shl i64 %21, 3
  store i64 %22, ptr %20, align 8, !tbaa !9
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.node, ptr %24, i32 0, i32 1
  %26 = getelementptr inbounds [8 x ptr], ptr %25, i64 0, i64 0
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %27, ptr %28, align 8, !tbaa !5
  br label %12, !llvm.loop !11

29:                                               ; preds = %12
  br label %81

30:                                               ; preds = %3
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = add nsw i64 %32, 1
  store i64 %33, ptr %31, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %39, %30
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = srem i64 %36, 8
  %38 = icmp eq i64 %37, 0
  br i1 %38, label %39, label %43

39:                                               ; preds = %34
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = ashr i64 %41, 3
  store i64 %42, ptr %40, align 8, !tbaa !9
  br label %34, !llvm.loop !13

43:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = call i32 @nBinDigits(i64 noundef %45)
  store i32 %46, ptr %7, align 4, !tbaa !14
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !14
  %50 = sub nsw i32 %49, 3
  %51 = zext i32 %50 to i64
  %52 = ashr i64 %48, %51
  %53 = icmp eq i64 %52, 5
  br i1 %53, label %54, label %57

54:                                               ; preds = %43
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 4, ptr %55, align 8, !tbaa !9
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr null, ptr %56, align 8, !tbaa !5
  br label %80

57:                                               ; preds = %43
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i64, ptr %59, align 8, !tbaa !9
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  call void @getNode(ptr noundef %58, i64 noundef %60, ptr noundef %61)
  br label %62

62:                                               ; preds = %69, %57
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.node, ptr %64, i32 0, i32 1
  %66 = getelementptr inbounds [8 x ptr], ptr %65, i64 0, i64 0
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %79

69:                                               ; preds = %62
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load i64, ptr %70, align 8, !tbaa !9
  %72 = shl i64 %71, 3
  store i64 %72, ptr %70, align 8, !tbaa !9
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load ptr, ptr %73, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.node, ptr %74, i32 0, i32 1
  %76 = getelementptr inbounds [8 x ptr], ptr %75, i64 0, i64 0
  %77 = load ptr, ptr %76, align 8, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %77, ptr %78, align 8, !tbaa !5
  br label %62, !llvm.loop !16

79:                                               ; preds = %62
  br label %80

80:                                               ; preds = %79, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %81

81:                                               ; preds = %80, %29
  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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !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}


; 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: nounwind uwtable
declare dso_local void @getNode(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @nBinDigits(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @getNxtLf(ptr noundef %0, ptr nocapture noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = icmp eq i64 %4, 4
  br i1 %5, label %.preheader, label %13

.preheader:                                       ; preds = %3
  %.promoted24 = load ptr, ptr %2, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %.promoted24, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %.not1925 = icmp eq ptr %7, null
  br i1 %.not1925, label %.loopexit, label %.lr.ph26

.lr.ph26:                                         ; preds = %.preheader, %.lr.ph26
  %8 = phi i64 [ %10, %.lr.ph26 ], [ 4, %.preheader ]
  %9 = phi ptr [ %12, %.lr.ph26 ], [ %7, %.preheader ]
  %10 = shl i64 %8, 3
  store ptr %9, ptr %2, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %9, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %.not19 = icmp eq ptr %12, null
  br i1 %.not19, label %..loopexit_crit_edge, label %.lr.ph26, !llvm.loop !11

13:                                               ; preds = %3
  %14 = add nsw i64 %4, 1
  br label %15

15:                                               ; preds = %15, %13
  %storemerge = phi i64 [ %14, %13 ], [ %18, %15 ]
  %16 = and i64 %storemerge, 7
  %17 = icmp eq i64 %16, 0
  %18 = ashr exact i64 %storemerge, 3
  br i1 %17, label %15, label %19, !llvm.loop !13

19:                                               ; preds = %15
  store i64 %storemerge, ptr %1, align 8, !tbaa !5
  %20 = tail call i32 @nBinDigits(i64 noundef %storemerge)
  %21 = load i64, ptr %1, align 8, !tbaa !5
  %22 = add nsw i32 %20, -3
  %23 = zext nneg i32 %22 to i64
  %24 = ashr i64 %21, %23
  %25 = icmp eq i64 %24, 5
  br i1 %25, label %26, label %27

26:                                               ; preds = %19
  store i64 4, ptr %1, align 8, !tbaa !5
  store ptr null, ptr %2, align 8, !tbaa !9
  br label %.loopexit

27:                                               ; preds = %19
  tail call void @getNode(ptr noundef %0, i64 noundef %21, ptr noundef %2)
  %.promoted = load ptr, ptr %2, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %.promoted, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %.not22 = icmp eq ptr %29, null
  br i1 %.not22, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %27
  %.promoted23 = load i64, ptr %1, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %.lr.ph, %30
  %31 = phi i64 [ %.promoted23, %.lr.ph ], [ %33, %30 ]
  %32 = phi ptr [ %29, %.lr.ph ], [ %35, %30 ]
  %33 = shl i64 %31, 3
  store ptr %32, ptr %2, align 8, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %32, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %.not = icmp eq ptr %35, null
  br i1 %.not, label %..loopexit20_crit_edge, label %30, !llvm.loop !14

..loopexit_crit_edge:                             ; preds = %.lr.ph26
  store i64 %10, ptr %1, align 8, !tbaa !5
  br label %.loopexit

..loopexit20_crit_edge:                           ; preds = %30
  store i64 %33, ptr %1, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %27, %..loopexit20_crit_edge, %.preheader, %..loopexit_crit_edge, %26
  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, !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 = distinct !{!14, !12}


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