; LLVM IR from Dev-XYS/Algorithms :: Palindromic-Tree.ll (Z5buildv)

; 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.node = type { [26 x ptr], ptr, i32, i32 }

@root = external dso_local global ptr, align 8
@empty = external dso_local global ptr, align 8
@last = external dso_local global ptr, align 8
@str = external dso_local global [100000 x i8], align 16
@len = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6extendci(i8 noundef signext, 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(224), i32 noundef, 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildv() #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i8 -1, ptr @str, align 16, !tbaa !5
  %4 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 224) #5
  invoke void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(224) %4, i32 noundef 0, i32 noundef -1)
          to label %5 unwind label %17

5:                                                ; preds = %0
  store ptr %4, ptr @root, align 8, !tbaa !8
  %6 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 224) #5
  invoke void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(224) %6, i32 noundef 0, i32 noundef 0)
          to label %7 unwind label %21

7:                                                ; preds = %5
  store ptr %6, ptr @empty, align 8, !tbaa !8
  %8 = load ptr, ptr @root, align 8, !tbaa !8
  %9 = load ptr, ptr @empty, align 8, !tbaa !8
  %10 = getelementptr inbounds %struct.node, ptr %9, i32 0, i32 1
  store ptr %8, ptr %10, align 8, !tbaa !10
  %11 = load ptr, ptr @empty, align 8, !tbaa !8
  store ptr %11, ptr @last, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 1, ptr %3, align 4, !tbaa !13
  br label %12

12:                                               ; preds = %34, %7
  %13 = load i32, ptr %3, align 4, !tbaa !13
  %14 = load i32, ptr @len, align 4, !tbaa !13
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %25, label %16

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

17:                                               ; preds = %0
  %18 = landingpad { ptr, i32 }
          cleanup
  %19 = extractvalue { ptr, i32 } %18, 0
  store ptr %19, ptr %1, align 8
  %20 = extractvalue { ptr, i32 } %18, 1
  store i32 %20, ptr %2, align 4
  call void @_ZdlPvm(ptr noundef %4, i64 noundef 224) #7
  br label %38

21:                                               ; preds = %5
  %22 = landingpad { ptr, i32 }
          cleanup
  %23 = extractvalue { ptr, i32 } %22, 0
  store ptr %23, ptr %1, align 8
  %24 = extractvalue { ptr, i32 } %22, 1
  store i32 %24, ptr %2, align 4
  call void @_ZdlPvm(ptr noundef %6, i64 noundef 224) #7
  br label %38

25:                                               ; preds = %12
  %26 = load i32, ptr %3, align 4, !tbaa !13
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100000 x i8], ptr @str, i64 0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = sext i8 %29 to i32
  %31 = sub nsw i32 %30, 97
  %32 = trunc i32 %31 to i8
  %33 = load i32, ptr %3, align 4, !tbaa !13
  call void @_Z6extendci(i8 noundef signext %32, i32 noundef %33)
  br label %34

34:                                               ; preds = %25
  %35 = load i32, ptr %3, align 4, !tbaa !13
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %3, align 4, !tbaa !13
  br label %12, !llvm.loop !14

37:                                               ; preds = %16
  ret void

38:                                               ; preds = %21, %17
  %39 = load ptr, ptr %1, align 8
  %40 = load i32, ptr %2, align 4
  %41 = insertvalue { ptr, i32 } poison, ptr %39, 0
  %42 = insertvalue { ptr, i32 } %41, i32 %40, 1
  resume { ptr, i32 } %42
}

attributes #0 = { 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 #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 = { builtin allocsize(0) }
attributes #6 = { nounwind }
attributes #7 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !9, i64 208}
!11 = !{!"_ZTS4node", !6, i64 0, !9, i64 208, !12, i64 216, !12, i64 220}
!12 = !{!"int", !6, i64 0}
!13 = !{!12, !12, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@root = external dso_local local_unnamed_addr global ptr, align 8
@empty = external dso_local local_unnamed_addr global ptr, align 8
@last = external dso_local local_unnamed_addr global ptr, align 8
@str = external dso_local local_unnamed_addr global [100000 x i8], align 16
@len = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6extendci(i8 noundef signext, i32 noundef) local_unnamed_addr #0

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

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildv() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  store i8 -1, ptr @str, align 16, !tbaa !5
  %1 = tail call noalias noundef nonnull dereferenceable(224) ptr @_Znwm(i64 noundef 224) #3
  tail call void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(224) %1, i32 noundef 0, i32 noundef -1)
  store ptr %1, ptr @root, align 8, !tbaa !8
  %2 = tail call noalias noundef nonnull dereferenceable(224) ptr @_Znwm(i64 noundef 224) #3
  tail call void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(224) %2, i32 noundef 0, i32 noundef 0)
  store ptr %2, ptr @empty, align 8, !tbaa !8
  %3 = load ptr, ptr @root, align 8, !tbaa !8
  %4 = getelementptr inbounds i8, ptr %2, i64 208
  store ptr %3, ptr %4, align 8, !tbaa !10
  store ptr %2, ptr @last, align 8, !tbaa !8
  %5 = load i32, ptr @len, align 4, !tbaa !13
  %.not4 = icmp slt i32 %5, 1
  br i1 %.not4, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  ret void

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %6 = getelementptr inbounds [100000 x i8], ptr @str, i64 0, i64 %indvars.iv
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = add i8 %7, -97
  %9 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_Z6extendci(i8 noundef signext %8, i32 noundef %9)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr @len, align 4, !tbaa !13
  %11 = sext i32 %10 to i64
  %.not.not = icmp slt i64 %indvars.iv, %11
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

attributes #0 = { 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 #1 = { 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 #2 = { 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 #3 = { 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !9, i64 208}
!11 = !{!"_ZTS4node", !6, i64 0, !9, i64 208, !12, i64 216, !12, i64 220}
!12 = !{!"int", !6, i64 0}
!13 = !{!12, !12, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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