; 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_init(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @gf_node_set_id(ptr noundef, i32 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: nounwind uwtable
declare dso_local i32 @gf_memory_alloc(ptr noundef, i64 noundef, ptr noundef) #0

; 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 void @gf_node_set_patch(ptr noundef, ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gf_patch_new_node(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, 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 ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store i32 9, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %62

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.gf_patch, ptr %13, i32 0, i32 11
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %21

17:                                               ; preds = %12
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.gf_patch, ptr %18, i32 0, i32 11
  %20 = load i32, ptr %19, align 8, !tbaa !9
  store i32 %20, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %62

21:                                               ; preds = %12
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call i32 @gf_memory_alloc(ptr noundef %22, i64 noundef 72, ptr noundef %6)
  store i32 %23, ptr %7, align 4, !tbaa !15
  %24 = load i32, ptr %7, align 4, !tbaa !15
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %21
  %27 = load i32, ptr %7, align 4, !tbaa !15
  store i32 %27, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %62

28:                                               ; preds = %21
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.gf_patch, ptr %30, i32 0, i32 3
  %32 = load i32, ptr %31, align 4, !tbaa !16
  call void @gf_node_init(ptr noundef %29, i32 noundef %32)
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.gf_patch, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !17
  call void @gf_node_set_id(ptr noundef %33, i32 noundef %36)
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gf_node_set_patch(ptr noundef %37, ptr noundef %38)
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.gf_patch, ptr %39, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !17
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %47

43:                                               ; preds = %28
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.gf_patch, ptr %45, i32 0, i32 0
  store ptr %44, ptr %46, align 8, !tbaa !18
  br label %52

47:                                               ; preds = %28
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.gf_patch, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !19
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  call void @gf_node_set_next(ptr noundef %50, ptr noundef %51)
  br label %52

52:                                               ; preds = %47, %43
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.gf_patch, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !17
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %54, align 8, !tbaa !17
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.gf_patch, ptr %58, i32 0, i32 1
  store ptr %57, ptr %59, align 8, !tbaa !19
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %60, ptr %61, align 8, !tbaa !5
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %62

62:                                               ; preds = %52, %26, %17, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %63 = load i32, ptr %3, align 4
  ret i32 %63
}

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, !11, i64 120}
!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 20}
!17 = !{!10, !11, i64 16}
!18 = !{!10, !6, i64 0}
!19 = !{!10, !6, i64 8}


; 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_init(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @gf_node_set_id(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress 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 void @gf_node_set_patch(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gf_patch_new_node(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  %4 = icmp eq ptr %0, null
  br i1 %4, label %31, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 120
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %31

8:                                                ; preds = %5
  %9 = call i32 @gf_memory_alloc(ptr noundef nonnull %0, i64 noundef 72, ptr noundef nonnull %3)
  %.not18 = icmp eq i32 %9, 0
  br i1 %.not18, label %10, label %31

10:                                               ; preds = %8
  %11 = load ptr, ptr %3, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %0, i64 20
  %13 = load i32, ptr %12, align 4, !tbaa !15
  call void @gf_node_init(ptr noundef %11, i32 noundef %13)
  %14 = load ptr, ptr %3, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !16
  call void @gf_node_set_id(ptr noundef %14, i32 noundef %16)
  %17 = load ptr, ptr %3, align 8, !tbaa !14
  call void @gf_node_set_patch(ptr noundef %17, ptr noundef nonnull %0)
  %18 = load i32, ptr %15, align 8, !tbaa !16
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %10
  %21 = load ptr, ptr %3, align 8, !tbaa !14
  store ptr %21, ptr %0, align 8, !tbaa !17
  br label %27

22:                                               ; preds = %10
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !18
  %25 = load ptr, ptr %3, align 8, !tbaa !14
  call void @gf_node_set_next(ptr noundef %24, ptr noundef %25)
  %.pre = load i32, ptr %15, align 8, !tbaa !16
  %.pre19 = load ptr, ptr %3, align 8, !tbaa !14
  %26 = add nsw i32 %.pre, 1
  br label %27

27:                                               ; preds = %22, %20
  %28 = phi ptr [ %.pre19, %22 ], [ %21, %20 ]
  %29 = phi i32 [ %26, %22 ], [ 1, %20 ]
  store i32 %29, ptr %15, align 8, !tbaa !16
  %30 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %28, ptr %30, align 8, !tbaa !18
  store ptr %28, ptr %1, align 8, !tbaa !14
  br label %31

31:                                               ; preds = %8, %5, %2, %27
  %.0 = phi i32 [ 0, %27 ], [ 9, %2 ], [ %7, %5 ], [ %9, %8 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  ret i32 %.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" }
attributes #1 = { mustprogress 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, !10, i64 120}
!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 = !{!7, !7, i64 0}
!15 = !{!6, !10, i64 20}
!16 = !{!6, !10, i64 16}
!17 = !{!6, !7, i64 0}
!18 = !{!6, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass