; 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 void @getNode(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = icmp eq i64 %9, 4
  br i1 %10, label %17, label %11

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

17:                                               ; preds = %11, %3
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %18, ptr %19, align 8, !tbaa !5
  br label %50

20:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = call i32 @nBinDigits(i64 noundef %21)
  store i32 %22, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = load i32, ptr %7, align 4, !tbaa !11
  %25 = sub nsw i32 %24, 6
  %26 = zext i32 %25 to i64
  %27 = ashr i64 %23, %26
  %28 = srem i64 %27, 8
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr %8, align 4, !tbaa !11
  %30 = load i32, ptr %7, align 4, !tbaa !11
  %31 = sub nsw i32 %30, 3
  %32 = sub nsw i32 %31, 1
  %33 = shl i32 1, %32
  %34 = zext i32 %33 to i64
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = load i32, ptr %7, align 4, !tbaa !11
  %37 = sub nsw i32 %36, 6
  %38 = shl i32 1, %37
  %39 = zext i32 %38 to i64
  %40 = srem i64 %35, %39
  %41 = add nsw i64 %34, %40
  store i64 %41, ptr %5, align 8, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.node, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %8, align 4, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [8 x ptr], ptr %43, i64 0, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = load i64, ptr %5, align 8, !tbaa !9
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  call void @getNode(ptr noundef %47, i64 noundef %48, ptr noundef %49)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %50

50:                                               ; preds = %20, %17
  ret void
}

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

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


; 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
define dso_local void @getNode(ptr noundef %0, i64 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = icmp eq i64 %1, 4
  br i1 %4, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %tailrecurse
  %.tr1316 = phi i64 [ %19, %tailrecurse ], [ %1, %3 ]
  %.tr15 = phi ptr [ %21, %tailrecurse ], [ %0, %3 ]
  %5 = getelementptr inbounds i8, ptr %.tr15, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %._crit_edge, label %tailrecurse

._crit_edge:                                      ; preds = %tailrecurse, %.lr.ph, %3
  %.tr.lcssa = phi ptr [ %0, %3 ], [ %.tr15, %.lr.ph ], [ %21, %tailrecurse ]
  store ptr %.tr.lcssa, ptr %2, align 8, !tbaa !5
  ret void

tailrecurse:                                      ; preds = %.lr.ph
  %8 = tail call i32 @nBinDigits(i64 noundef %.tr1316)
  %9 = add nsw i32 %8, -6
  %10 = zext nneg i32 %9 to i64
  %11 = ashr i64 %.tr1316, %10
  %12 = srem i64 %11, 8
  %13 = add nsw i32 %8, -4
  %14 = shl nuw i32 1, %13
  %15 = zext i32 %14 to i64
  %16 = shl nuw i32 1, %9
  %17 = zext i32 %16 to i64
  %18 = srem i64 %.tr1316, %17
  %19 = add nsw i64 %18, %15
  %20 = getelementptr inbounds [8 x ptr], ptr %5, i64 0, i64 %12
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = icmp eq i64 %19, 4
  br i1 %22, label %._crit_edge, label %.lr.ph
}

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

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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