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

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

@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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6extendci(i8 noundef signext %0, i32 noundef %1) #0 personality ptr @__gxx_personality_v0 {
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i8 %0, ptr %3, align 1, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %9 = load ptr, ptr @last, align 8, !tbaa !10
  store ptr %9, ptr %5, align 8, !tbaa !10
  br label %10

10:                                               ; preds = %27, %2
  %11 = load i32, ptr %4, align 4, !tbaa !8
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100000 x i8], ptr @str, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = sext i8 %14 to i32
  %16 = load i32, ptr %4, align 4, !tbaa !8
  %17 = load ptr, ptr %5, align 8, !tbaa !10
  %18 = getelementptr inbounds %struct.node, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = sub nsw i32 %16, %19
  %21 = sub nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100000 x i8], ptr @str, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %25 = sext i8 %24 to i32
  %26 = icmp ne i32 %15, %25
  br i1 %26, label %27, label %31

27:                                               ; preds = %10
  %28 = load ptr, ptr %5, align 8, !tbaa !10
  %29 = getelementptr inbounds %struct.node, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  store ptr %30, ptr %5, align 8, !tbaa !10
  br label %10, !llvm.loop !15

31:                                               ; preds = %10
  %32 = load ptr, ptr %5, align 8, !tbaa !10
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 0
  %34 = load i8, ptr %3, align 1, !tbaa !5
  %35 = sext i8 %34 to i64
  %36 = getelementptr inbounds [26 x ptr], ptr %33, i64 0, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !10
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %104

39:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %40 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 224) #6
  %41 = load i32, ptr %4, align 4, !tbaa !8
  %42 = load ptr, ptr %5, align 8, !tbaa !10
  %43 = getelementptr inbounds %struct.node, ptr %42, i32 0, i32 3
  %44 = load i32, ptr %43, align 4, !tbaa !12
  %45 = sub nsw i32 %41, %44
  %46 = sub nsw i32 %45, 1
  %47 = load ptr, ptr %5, align 8, !tbaa !10
  %48 = getelementptr inbounds %struct.node, ptr %47, i32 0, i32 3
  %49 = load i32, ptr %48, align 4, !tbaa !12
  %50 = add nsw i32 %49, 2
  invoke void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(224) %40, i32 noundef %46, i32 noundef %50)
          to label %51 unwind label %67

51:                                               ; preds = %39
  store ptr %40, ptr %6, align 8, !tbaa !10
  %52 = load ptr, ptr %6, align 8, !tbaa !10
  %53 = load ptr, ptr %5, align 8, !tbaa !10
  %54 = getelementptr inbounds %struct.node, ptr %53, i32 0, i32 0
  %55 = load i8, ptr %3, align 1, !tbaa !5
  %56 = sext i8 %55 to i64
  %57 = getelementptr inbounds [26 x ptr], ptr %54, i64 0, i64 %56
  store ptr %52, ptr %57, align 8, !tbaa !10
  %58 = load ptr, ptr %5, align 8, !tbaa !10
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !14
  store ptr %60, ptr %5, align 8, !tbaa !10
  %61 = load ptr, ptr %5, align 8, !tbaa !10
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %71

63:                                               ; preds = %51
  %64 = load ptr, ptr @empty, align 8, !tbaa !10
  %65 = load ptr, ptr %6, align 8, !tbaa !10
  %66 = getelementptr inbounds %struct.node, ptr %65, i32 0, i32 1
  store ptr %64, ptr %66, align 8, !tbaa !14
  br label %102

67:                                               ; preds = %39
  %68 = landingpad { ptr, i32 }
          cleanup
  %69 = extractvalue { ptr, i32 } %68, 0
  store ptr %69, ptr %7, align 8
  %70 = extractvalue { ptr, i32 } %68, 1
  store i32 %70, ptr %8, align 4
  call void @_ZdlPvm(ptr noundef %40, i64 noundef 224) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %112

71:                                               ; preds = %51
  br label %72

72:                                               ; preds = %89, %71
  %73 = load i32, ptr %4, align 4, !tbaa !8
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [100000 x i8], ptr @str, i64 0, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !5
  %77 = sext i8 %76 to i32
  %78 = load i32, ptr %4, align 4, !tbaa !8
  %79 = load ptr, ptr %5, align 8, !tbaa !10
  %80 = getelementptr inbounds %struct.node, ptr %79, i32 0, i32 3
  %81 = load i32, ptr %80, align 4, !tbaa !12
  %82 = sub nsw i32 %78, %81
  %83 = sub nsw i32 %82, 1
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [100000 x i8], ptr @str, i64 0, i64 %84
  %86 = load i8, ptr %85, align 1, !tbaa !5
  %87 = sext i8 %86 to i32
  %88 = icmp ne i32 %77, %87
  br i1 %88, label %89, label %93

89:                                               ; preds = %72
  %90 = load ptr, ptr %5, align 8, !tbaa !10
  %91 = getelementptr inbounds %struct.node, ptr %90, i32 0, i32 1
  %92 = load ptr, ptr %91, align 8, !tbaa !14
  store ptr %92, ptr %5, align 8, !tbaa !10
  br label %72, !llvm.loop !17

93:                                               ; preds = %72
  %94 = load ptr, ptr %5, align 8, !tbaa !10
  %95 = getelementptr inbounds %struct.node, ptr %94, i32 0, i32 0
  %96 = load i8, ptr %3, align 1, !tbaa !5
  %97 = sext i8 %96 to i64
  %98 = getelementptr inbounds [26 x ptr], ptr %95, i64 0, i64 %97
  %99 = load ptr, ptr %98, align 8, !tbaa !10
  %100 = load ptr, ptr %6, align 8, !tbaa !10
  %101 = getelementptr inbounds %struct.node, ptr %100, i32 0, i32 1
  store ptr %99, ptr %101, align 8, !tbaa !14
  br label %102

102:                                              ; preds = %93, %63
  %103 = load ptr, ptr %6, align 8, !tbaa !10
  store ptr %103, ptr @last, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %111

104:                                              ; preds = %31
  %105 = load ptr, ptr %5, align 8, !tbaa !10
  %106 = getelementptr inbounds %struct.node, ptr %105, i32 0, i32 0
  %107 = load i8, ptr %3, align 1, !tbaa !5
  %108 = sext i8 %107 to i64
  %109 = getelementptr inbounds [26 x ptr], ptr %106, i64 0, i64 %108
  %110 = load ptr, ptr %109, align 8, !tbaa !10
  store ptr %110, ptr @last, align 8, !tbaa !10
  br label %111

111:                                              ; preds = %104, %102
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void

112:                                              ; preds = %67
  %113 = load ptr, ptr %7, align 8
  %114 = load i32, ptr %8, align 4
  %115 = insertvalue { ptr, i32 } poison, ptr %113, 0
  %116 = insertvalue { ptr, i32 } %115, i32 %114, 1
  resume { ptr, i32 } %116
}

; 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

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 = { nounwind }
attributes #6 = { builtin allocsize(0) }
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 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!13, !9, i64 220}
!13 = !{!"_ZTS4node", !6, i64 0, !11, i64 208, !9, i64 216, !9, i64 220}
!14 = !{!13, !11, i64 208}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !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"

@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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6extendci(i8 noundef signext %0, i32 noundef %1) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %3 = sext i32 %1 to i64
  %4 = getelementptr inbounds [100000 x i8], ptr @str, i64 0, i64 %3
  %5 = load i8, ptr %4, align 1, !tbaa !5
  br label %6

6:                                                ; preds = %6, %2
  %.0.in = phi ptr [ @last, %2 ], [ %14, %6 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %.0, i64 220
  %8 = load i32, ptr %7, align 4, !tbaa !10
  %9 = xor i32 %8, -1
  %10 = add i32 %9, %1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [100000 x i8], ptr @str, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %.not = icmp eq i8 %5, %13
  %14 = getelementptr inbounds i8, ptr %.0, i64 208
  br i1 %.not, label %15, label %6, !llvm.loop !13

15:                                               ; preds = %6
  %16 = sext i8 %0 to i64
  %17 = getelementptr inbounds [26 x ptr], ptr %.0, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !8
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %45

20:                                               ; preds = %15
  %21 = tail call noalias noundef nonnull dereferenceable(224) ptr @_Znwm(i64 noundef 224) #3
  %22 = add nsw i32 %8, 2
  tail call void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(224) %21, i32 noundef %10, i32 noundef %22)
  store ptr %21, ptr %17, align 8, !tbaa !8
  %23 = load ptr, ptr %14, align 8, !tbaa !15
  %24 = icmp eq ptr %23, null
  br i1 %24, label %.sink.split, label %.preheader

.preheader:                                       ; preds = %20
  %25 = load i8, ptr %4, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %23, i64 220
  %27 = load i32, ptr %26, align 4, !tbaa !10
  %28 = xor i32 %27, -1
  %29 = add i32 %28, %1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100000 x i8], ptr @str, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %.not2629 = icmp eq i8 %25, %32
  br i1 %.not2629, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.130 = phi ptr [ %34, %.lr.ph ], [ %23, %.preheader ]
  %33 = getelementptr inbounds i8, ptr %.130, i64 208
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = getelementptr inbounds i8, ptr %34, i64 220
  %36 = load i32, ptr %35, align 4, !tbaa !10
  %37 = xor i32 %36, -1
  %38 = add i32 %37, %1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100000 x i8], ptr @str, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !5
  %.not26 = icmp eq i8 %25, %41
  br i1 %.not26, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.1.lcssa = phi ptr [ %23, %.preheader ], [ %34, %.lr.ph ]
  %42 = getelementptr inbounds [26 x ptr], ptr %.1.lcssa, i64 0, i64 %16
  br label %.sink.split

.sink.split:                                      ; preds = %20, %._crit_edge
  %empty.sink = phi ptr [ %42, %._crit_edge ], [ @empty, %20 ]
  %43 = load ptr, ptr %empty.sink, align 8, !tbaa !8
  %44 = getelementptr inbounds i8, ptr %21, i64 208
  store ptr %43, ptr %44, align 8, !tbaa !15
  br label %45

45:                                               ; preds = %.sink.split, %15
  %storemerge = phi ptr [ %18, %15 ], [ %21, %.sink.split ]
  store ptr %storemerge, ptr @last, align 8, !tbaa !8
  ret void
}

; 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(...)

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, !12, i64 220}
!11 = !{!"_ZTS4node", !6, i64 0, !9, i64 208, !12, i64 216, !12, i64 220}
!12 = !{!"int", !6, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!11, !9, i64 208}
!16 = distinct !{!16, !14}


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