; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (409)

; 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 i32 @longestPalindrome(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [58 x i32], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 232, ptr %3) #3
  call void @llvm.memset.p0.i64(ptr align 16 %3, i8 0, i64 232, i1 false)
  br label %8

8:                                                ; preds = %12, %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = icmp ne i8 %10, 0
  br i1 %11, label %12, label %22

12:                                               ; preds = %8
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i32 1
  store ptr %14, ptr %2, align 8, !tbaa !5
  %15 = load i8, ptr %13, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = sub nsw i32 %16, 65
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [58 x i32], ptr %3, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !10
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %19, align 4, !tbaa !10
  br label %8, !llvm.loop !12

22:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !10
  br label %23

23:                                               ; preds = %42, %22
  %24 = load i32, ptr %6, align 4, !tbaa !10
  %25 = icmp slt i32 %24, 58
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %28 = load i32, ptr %6, align 4, !tbaa !10
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [58 x i32], ptr %3, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !10
  store i32 %31, ptr %7, align 4, !tbaa !10
  %32 = load i32, ptr %7, align 4, !tbaa !10
  %33 = and i32 %32, 1
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %27
  store i32 1, ptr %5, align 4, !tbaa !10
  %36 = load i32, ptr %4, align 4, !tbaa !10
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr %4, align 4, !tbaa !10
  br label %38

38:                                               ; preds = %35, %27
  %39 = load i32, ptr %7, align 4, !tbaa !10
  %40 = load i32, ptr %4, align 4, !tbaa !10
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr %4, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %42

42:                                               ; preds = %38
  %43 = load i32, ptr %6, align 4, !tbaa !10
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %6, align 4, !tbaa !10
  br label %23, !llvm.loop !14

45:                                               ; preds = %26
  %46 = load i32, ptr %4, align 4, !tbaa !10
  %47 = load i32, ptr %5, align 4, !tbaa !10
  %48 = add nsw i32 %46, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 232, ptr %3) #3
  ret i32 %48
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.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) #2

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !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 norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @longestPalindrome(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca [58 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 232, ptr nonnull %2) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(232) %2, i8 0, i64 232, i1 false)
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %.not17 = icmp eq i8 %3, 0
  br i1 %.not17, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %4 = phi i8 [ %11, %.lr.ph ], [ %3, %1 ]
  %.018 = phi ptr [ %5, %.lr.ph ], [ %0, %1 ]
  %5 = getelementptr inbounds i8, ptr %.018, i64 1
  %6 = sext i8 %4 to i64
  %7 = add nsw i64 %6, -65
  %8 = getelementptr inbounds [58 x i32], ptr %2, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !8
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %8, align 4, !tbaa !8
  %11 = load i8, ptr %5, align 1, !tbaa !5
  %.not = icmp eq i8 %11, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !10

.loopexit:                                        ; preds = %.lr.ph, %1
  %12 = getelementptr inbounds i8, ptr %2, i64 208
  %wide.load26.6 = load <4 x i32>, ptr %12, align 16, !tbaa !8
  %13 = getelementptr inbounds i8, ptr %2, i64 176
  %wide.load26.5 = load <4 x i32>, ptr %13, align 16, !tbaa !8
  %14 = getelementptr inbounds i8, ptr %2, i64 144
  %wide.load26.4 = load <4 x i32>, ptr %14, align 16, !tbaa !8
  %15 = getelementptr inbounds i8, ptr %2, i64 112
  %wide.load26.3 = load <4 x i32>, ptr %15, align 16, !tbaa !8
  %16 = getelementptr inbounds i8, ptr %2, i64 80
  %wide.load26.2 = load <4 x i32>, ptr %16, align 16, !tbaa !8
  %17 = getelementptr inbounds i8, ptr %2, i64 48
  %wide.load26.1 = load <4 x i32>, ptr %17, align 16, !tbaa !8
  %18 = getelementptr inbounds i8, ptr %2, i64 16
  %wide.load26 = load <4 x i32>, ptr %18, align 16, !tbaa !8
  %19 = trunc <4 x i32> %wide.load26 to <4 x i1>
  %20 = sext <4 x i1> %19 to <4 x i32>
  %21 = add <4 x i32> %wide.load26, %20
  %22 = add <4 x i32> %wide.load26.1, %21
  %23 = trunc <4 x i32> %wide.load26.1 to <4 x i1>
  %24 = sext <4 x i1> %23 to <4 x i32>
  %25 = add <4 x i32> %22, %24
  %26 = add <4 x i32> %wide.load26.2, %25
  %27 = trunc <4 x i32> %wide.load26.2 to <4 x i1>
  %28 = sext <4 x i1> %27 to <4 x i32>
  %29 = add <4 x i32> %26, %28
  %30 = add <4 x i32> %wide.load26.3, %29
  %31 = trunc <4 x i32> %wide.load26.3 to <4 x i1>
  %32 = sext <4 x i1> %31 to <4 x i32>
  %33 = add <4 x i32> %30, %32
  %34 = add <4 x i32> %wide.load26.4, %33
  %35 = trunc <4 x i32> %wide.load26.4 to <4 x i1>
  %36 = sext <4 x i1> %35 to <4 x i32>
  %37 = add <4 x i32> %34, %36
  %38 = add <4 x i32> %wide.load26.5, %37
  %39 = trunc <4 x i32> %wide.load26.5 to <4 x i1>
  %40 = sext <4 x i1> %39 to <4 x i32>
  %41 = add <4 x i32> %38, %40
  %42 = add <4 x i32> %wide.load26.6, %41
  %43 = trunc <4 x i32> %wide.load26.6 to <4 x i1>
  %44 = sext <4 x i1> %43 to <4 x i32>
  %45 = add <4 x i32> %42, %44
  %46 = getelementptr inbounds i8, ptr %2, i64 192
  %wide.load.6 = load <4 x i32>, ptr %46, align 16, !tbaa !8
  %47 = getelementptr inbounds i8, ptr %2, i64 160
  %wide.load.5 = load <4 x i32>, ptr %47, align 16, !tbaa !8
  %48 = getelementptr inbounds i8, ptr %2, i64 128
  %wide.load.4 = load <4 x i32>, ptr %48, align 16, !tbaa !8
  %49 = getelementptr inbounds i8, ptr %2, i64 96
  %wide.load.3 = load <4 x i32>, ptr %49, align 16, !tbaa !8
  %50 = getelementptr inbounds i8, ptr %2, i64 64
  %wide.load.2 = load <4 x i32>, ptr %50, align 16, !tbaa !8
  %51 = getelementptr inbounds i8, ptr %2, i64 32
  %wide.load.1 = load <4 x i32>, ptr %51, align 16, !tbaa !8
  %wide.load = load <4 x i32>, ptr %2, align 16, !tbaa !8
  %52 = trunc <4 x i32> %wide.load to <4 x i1>
  %53 = sext <4 x i1> %52 to <4 x i32>
  %54 = add <4 x i32> %wide.load, %53
  %55 = add <4 x i32> %wide.load.1, %54
  %56 = trunc <4 x i32> %wide.load.1 to <4 x i1>
  %57 = sext <4 x i1> %56 to <4 x i32>
  %58 = add <4 x i32> %55, %57
  %59 = add <4 x i32> %wide.load.2, %58
  %60 = trunc <4 x i32> %wide.load.2 to <4 x i1>
  %61 = sext <4 x i1> %60 to <4 x i32>
  %62 = add <4 x i32> %59, %61
  %63 = add <4 x i32> %wide.load.3, %62
  %64 = trunc <4 x i32> %wide.load.3 to <4 x i1>
  %65 = sext <4 x i1> %64 to <4 x i32>
  %66 = add <4 x i32> %63, %65
  %67 = add <4 x i32> %wide.load.4, %66
  %68 = trunc <4 x i32> %wide.load.4 to <4 x i1>
  %69 = sext <4 x i1> %68 to <4 x i32>
  %70 = add <4 x i32> %67, %69
  %71 = add <4 x i32> %wide.load.5, %70
  %72 = trunc <4 x i32> %wide.load.5 to <4 x i1>
  %73 = sext <4 x i1> %72 to <4 x i32>
  %74 = add <4 x i32> %71, %73
  %75 = add <4 x i32> %wide.load.6, %74
  %76 = trunc <4 x i32> %wide.load.6 to <4 x i1>
  %77 = sext <4 x i1> %76 to <4 x i32>
  %78 = add <4 x i32> %75, %77
  %bin.rdx27 = add <4 x i32> %45, %78
  %79 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx27)
  %80 = or <4 x i1> %52, %56
  %81 = or <4 x i1> %80, %60
  %82 = or <4 x i1> %81, %64
  %83 = or <4 x i1> %82, %68
  %84 = or <4 x i1> %83, %72
  %85 = or <4 x i1> %84, %76
  %86 = or <4 x i1> %85, %23
  %87 = or <4 x i1> %86, %19
  %88 = or <4 x i1> %87, %27
  %89 = or <4 x i1> %88, %31
  %90 = or <4 x i1> %89, %35
  %91 = or <4 x i1> %90, %39
  %bin.rdx = or <4 x i1> %91, %43
  %bin.rdx.fr = freeze <4 x i1> %bin.rdx
  %92 = bitcast <4 x i1> %bin.rdx.fr to i4
  %.not29 = icmp ne i4 %92, 0
  %93 = getelementptr inbounds i8, ptr %2, i64 224
  %94 = load i32, ptr %93, align 16, !tbaa !8
  %95 = and i32 %94, 1
  %.not15 = icmp ne i32 %95, 0
  %96 = sext i1 %.not15 to i32
  %narrow = or i1 %.not15, %.not29
  %spec.select = add i32 %94, %79
  %97 = add i32 %spec.select, %96
  %98 = getelementptr inbounds i8, ptr %2, i64 228
  %99 = load i32, ptr %98, align 4, !tbaa !8
  %100 = and i32 %99, 1
  %.not15.1 = icmp ne i32 %100, 0
  %101 = sext i1 %.not15.1 to i32
  %narrow34 = select i1 %.not15.1, i1 true, i1 %narrow
  %spec.select16.1 = zext i1 %narrow34 to i32
  %spec.select.1 = add i32 %99, %97
  %102 = add i32 %spec.select.1, %101
  %103 = add nsw i32 %102, %spec.select16.1
  call void @llvm.lifetime.end.p0(i64 232, ptr nonnull %2) #4
  ret i32 %103
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #3

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass