; LLVM IR from ravireddy07/cpp-book :: src/Code-Chef/PRPALIN.ll (Z12isPalindromel)

; 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z12isPalindromel(i64 noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = call noundef i64 @_ZSt3absl(i64 noundef %8)
  store i64 %9, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 1, ptr %6, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %15, %1
  %11 = load i64, ptr %4, align 8, !tbaa !5
  %12 = mul i64 10, %11
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %15, label %18

15:                                               ; preds = %10
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = mul i64 %16, 10
  store i64 %17, ptr %4, align 8, !tbaa !5
  br label %10, !llvm.loop !9

18:                                               ; preds = %10
  br label %19

19:                                               ; preds = %32, %18
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = icmp sgt i64 %20, 0
  br i1 %21, label %22, label %42

22:                                               ; preds = %19
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = udiv i64 %23, %24
  store i64 %25, ptr %5, align 8, !tbaa !5
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = srem i64 %26, 10
  store i64 %27, ptr %6, align 8, !tbaa !5
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = load i64, ptr %6, align 8, !tbaa !5
  %30 = icmp ne i64 %28, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %22
  store i1 false, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %43

32:                                               ; preds = %22
  %33 = load i64, ptr %3, align 8, !tbaa !5
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = load i64, ptr %5, align 8, !tbaa !5
  %36 = mul i64 %34, %35
  %37 = sub i64 %33, %36
  store i64 %37, ptr %3, align 8, !tbaa !5
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = sdiv i64 %38, 10
  store i64 %39, ptr %3, align 8, !tbaa !5
  %40 = load i64, ptr %4, align 8, !tbaa !5
  %41 = udiv i64 %40, 100
  store i64 %41, ptr %4, align 8, !tbaa !5
  br label %19, !llvm.loop !11

42:                                               ; preds = %19
  store i1 true, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %43

43:                                               ; preds = %42, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %44 = load i1, ptr %2, align 1
  ret i1 %44
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absl(i64 noundef) #1

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

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

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 = { inlinehint 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; 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: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z12isPalindromel(i64 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef i64 @_ZSt3absl(i64 noundef %0)
  br label %3

3:                                                ; preds = %3, %1
  %.0 = phi i64 [ 1, %1 ], [ %4, %3 ]
  %4 = mul i64 %.0, 10
  %5 = icmp ult i64 %4, %2
  br i1 %5, label %3, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %3
  %6 = icmp slt i64 %2, 1
  br i1 %6, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %9
  %.121 = phi i64 [ %12, %9 ], [ %.0, %.preheader ]
  %.01520 = phi i64 [ %11, %9 ], [ %2, %.preheader ]
  %7 = udiv i64 %.01520, %.121
  %.recomposed = urem i64 %.01520, %.121
  %8 = urem i64 %.01520, 10
  %.not = icmp eq i64 %7, %8
  br i1 %.not, label %9, label %._crit_edge

9:                                                ; preds = %.lr.ph
  %10 = mul nuw i64 %7, %.121
  %11 = udiv i64 %.recomposed, 10
  %12 = udiv i64 %.121, 100
  %13 = icmp ult i64 %.recomposed, 10
  br i1 %13, label %._crit_edge, label %.lr.ph, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph, %9, %.preheader
  %.lcssa = phi i1 [ true, %.preheader ], [ %.not, %9 ], [ %.not, %.lr.ph ]
  ret i1 %.lcssa
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absl(i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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