; LLVM IR from 6leetcode/6leetcode :: questions/Algorithms/0005. Longest Palindromic Substring (Testing)

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

; Function Attrs: nounwind uwtable
define dso_local ptr @longestPalindrome(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !9
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %19

15:                                               ; preds = %1
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %21, label %19

19:                                               ; preds = %15, %1
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %20, ptr %2, align 8
  store i32 1, ptr %11, align 4
  br label %124

21:                                               ; preds = %15
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = call i64 @strlen(ptr noundef %22) #6
  %24 = trunc i64 %23 to i32
  store i32 %24, ptr %4, align 4, !tbaa !9
  store i32 0, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !9
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %104, %21
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = sub nsw i32 %27, %28
  %30 = mul nsw i32 %29, 2
  %31 = icmp slt i32 %26, %30
  br i1 %31, label %32, label %107

32:                                               ; preds = %25
  br label %33

33:                                               ; preds = %55, %32
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %38, label %53

38:                                               ; preds = %33
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %39, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = sext i8 %43 to i32
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %45, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !11
  %51 = sext i8 %50 to i32
  %52 = icmp eq i32 %44, %51
  br label %53

53:                                               ; preds = %38, %33
  %54 = phi i1 [ false, %33 ], [ %52, %38 ]
  br i1 %54, label %55, label %58

55:                                               ; preds = %53
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %6, align 4, !tbaa !9
  br label %33, !llvm.loop !12

58:                                               ; preds = %53
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %7, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %87, %58
  %62 = load i32, ptr %5, align 4, !tbaa !9
  %63 = icmp sgt i32 %62, 0
  br i1 %63, label %64, label %85

64:                                               ; preds = %61
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  %67 = load i32, ptr %4, align 4, !tbaa !9
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %69, label %85

69:                                               ; preds = %64
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = load i32, ptr %5, align 4, !tbaa !9
  %72 = sub nsw i32 %71, 1
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %70, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !11
  %76 = sext i8 %75 to i32
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = load i32, ptr %6, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i8, ptr %77, i64 %80
  %82 = load i8, ptr %81, align 1, !tbaa !11
  %83 = sext i8 %82 to i32
  %84 = icmp eq i32 %76, %83
  br label %85

85:                                               ; preds = %69, %64, %61
  %86 = phi i1 [ false, %64 ], [ false, %61 ], [ %84, %69 ]
  br i1 %86, label %87, label %92

87:                                               ; preds = %85
  %88 = load i32, ptr %5, align 4, !tbaa !9
  %89 = add nsw i32 %88, -1
  store i32 %89, ptr %5, align 4, !tbaa !9
  %90 = load i32, ptr %6, align 4, !tbaa !9
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %6, align 4, !tbaa !9
  br label %61, !llvm.loop !14

92:                                               ; preds = %85
  %93 = load i32, ptr %6, align 4, !tbaa !9
  %94 = load i32, ptr %5, align 4, !tbaa !9
  %95 = sub nsw i32 %93, %94
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %8, align 4, !tbaa !9
  %97 = load i32, ptr %10, align 4, !tbaa !9
  %98 = load i32, ptr %8, align 4, !tbaa !9
  %99 = icmp slt i32 %97, %98
  br i1 %99, label %100, label %103

100:                                              ; preds = %92
  %101 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %101, ptr %10, align 4, !tbaa !9
  %102 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %102, ptr %9, align 4, !tbaa !9
  br label %103

103:                                              ; preds = %100, %92
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %105, ptr %5, align 4, !tbaa !9
  %106 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %106, ptr %6, align 4, !tbaa !9
  br label %25, !llvm.loop !15

107:                                              ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %108 = load i32, ptr %4, align 4, !tbaa !9
  %109 = add nsw i32 %108, 1
  %110 = sext i32 %109 to i64
  %111 = call noalias ptr @malloc(i64 noundef %110) #7
  store ptr %111, ptr %12, align 8, !tbaa !5
  %112 = load ptr, ptr %12, align 8, !tbaa !5
  %113 = load ptr, ptr %3, align 8, !tbaa !5
  %114 = load i32, ptr %9, align 4, !tbaa !9
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds i8, ptr %113, i64 %115
  %117 = load i32, ptr %10, align 4, !tbaa !9
  %118 = sext i32 %117 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %112, ptr align 1 %116, i64 %118, i1 false)
  %119 = load ptr, ptr %12, align 8, !tbaa !5
  %120 = load i32, ptr %10, align 4, !tbaa !9
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds i8, ptr %119, i64 %121
  store i8 0, ptr %122, align 1, !tbaa !11
  %123 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %123, ptr %2, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %124

124:                                              ; preds = %107, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %125 = load ptr, ptr %2, align 8
  ret ptr %125
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

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 willreturn memory(read) "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 = { nounwind 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { nounwind 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


; 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: nofree nounwind uwtable
define dso_local noundef ptr @longestPalindrome(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %50, label %2

2:                                                ; preds = %1
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %.not54 = icmp eq i8 %3, 0
  br i1 %.not54, label %50, label %4

4:                                                ; preds = %2
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #5
  %6 = trunc i64 %5 to i32
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.preheader.lr.ph, label %._crit_edge

.preheader.lr.ph:                                 ; preds = %4
  %invariant.gep = getelementptr i8, ptr %0, i64 -1
  %8 = and i64 %5, 2147483647
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.critedge2
  %.04268 = phi i32 [ 0, %.preheader.lr.ph ], [ %spec.select56, %.critedge2 ]
  %.04367 = phi i32 [ 0, %.preheader.lr.ph ], [ %spec.select, %.critedge2 ]
  %.04566 = phi i32 [ 0, %.preheader.lr.ph ], [ %.lcssa, %.critedge2 ]
  %9 = sext i32 %.04566 to i64
  %10 = add nsw i32 %.04566, 1
  %smax = tail call i32 @llvm.smax.i32(i32 %10, i32 %6)
  %11 = add nsw i32 %smax, -1
  br label %12

12:                                               ; preds = %.preheader, %14
  %indvars.iv = phi i64 [ %9, %.preheader ], [ %indvars.iv.next, %14 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %13 = icmp slt i64 %indvars.iv.next, %8
  br i1 %13, label %14, label %.critedge

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = icmp eq i8 %16, %18
  br i1 %19, label %12, label %.critedge.split.loop.exit76, !llvm.loop !8

.critedge.split.loop.exit76:                      ; preds = %14
  %20 = trunc nsw i64 %indvars.iv to i32
  %21 = trunc nsw i64 %indvars.iv.next to i32
  br label %.critedge

.critedge:                                        ; preds = %12, %.critedge.split.loop.exit76
  %.149.lcssa = phi i32 [ %20, %.critedge.split.loop.exit76 ], [ %11, %12 ]
  %.lcssa = phi i32 [ %21, %.critedge.split.loop.exit76 ], [ %smax, %12 ]
  %22 = icmp sgt i32 %.04566, 0
  br i1 %22, label %.lr.ph.preheader, label %.critedge2

.lr.ph.preheader:                                 ; preds = %.critedge
  %23 = sext i32 %.149.lcssa to i64
  %24 = add i32 %.149.lcssa, %.04566
  %25 = add i32 %.149.lcssa, 1
  %smax74 = tail call i32 @llvm.smax.i32(i32 %25, i32 %6)
  %26 = add nsw i32 %smax74, -1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %34
  %indvars.iv72 = phi i64 [ %23, %.lr.ph.preheader ], [ %indvars.iv.next73, %34 ]
  %.14658 = phi i32 [ %.04566, %.lr.ph.preheader ], [ %35, %34 ]
  %indvars.iv.next73 = add nsw i64 %indvars.iv72, 1
  %27 = icmp slt i64 %indvars.iv.next73, %8
  br i1 %27, label %28, label %.critedge2

28:                                               ; preds = %.lr.ph
  %29 = zext nneg i32 %.14658 to i64
  %gep = getelementptr i8, ptr %invariant.gep, i64 %29
  %30 = load i8, ptr %gep, align 1, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next73
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = icmp eq i8 %30, %32
  br i1 %33, label %34, label %.critedge2.loopexit.split.loop.exit82

34:                                               ; preds = %28
  %35 = add nsw i32 %.14658, -1
  %36 = icmp sgt i32 %.14658, 1
  br i1 %36, label %.lr.ph, label %.critedge2, !llvm.loop !10

.critedge2.loopexit.split.loop.exit82:            ; preds = %28
  %37 = trunc nsw i64 %indvars.iv72 to i32
  br label %.critedge2

.critedge2:                                       ; preds = %.lr.ph, %34, %.critedge2.loopexit.split.loop.exit82, %.critedge
  %.2.lcssa = phi i32 [ %.149.lcssa, %.critedge ], [ %37, %.critedge2.loopexit.split.loop.exit82 ], [ %26, %.lr.ph ], [ %24, %34 ]
  %.146.lcssa = phi i32 [ %.04566, %.critedge ], [ %.14658, %.critedge2.loopexit.split.loop.exit82 ], [ %.14658, %.lr.ph ], [ 0, %34 ]
  %38 = sub nsw i32 %.2.lcssa, %.146.lcssa
  %.not55 = icmp sgt i32 %.04268, %38
  %39 = add nsw i32 %38, 1
  %spec.select = select i1 %.not55, i32 %.04367, i32 %.146.lcssa
  %spec.select56 = select i1 %.not55, i32 %.04268, i32 %39
  %40 = sub nsw i32 %6, %.lcssa
  %41 = shl nsw i32 %40, 1
  %42 = icmp slt i32 %spec.select56, %41
  br i1 %42, label %.preheader, label %._crit_edge.loopexit, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %.critedge2
  %43 = sext i32 %spec.select to i64
  %44 = sext i32 %spec.select56 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %.043.lcssa = phi i64 [ 0, %4 ], [ %43, %._crit_edge.loopexit ]
  %.042.lcssa = phi i64 [ 0, %4 ], [ %44, %._crit_edge.loopexit ]
  %45 = shl i64 %5, 32
  %sext = add i64 %45, 4294967296
  %46 = ashr exact i64 %sext, 32
  %47 = tail call noalias ptr @malloc(i64 noundef %46) #6
  %48 = getelementptr inbounds i8, ptr %0, i64 %.043.lcssa
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %47, ptr nonnull align 1 %48, i64 %.042.lcssa, i1 false)
  %49 = getelementptr inbounds i8, ptr %47, i64 %.042.lcssa
  store i8 0, ptr %49, align 1, !tbaa !5
  br label %50

50:                                               ; preds = %1, %2, %._crit_edge
  %.0 = phi ptr [ %47, %._crit_edge ], [ %0, %2 ], [ null, %1 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

attributes #0 = { nofree 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 nofree nounwind willreturn memory(argmem: read) "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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { nounwind 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/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = distinct !{!11, !9}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass