; LLVM IR from PaulBatchelor/sndkit :: graforge (graforge)

; 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.gf_patch = type { ptr, ptr, i32, i32, i32, i32, %struct.gf_pointerlist, %struct.gf_bufferpool, %struct.gf_stack, i32, ptr, i32, ptr, ptr, ptr }
%struct.gf_pointerlist = type { ptr, ptr, i32 }
%struct.gf_bufferpool = type { ptr, i32, i32, i32, i32 }
%struct.gf_stack = type { i32, i32, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @gf_node_compute(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @gf_node_get_next(ptr noundef) #0

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

9:                                                ; preds = %20, %1
  %10 = load i32, ptr %3, align 4, !tbaa !15
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.gf_patch, ptr %11, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !16
  %14 = icmp slt i32 %10, %13
  br i1 %14, label %15, label %23

15:                                               ; preds = %9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call ptr @gf_node_get_next(ptr noundef %16)
  store ptr %17, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gf_node_compute(ptr noundef %18)
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %19, ptr %4, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %15
  %21 = load i32, ptr %3, align 4, !tbaa !15
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %3, align 4, !tbaa !15
  br label %9, !llvm.loop !17

23:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!10 = !{!"gf_patch", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !12, i64 32, !13, i64 56, !14, i64 80, !11, i64 104, !6, i64 112, !11, i64 120, !6, i64 128, !6, i64 136, !6, i64 144}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16}
!13 = !{!"gf_bufferpool", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!14 = !{!"gf_stack", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !11, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"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 @gf_node_compute(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @gf_node_get_next(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @gf_patch_compute(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !14
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.08 = phi i32 [ %7, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.067 = phi ptr [ %6, %.lr.ph ], [ %5, %.lr.ph.preheader ]
  %6 = tail call ptr @gf_node_get_next(ptr noundef %.067)
  tail call void @gf_node_compute(ptr noundef %.067)
  %7 = add nuw nsw i32 %.08, 1
  %8 = load i32, ptr %2, align 8, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %1
  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, !10, i64 16}
!6 = !{!"gf_patch", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !11, i64 32, !12, i64 56, !13, i64 80, !10, i64 104, !7, i64 112, !10, i64 120, !7, i64 128, !7, i64 136, !7, i64 144}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16}
!12 = !{!"gf_bufferpool", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!13 = !{!"gf_stack", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 16}
!14 = !{!6, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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