; 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
define dso_local i32 @nLf(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.node, ptr %5, i32 0, i32 1
  %7 = getelementptr inbounds [8 x ptr], ptr %6, i64 0, i64 0
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %30

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %26, %11
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 8
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %29

16:                                               ; preds = %12
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.node, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [8 x ptr], ptr %18, i64 0, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = call i32 @nLf(ptr noundef %22)
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = add nsw i32 %24, %23
  store i32 %25, ptr %3, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %16
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %4, align 4, !tbaa !9
  br label %12, !llvm.loop !11

29:                                               ; preds = %15
  br label %30

30:                                               ; preds = %29, %10
  %31 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %31
}

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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

; Function Attrs: nofree nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @nLf(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %.preheader.preheader, %1
  %accumulator.tr = phi i32 [ 0, %1 ], [ %32, %.preheader.preheader ]
  %.tr = phi ptr [ %0, %1 ], [ %31, %.preheader.preheader ]
  %2 = getelementptr inbounds i8, ptr %.tr, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %tailrecurse
  %5 = tail call i32 @nLf(ptr noundef nonnull %3)
  %6 = getelementptr inbounds i8, ptr %.tr, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = tail call i32 @nLf(ptr noundef %7)
  %9 = add nsw i32 %8, %5
  %10 = getelementptr inbounds i8, ptr %.tr, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = tail call i32 @nLf(ptr noundef %11)
  %13 = add nsw i32 %12, %9
  %14 = getelementptr inbounds i8, ptr %.tr, i64 32
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = tail call i32 @nLf(ptr noundef %15)
  %17 = add nsw i32 %16, %13
  %18 = getelementptr inbounds i8, ptr %.tr, i64 40
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = tail call i32 @nLf(ptr noundef %19)
  %21 = add nsw i32 %20, %17
  %22 = getelementptr inbounds i8, ptr %.tr, i64 48
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = tail call i32 @nLf(ptr noundef %23)
  %25 = add nsw i32 %24, %21
  %26 = getelementptr inbounds i8, ptr %.tr, i64 56
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = tail call i32 @nLf(ptr noundef %27)
  %29 = add nsw i32 %28, %25
  %30 = getelementptr inbounds i8, ptr %.tr, i64 64
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = add nsw i32 %accumulator.tr, %29
  br label %tailrecurse

.loopexit:                                        ; preds = %tailrecurse
  %accumulator.ret.tr = add nsw i32 %accumulator.tr, 1
  ret i32 %accumulator.ret.tr
}

attributes #0 = { nofree nosync nounwind memory(read, 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass