; LLVM IR from yanglr/leetcode-ac :: cpp-leetcode (leetcode117-populating-next-right-pointers-in-each-node-ii_level_order)

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

%class.Solution = type { i8 }
%class.Node = type { i32, ptr, ptr, ptr }

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca %class.Solution, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %7 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #7
  invoke void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %7, i32 noundef 1)
          to label %8 unwind label %77

8:                                                ; preds = %0
  store ptr %7, ptr %3, align 8, !tbaa !5
  %9 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #7
  invoke void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %9, i32 noundef 2)
          to label %10 unwind label %81

10:                                               ; preds = %8
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %class.Node, ptr %11, i32 0, i32 1
  store ptr %9, ptr %12, align 8, !tbaa !9
  %13 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #7
  invoke void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %13, i32 noundef 3)
          to label %14 unwind label %85

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %class.Node, ptr %15, i32 0, i32 2
  store ptr %13, ptr %16, align 8, !tbaa !12
  %17 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #7
  invoke void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %17, i32 noundef 4)
          to label %18 unwind label %89

18:                                               ; preds = %14
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %class.Node, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %class.Node, ptr %21, i32 0, i32 1
  store ptr %17, ptr %22, align 8, !tbaa !9
  %23 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #7
  invoke void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %23, i32 noundef 5)
          to label %24 unwind label %93

24:                                               ; preds = %18
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.Node, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %class.Node, ptr %27, i32 0, i32 2
  store ptr %23, ptr %28, align 8, !tbaa !12
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %class.Node, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = getelementptr inbounds %class.Node, ptr %31, i32 0, i32 1
  store ptr null, ptr %32, align 8, !tbaa !9
  %33 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #7
  invoke void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %33, i32 noundef 7)
          to label %34 unwind label %97

34:                                               ; preds = %24
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %class.Node, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  %38 = getelementptr inbounds %class.Node, ptr %37, i32 0, i32 2
  store ptr %33, ptr %38, align 8, !tbaa !12
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %class.Node, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = getelementptr inbounds %class.Node, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = getelementptr inbounds %class.Node, ptr %43, i32 0, i32 1
  store ptr null, ptr %44, align 8, !tbaa !9
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %class.Node, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = getelementptr inbounds %class.Node, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = getelementptr inbounds %class.Node, ptr %49, i32 0, i32 2
  store ptr null, ptr %50, align 8, !tbaa !12
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %class.Node, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = getelementptr inbounds %class.Node, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !12
  %56 = getelementptr inbounds %class.Node, ptr %55, i32 0, i32 1
  store ptr null, ptr %56, align 8, !tbaa !9
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %class.Node, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  %60 = getelementptr inbounds %class.Node, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !12
  %62 = getelementptr inbounds %class.Node, ptr %61, i32 0, i32 2
  store ptr null, ptr %62, align 8, !tbaa !12
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %class.Node, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !12
  %66 = getelementptr inbounds %class.Node, ptr %65, i32 0, i32 2
  %67 = load ptr, ptr %66, align 8, !tbaa !12
  %68 = getelementptr inbounds %class.Node, ptr %67, i32 0, i32 1
  store ptr null, ptr %68, align 8, !tbaa !9
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %class.Node, ptr %69, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !12
  %72 = getelementptr inbounds %class.Node, ptr %71, i32 0, i32 2
  %73 = load ptr, ptr %72, align 8, !tbaa !12
  %74 = getelementptr inbounds %class.Node, ptr %73, i32 0, i32 2
  store ptr null, ptr %74, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = call noundef ptr @_ZN8Solution7connectEP4Node(ptr noundef nonnull align 1 dereferenceable(1) %2, ptr noundef %75)
  store ptr %76, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #6
  ret i32 0

77:                                               ; preds = %0
  %78 = landingpad { ptr, i32 }
          cleanup
  %79 = extractvalue { ptr, i32 } %78, 0
  store ptr %79, ptr %4, align 8
  %80 = extractvalue { ptr, i32 } %78, 1
  store i32 %80, ptr %5, align 4
  call void @_ZdlPvm(ptr noundef %7, i64 noundef 32) #8
  br label %101

81:                                               ; preds = %8
  %82 = landingpad { ptr, i32 }
          cleanup
  %83 = extractvalue { ptr, i32 } %82, 0
  store ptr %83, ptr %4, align 8
  %84 = extractvalue { ptr, i32 } %82, 1
  store i32 %84, ptr %5, align 4
  call void @_ZdlPvm(ptr noundef %9, i64 noundef 32) #8
  br label %101

85:                                               ; preds = %10
  %86 = landingpad { ptr, i32 }
          cleanup
  %87 = extractvalue { ptr, i32 } %86, 0
  store ptr %87, ptr %4, align 8
  %88 = extractvalue { ptr, i32 } %86, 1
  store i32 %88, ptr %5, align 4
  call void @_ZdlPvm(ptr noundef %13, i64 noundef 32) #8
  br label %101

89:                                               ; preds = %14
  %90 = landingpad { ptr, i32 }
          cleanup
  %91 = extractvalue { ptr, i32 } %90, 0
  store ptr %91, ptr %4, align 8
  %92 = extractvalue { ptr, i32 } %90, 1
  store i32 %92, ptr %5, align 4
  call void @_ZdlPvm(ptr noundef %17, i64 noundef 32) #8
  br label %101

93:                                               ; preds = %18
  %94 = landingpad { ptr, i32 }
          cleanup
  %95 = extractvalue { ptr, i32 } %94, 0
  store ptr %95, ptr %4, align 8
  %96 = extractvalue { ptr, i32 } %94, 1
  store i32 %96, ptr %5, align 4
  call void @_ZdlPvm(ptr noundef %23, i64 noundef 32) #8
  br label %101

97:                                               ; preds = %24
  %98 = landingpad { ptr, i32 }
          cleanup
  %99 = extractvalue { ptr, i32 } %98, 0
  store ptr %99, ptr %4, align 8
  %100 = extractvalue { ptr, i32 } %98, 1
  store i32 %100, ptr %5, align 4
  call void @_ZdlPvm(ptr noundef %33, i64 noundef 32) #8
  br label %101

101:                                              ; preds = %97, %93, %89, %85, %81, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #6
  br label %102

102:                                              ; preds = %101
  %103 = load ptr, ptr %4, align 8
  %104 = load i32, ptr %5, align 4
  %105 = insertvalue { ptr, i32 } poison, ptr %103, 0
  %106 = insertvalue { ptr, i32 } %105, i32 %104, 1
  resume { ptr, i32 } %106
}

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) unnamed_addr #3 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN8Solution7connectEP4Node(ptr noundef nonnull align 1 dereferenceable(1), ptr noundef) #5 align 2

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

attributes #0 = { mustprogress norecurse 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 = { nobuiltin allocsize(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 = { mustprogress 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 #4 = { nobuiltin nounwind "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 #5 = { mustprogress 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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS4Node", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}


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

%class.Solution = type { i8 }

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca %class.Solution, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #6
  %2 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #7
  tail call void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %2, i32 noundef 1)
  %3 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #7
  tail call void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %3, i32 noundef 2)
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %3, ptr %4, align 8, !tbaa !5
  %5 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #7
  tail call void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %5, i32 noundef 3)
  %6 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %5, ptr %6, align 8, !tbaa !11
  %7 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #7
  tail call void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %7, i32 noundef 4)
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %7, ptr %9, align 8, !tbaa !5
  %10 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #7
  tail call void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %10, i32 noundef 5)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  store ptr %10, ptr %12, align 8, !tbaa !11
  %13 = load ptr, ptr %6, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr null, ptr %14, align 8, !tbaa !5
  %15 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #7
  tail call void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %15, i32 noundef 7)
  %16 = load ptr, ptr %6, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  store ptr %15, ptr %17, align 8, !tbaa !11
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 8
  store ptr null, ptr %21, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  store ptr null, ptr %25, align 8, !tbaa !11
  %26 = getelementptr inbounds i8, ptr %22, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  store ptr null, ptr %28, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = getelementptr inbounds i8, ptr %31, i64 16
  store ptr null, ptr %32, align 8, !tbaa !11
  %33 = load ptr, ptr %6, align 8, !tbaa !11
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds i8, ptr %35, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %36, i8 0, i64 16, i1 false)
  %37 = call noundef ptr @_ZN8Solution7connectEP4Node(ptr noundef nonnull align 1 dereferenceable(1) %1, ptr noundef nonnull %2)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #6
  ret i32 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) unnamed_addr #3 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN8Solution7connectEP4Node(ptr noundef nonnull align 1 dereferenceable(1), ptr noundef) local_unnamed_addr #4 align 2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

attributes #0 = { mustprogress norecurse 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 = { nobuiltin allocsize(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 = { mustprogress 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 #4 = { mustprogress 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }

!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 8}
!6 = !{!"_ZTS4Node", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass