; LLVM IR from AlgoGenesis/C :: Searching Algorithms/Valid_Palindrome (Valid 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 @isPalindrome(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %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
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call i64 @strlen(ptr noundef %11) #5
  %13 = sub i64 %12, 1
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %5, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %100, %1
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %105

19:                                               ; preds = %15
  br label %20

20:                                               ; preds = %42, %19
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %40

24:                                               ; preds = %20
  %25 = call ptr @__ctype_b_loc() #6
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %27, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i16, ptr %26, i64 %33
  %35 = load i16, ptr %34, align 2, !tbaa !12
  %36 = zext i16 %35 to i32
  %37 = and i32 %36, 8
  %38 = icmp ne i32 %37, 0
  %39 = xor i1 %38, true
  br label %40

40:                                               ; preds = %24, %20
  %41 = phi i1 [ false, %20 ], [ %39, %24 ]
  br i1 %41, label %42, label %45

42:                                               ; preds = %40
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %4, align 4, !tbaa !9
  br label %20, !llvm.loop !14

45:                                               ; preds = %40
  br label %46

46:                                               ; preds = %68, %45
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %50, label %66

50:                                               ; preds = %46
  %51 = call ptr @__ctype_b_loc() #6
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i8, ptr %53, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !11
  %58 = sext i8 %57 to i32
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i16, ptr %52, i64 %59
  %61 = load i16, ptr %60, align 2, !tbaa !12
  %62 = zext i16 %61 to i32
  %63 = and i32 %62, 8
  %64 = icmp ne i32 %63, 0
  %65 = xor i1 %64, true
  br label %66

66:                                               ; preds = %50, %46
  %67 = phi i1 [ false, %46 ], [ %65, %50 ]
  br i1 %67, label %68, label %71

68:                                               ; preds = %66
  %69 = load i32, ptr %5, align 4, !tbaa !9
  %70 = add nsw i32 %69, -1
  store i32 %70, ptr %5, align 4, !tbaa !9
  br label %46, !llvm.loop !16

71:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %72 = call ptr @__ctype_tolower_loc() #6
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = load i32, ptr %4, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i8, ptr %74, i64 %76
  %78 = load i8, ptr %77, align 1, !tbaa !11
  %79 = sext i8 %78 to i32
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i32, ptr %73, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !9
  store i32 %82, ptr %6, align 4, !tbaa !9
  %83 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %83, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %84 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %85 = call ptr @__ctype_tolower_loc() #6
  %86 = load ptr, ptr %85, align 8, !tbaa !5
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = load i32, ptr %5, align 4, !tbaa !9
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds i8, ptr %87, i64 %89
  %91 = load i8, ptr %90, align 1, !tbaa !11
  %92 = sext i8 %91 to i32
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds i32, ptr %86, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !9
  store i32 %95, ptr %8, align 4, !tbaa !9
  %96 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %96, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %97 = load i32, ptr %9, align 4, !tbaa !9
  %98 = icmp ne i32 %84, %97
  br i1 %98, label %99, label %100

99:                                               ; preds = %71
  store i32 0, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %106

100:                                              ; preds = %71
  %101 = load i32, ptr %4, align 4, !tbaa !9
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %4, align 4, !tbaa !9
  %103 = load i32, ptr %5, align 4, !tbaa !9
  %104 = add nsw i32 %103, -1
  store i32 %104, ptr %5, align 4, !tbaa !9
  br label %15, !llvm.loop !17

105:                                              ; preds = %15
  store i32 1, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %106

106:                                              ; preds = %105, %99
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %107 = load i32, ptr %2, align 4
  ret i32 %107
}

; 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 willreturn memory(none)
declare ptr @__ctype_b_loc() #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_tolower_loc() #3

; 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 willreturn memory(none) "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 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


; 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 memory(read, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @isPalindrome(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %3 = trunc i64 %2 to i32
  %.02634 = add i32 %3, -1
  %4 = icmp sgt i32 %.02634, 0
  br i1 %4, label %.preheader.lr.ph, label %._crit_edge

.preheader.lr.ph:                                 ; preds = %1
  %5 = tail call ptr @__ctype_b_loc() #5
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = tail call ptr @__ctype_tolower_loc() #5
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  br label %.preheader

9:                                                ; preds = %.critedge2
  %10 = add nsw i32 %.1.lcssa46, 1
  %.026 = add i32 %.127.lcssa, -1
  %11 = icmp slt i32 %10, %.026
  br i1 %11, label %.preheader, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %.preheader.lr.ph, %9
  %.02636 = phi i32 [ %.02634, %.preheader.lr.ph ], [ %.026, %9 ]
  %.02535 = phi i32 [ 0, %.preheader.lr.ph ], [ %10, %9 ]
  %12 = sext i32 %.02535 to i64
  %13 = sext i32 %.02636 to i64
  %14 = add nsw i32 %.02535, 1
  %smax = tail call i32 @llvm.smax.i32(i32 %.02636, i32 %14)
  br label %15

15:                                               ; preds = %.preheader, %22
  %indvars.iv = phi i64 [ %12, %.preheader ], [ %indvars.iv.next, %22 ]
  %16 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = sext i8 %17 to i64
  %19 = getelementptr inbounds i16, ptr %6, i64 %18
  %20 = load i16, ptr %19, align 2, !tbaa !12
  %21 = and i16 %20, 8
  %.not = icmp eq i16 %21, 0
  br i1 %.not, label %22, label %.critedge

22:                                               ; preds = %15
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %23 = icmp slt i64 %indvars.iv.next, %13
  br i1 %23, label %15, label %.critedge..critedge2_crit_edge, !llvm.loop !14

.critedge:                                        ; preds = %15
  %24 = trunc nsw i64 %indvars.iv to i32
  %25 = icmp sgt i32 %.02636, %24
  br i1 %25, label %.lr.ph, label %.critedge..critedge2_crit_edge

.critedge..critedge2_crit_edge:                   ; preds = %22, %.critedge
  %.1.lcssa47 = phi i32 [ %24, %.critedge ], [ %smax, %22 ]
  %.pre = sext i32 %.1.lcssa47 to i64
  br label %.critedge2

.lr.ph:                                           ; preds = %.critedge
  %sext50 = shl i64 %indvars.iv, 32
  %26 = ashr exact i64 %sext50, 32
  br label %27

27:                                               ; preds = %.lr.ph, %35
  %indvars.iv40 = phi i64 [ %13, %.lr.ph ], [ %indvars.iv.next41, %35 ]
  %28 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv40
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = sext i8 %29 to i64
  %31 = getelementptr inbounds i16, ptr %6, i64 %30
  %32 = load i16, ptr %31, align 2, !tbaa !12
  %33 = and i16 %32, 8
  %.not28 = icmp eq i16 %33, 0
  br i1 %.not28, label %35, label %..critedge2.loopexit_crit_edge

..critedge2.loopexit_crit_edge:                   ; preds = %27
  %34 = trunc nsw i64 %indvars.iv40 to i32
  %sext = shl i64 %indvars.iv40, 32
  %.pre43 = ashr exact i64 %sext, 32
  br label %.critedge2

35:                                               ; preds = %27
  %indvars.iv.next41 = add nsw i64 %indvars.iv40, -1
  %36 = icmp sgt i64 %indvars.iv.next41, %26
  br i1 %36, label %27, label %.critedge2, !llvm.loop !15

.critedge2:                                       ; preds = %35, %..critedge2.loopexit_crit_edge, %.critedge..critedge2_crit_edge
  %.1.lcssa46 = phi i32 [ %.1.lcssa47, %.critedge..critedge2_crit_edge ], [ %24, %..critedge2.loopexit_crit_edge ], [ %24, %35 ]
  %.pre-phi44 = phi i64 [ %.pre, %.critedge..critedge2_crit_edge ], [ %26, %..critedge2.loopexit_crit_edge ], [ %26, %35 ]
  %.pre-phi = phi i64 [ %13, %.critedge..critedge2_crit_edge ], [ %.pre43, %..critedge2.loopexit_crit_edge ], [ %26, %35 ]
  %.127.lcssa = phi i32 [ %.02636, %.critedge..critedge2_crit_edge ], [ %34, %..critedge2.loopexit_crit_edge ], [ %24, %35 ]
  %37 = getelementptr inbounds i8, ptr %0, i64 %.pre-phi44
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = sext i8 %38 to i64
  %40 = getelementptr inbounds i32, ptr %8, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !16
  %42 = getelementptr inbounds i8, ptr %0, i64 %.pre-phi
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = sext i8 %43 to i64
  %45 = getelementptr inbounds i32, ptr %8, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !16
  %.not29 = icmp eq i32 %41, %46
  br i1 %.not29, label %9, label %._crit_edge

._crit_edge:                                      ; preds = %.critedge2, %9, %1
  %.0 = phi i32 [ 1, %1 ], [ 1, %9 ], [ 0, %.critedge2 ]
  ret i32 %.0
}

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_tolower_loc() local_unnamed_addr #2

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

attributes #0 = { nofree 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 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 nosync nounwind willreturn memory(none) "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind willreturn memory(read) }
attributes #5 = { nounwind willreturn memory(none) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}


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