; LLVM IR from kenjin/Awesome-LC-C-Cracker :: leetcode-c-sol/0409_longest-palindrome (0409_longest-palindrome)

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

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

11:                                               ; preds = %7
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = icmp sle i32 65, %14
  br i1 %15, label %16, label %31

16:                                               ; preds = %11
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = sext i8 %18 to i32
  %20 = icmp sle i32 %19, 90
  br i1 %20, label %21, label %31

21:                                               ; preds = %16
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = sext i8 %23 to i32
  %25 = sub nsw i32 %24, 65
  %26 = add nsw i32 %25, 26
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [52 x i32], ptr %3, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !10
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %28, align 4, !tbaa !10
  br label %51

31:                                               ; preds = %16, %11
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = load i8, ptr %32, align 1, !tbaa !9
  %34 = sext i8 %33 to i32
  %35 = icmp sle i32 97, %34
  br i1 %35, label %36, label %50

36:                                               ; preds = %31
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = load i8, ptr %37, align 1, !tbaa !9
  %39 = sext i8 %38 to i32
  %40 = icmp sle i32 %39, 122
  br i1 %40, label %41, label %50

41:                                               ; preds = %36
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = sub nsw i32 %44, 97
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [52 x i32], ptr %3, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !10
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %47, align 4, !tbaa !10
  br label %50

50:                                               ; preds = %41, %36, %31
  br label %51

51:                                               ; preds = %50, %21
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i32 1
  store ptr %53, ptr %2, align 8, !tbaa !5
  br label %7, !llvm.loop !12

54:                                               ; preds = %7
  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 %55

55:                                               ; preds = %78, %54
  %56 = load i32, ptr %6, align 4, !tbaa !10
  %57 = icmp slt i32 %56, 52
  br i1 %57, label %59, label %58

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

59:                                               ; preds = %55
  %60 = load i32, ptr %5, align 4, !tbaa !10
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %70, label %62

62:                                               ; preds = %59
  %63 = load i32, ptr %6, align 4, !tbaa !10
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [52 x i32], ptr %3, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !10
  %67 = and i32 %66, 1
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %62
  store i32 1, ptr %5, align 4, !tbaa !10
  br label %70

70:                                               ; preds = %69, %62, %59
  %71 = load i32, ptr %6, align 4, !tbaa !10
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [52 x i32], ptr %3, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !10
  %75 = ashr i32 %74, 1
  %76 = load i32, ptr %4, align 4, !tbaa !10
  %77 = add nsw i32 %76, %75
  store i32 %77, ptr %4, align 4, !tbaa !10
  br label %78

78:                                               ; preds = %70
  %79 = load i32, ptr %6, align 4, !tbaa !10
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %6, align 4, !tbaa !10
  br label %55, !llvm.loop !14

81:                                               ; preds = %58
  %82 = load i32, ptr %4, align 4, !tbaa !10
  %83 = shl i32 %82, 1
  %84 = load i32, ptr %5, align 4, !tbaa !10
  %85 = add nsw i32 %83, %84
  store i32 %85, ptr %4, align 4, !tbaa !10
  %86 = load i32, ptr %4, align 4, !tbaa !10
  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 208, ptr %3) #3
  ret i32 %86
}

; 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 [52 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 208, ptr nonnull %2) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(208) %2, i8 0, i64 208, i1 false)
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %.not27 = icmp eq i8 %3, 0
  br i1 %.not27, label %._crit_edge.preheader, label %.lr.ph

._crit_edge.preheader:                            ; preds = %14, %1
  br label %._crit_edge

.lr.ph:                                           ; preds = %1, %14
  %4 = phi i8 [ %16, %14 ], [ %3, %1 ]
  %.01828 = phi ptr [ %15, %14 ], [ %0, %1 ]
  %5 = add i8 %4, -65
  %or.cond = icmp ult i8 %5, 26
  br i1 %or.cond, label %6, label %8

6:                                                ; preds = %.lr.ph
  %narrow25 = add nuw nsw i8 %4, 25
  %7 = and i8 %narrow25, 63
  br label %.sink.split

8:                                                ; preds = %.lr.ph
  %9 = add i8 %4, -97
  %or.cond26 = icmp ult i8 %9, 26
  br i1 %or.cond26, label %.sink.split, label %14

.sink.split:                                      ; preds = %8, %6
  %.sink = phi i8 [ %7, %6 ], [ %9, %8 ]
  %10 = zext nneg i8 %.sink to i64
  %11 = getelementptr inbounds [52 x i32], ptr %2, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !8
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr %11, align 4, !tbaa !8
  br label %14

14:                                               ; preds = %.sink.split, %8
  %15 = getelementptr inbounds i8, ptr %.01828, i64 1
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %.not = icmp eq i8 %16, 0
  br i1 %.not, label %._crit_edge.preheader, label %.lr.ph, !llvm.loop !10

17:                                               ; preds = %._crit_edge
  %18 = shl i32 %29, 1
  %19 = or disjoint i32 %18, %.1.1
  call void @llvm.lifetime.end.p0(i64 208, ptr nonnull %2) #3
  ret i32 %19

._crit_edge:                                      ; preds = %._crit_edge, %._crit_edge.preheader
  %indvars.iv = phi i64 [ 0, %._crit_edge.preheader ], [ %indvars.iv.next.1, %._crit_edge ]
  %.01630 = phi i32 [ 0, %._crit_edge.preheader ], [ %.1.1, %._crit_edge ]
  %.01729 = phi i32 [ 0, %._crit_edge.preheader ], [ %29, %._crit_edge ]
  %.not22 = icmp eq i32 %.01630, 0
  %20 = getelementptr inbounds [52 x i32], ptr %2, i64 0, i64 %indvars.iv
  %21 = load i32, ptr %20, align 8, !tbaa !8
  %22 = and i32 %21, 1
  %23 = ashr i32 %21, 1
  %24 = add nsw i32 %23, %.01729
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %.not22.136 = icmp eq i32 %22, 0
  %.not22.1 = select i1 %.not22, i1 %.not22.136, i1 false
  %25 = getelementptr inbounds [52 x i32], ptr %2, i64 0, i64 %indvars.iv.next
  %26 = load i32, ptr %25, align 4, !tbaa !8
  %27 = and i32 %26, 1
  %.1.1 = select i1 %.not22.1, i32 %27, i32 1
  %28 = ashr i32 %26, 1
  %29 = add nsw i32 %28, %24
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 52
  br i1 %exitcond.not.1, label %17, label %._crit_edge, !llvm.loop !12
}

; 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

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 = { 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"}
!12 = distinct !{!12, !11}


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