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

; 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: 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 @setNode(ptr noundef, i16 noundef zeroext, i32 noundef) #1

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

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

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %28

14:                                               ; preds = %10
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i16, ptr %16, i64 %18
  %20 = load i16, ptr %19, align 2, !tbaa !11
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = and i32 %21, 1
  call void @setNode(ptr noundef %15, i16 noundef zeroext %20, i32 noundef %22)
  br label %23

23:                                               ; preds = %14
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %9, align 4, !tbaa !9
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = ashr i32 %26, 1
  store i32 %27, ptr %8, align 4, !tbaa !9
  br label %10, !llvm.loop !13

28:                                               ; preds = %13
  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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: nounwind uwtable
declare dso_local void @setNode(ptr noundef, i16 noundef zeroext, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @writeNodes(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load i16, ptr %2, align 2, !tbaa !5
  %6 = and i32 %3, 1
  tail call void @setNode(ptr noundef %0, i16 noundef zeroext %5, i32 noundef %6)
  %7 = lshr i32 %3, 1
  %8 = getelementptr inbounds i8, ptr %2, i64 2
  %9 = load i16, ptr %8, align 2, !tbaa !5
  %10 = and i32 %7, 1
  tail call void @setNode(ptr noundef %0, i16 noundef zeroext %9, i32 noundef %10)
  %11 = lshr i32 %3, 2
  %12 = getelementptr inbounds i8, ptr %2, i64 4
  %13 = load i16, ptr %12, align 2, !tbaa !5
  %14 = and i32 %11, 1
  tail call void @setNode(ptr noundef %0, i16 noundef zeroext %13, i32 noundef %14)
  %15 = lshr i32 %3, 3
  %16 = getelementptr inbounds i8, ptr %2, i64 6
  %17 = load i16, ptr %16, align 2, !tbaa !5
  %18 = and i32 %15, 1
  tail call void @setNode(ptr noundef %0, i16 noundef zeroext %17, i32 noundef %18)
  %19 = lshr i32 %3, 4
  %20 = getelementptr inbounds i8, ptr %2, i64 8
  %21 = load i16, ptr %20, align 2, !tbaa !5
  %22 = and i32 %19, 1
  tail call void @setNode(ptr noundef %0, i16 noundef zeroext %21, i32 noundef %22)
  %23 = lshr i32 %3, 5
  %24 = getelementptr inbounds i8, ptr %2, i64 10
  %25 = load i16, ptr %24, align 2, !tbaa !5
  %26 = and i32 %23, 1
  tail call void @setNode(ptr noundef %0, i16 noundef zeroext %25, i32 noundef %26)
  %27 = lshr i32 %3, 6
  %28 = getelementptr inbounds i8, ptr %2, i64 12
  %29 = load i16, ptr %28, align 2, !tbaa !5
  %30 = and i32 %27, 1
  tail call void @setNode(ptr noundef %0, i16 noundef zeroext %29, i32 noundef %30)
  %31 = lshr i32 %3, 7
  %32 = getelementptr inbounds i8, ptr %2, i64 14
  %33 = load i16, ptr %32, align 2, !tbaa !5
  %34 = and i32 %31, 1
  tail call void @setNode(ptr noundef %0, i16 noundef zeroext %33, i32 noundef %34)
  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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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