; LLVM IR from mist64/perfect6502 :: netlist_sim (recalcNodeList)

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

; Function Attrs: nounwind uwtable
define dso_local void @recalcNodeList(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %37, %1
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 100
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  store i32 2, ptr %4, align 4
  br label %40

11:                                               ; preds = %7
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  call void @lists_switch(ptr noundef %12)
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call zeroext i16 @listin_count(ptr noundef %13)
  %15 = icmp ne i16 %14, 0
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  store i32 2, ptr %4, align 4
  br label %40

17:                                               ; preds = %11
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  call void @listout_clear(ptr noundef %18)
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #3
  store i16 0, ptr %5, align 2, !tbaa !11
  br label %19

19:                                               ; preds = %33, %17
  %20 = load i16, ptr %5, align 2, !tbaa !11
  %21 = zext i16 %20 to i32
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = call zeroext i16 @listin_count(ptr noundef %22)
  %24 = zext i16 %23 to i32
  %25 = icmp slt i32 %21, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %19
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #3
  br label %36

27:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #3
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = load i16, ptr %5, align 2, !tbaa !11
  %30 = call zeroext i16 @listin_get(ptr noundef %28, i16 noundef zeroext %29)
  store i16 %30, ptr %6, align 2, !tbaa !11
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = load i16, ptr %6, align 2, !tbaa !11
  call void @recalcNode(ptr noundef %31, i16 noundef zeroext %32)
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  br label %33

33:                                               ; preds = %27
  %34 = load i16, ptr %5, align 2, !tbaa !11
  %35 = add i16 %34, 1
  store i16 %35, ptr %5, align 2, !tbaa !11
  br label %19, !llvm.loop !13

36:                                               ; preds = %26
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %3, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !15

40:                                               ; preds = %16, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  call void @listout_clear(ptr noundef %42)
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @lists_switch(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @listin_count(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @listout_clear(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @listin_get(ptr noundef, i16 noundef zeroext) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @recalcNode(ptr noundef, i16 noundef zeroext) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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 = !{!12, !12, i64 0}
!12 = !{!"short", !7, 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: nounwind uwtable
define dso_local void @recalcNodeList(ptr noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %1, %._crit_edge
  %.014 = phi i32 [ 0, %1 ], [ %6, %._crit_edge ]
  tail call void @lists_switch(ptr noundef %0)
  %3 = tail call zeroext i16 @listin_count(ptr noundef %0)
  %.not = icmp eq i16 %3, 0
  br i1 %.not, label %11, label %4

4:                                                ; preds = %2
  tail call void @listout_clear(ptr noundef %0)
  %5 = tail call zeroext i16 @listin_count(ptr noundef %0)
  %.not15 = icmp eq i16 %5, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %4
  %6 = add nuw nsw i32 %.014, 1
  %exitcond.not = icmp eq i32 %6, 100
  br i1 %exitcond.not, label %11, label %2, !llvm.loop !5

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.01213 = phi i16 [ %8, %.lr.ph ], [ 0, %4 ]
  %7 = tail call zeroext i16 @listin_get(ptr noundef %0, i16 noundef zeroext %.01213)
  tail call void @recalcNode(ptr noundef %0, i16 noundef zeroext %7)
  %8 = add nuw i16 %.01213, 1
  %9 = tail call zeroext i16 @listin_count(ptr noundef %0)
  %10 = icmp ult i16 %8, %9
  br i1 %10, label %.lr.ph, label %._crit_edge, !llvm.loop !7

11:                                               ; preds = %2, %._crit_edge
  tail call void @listout_clear(ptr noundef %0)
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @lists_switch(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @listin_count(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @listout_clear(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @listin_get(ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @recalcNode(ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

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" }
attributes #1 = { inlinehint 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass