; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 10. Linked List/cpp/Checking if a linked list is Palindrome.ll (Z12isPalindromeP4Node)

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

%class.Node = type { i32, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z9reverseLLP4Node(ptr noundef) #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z12isPalindromeP4Node(ptr noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %14

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  store i1 %13, ptr %2, align 1
  br label %71

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %15, ptr %5, align 8, !tbaa !5
  store ptr %15, ptr %4, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %26, %14
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %24

19:                                               ; preds = %16
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %class.Node, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  br label %24

24:                                               ; preds = %19, %16
  %25 = phi i1 [ false, %16 ], [ %23, %19 ]
  br i1 %25, label %26, label %35

26:                                               ; preds = %24
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.Node, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds %class.Node, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  store ptr %31, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %class.Node, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  store ptr %34, ptr %4, align 8, !tbaa !5
  br label %16, !llvm.loop !12

35:                                               ; preds = %24
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %41, label %38

38:                                               ; preds = %35
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = call noundef ptr @_Z9reverseLLP4Node(ptr noundef %39)
  store ptr %40, ptr %4, align 8, !tbaa !5
  br label %47

41:                                               ; preds = %35
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %class.Node, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  store ptr %44, ptr %4, align 8, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = call noundef ptr @_Z9reverseLLP4Node(ptr noundef %45)
  store ptr %46, ptr %4, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %41, %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %48, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %49, ptr %7, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %62, %47
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %69

53:                                               ; preds = %50
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %class.Node, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !14
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %class.Node, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !14
  %60 = icmp ne i32 %56, %59
  br i1 %60, label %61, label %62

61:                                               ; preds = %53
  store i1 false, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %70

62:                                               ; preds = %53
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %class.Node, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !9
  store ptr %65, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %class.Node, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !9
  store ptr %68, ptr %6, align 8, !tbaa !5
  br label %50, !llvm.loop !15

69:                                               ; preds = %50
  store i1 true, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %70

70:                                               ; preds = %69, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %71

71:                                               ; preds = %70, %11
  %72 = load i1, ptr %2, align 1
  ret i1 %72
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS4Node", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!10, !11, i64 0}
!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: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z9reverseLLP4Node(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z12isPalindromeP4Node(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1, %5
  %.02032 = phi ptr [ %7, %5 ], [ %0, %1 ]
  %.02131 = phi ptr [ %9, %5 ], [ %0, %1 ]
  %3 = getelementptr inbounds i8, ptr %.02032, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not26 = icmp eq ptr %4, null
  br i1 %.not26, label %.critedge, label %5

5:                                                ; preds = %.preheader
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %.02131, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %.critedge29, label %.preheader, !llvm.loop !11

.critedge:                                        ; preds = %.preheader
  %10 = getelementptr inbounds i8, ptr %.02131, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  br label %.critedge29

.critedge29:                                      ; preds = %5, %.critedge
  %.sink = phi ptr [ %11, %.critedge ], [ %9, %5 ]
  %12 = tail call noundef ptr @_Z9reverseLLP4Node(ptr noundef %.sink)
  %.not2733 = icmp eq ptr %12, null
  br i1 %.not2733, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.critedge29, %15
  %.035 = phi ptr [ %17, %15 ], [ %12, %.critedge29 ]
  %.01934 = phi ptr [ %19, %15 ], [ %0, %.critedge29 ]
  %13 = load i32, ptr %.01934, align 8, !tbaa !13
  %14 = load i32, ptr %.035, align 8, !tbaa !13
  %.not28 = icmp eq i32 %13, %14
  br i1 %.not28, label %15, label %.loopexit

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %.035, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.01934, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %.not27 = icmp eq ptr %17, null
  br i1 %.not27, label %.loopexit, label %.lr.ph, !llvm.loop !14

.loopexit:                                        ; preds = %15, %.lr.ph, %.critedge29, %1
  %.123 = phi i1 [ false, %1 ], [ true, %.critedge29 ], [ %.not28, %.lr.ph ], [ %.not28, %15 ]
  ret i1 %.123
}

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

!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, !10, i64 8}
!6 = !{!"_ZTS4Node", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !7, i64 0}
!14 = distinct !{!14, !12}


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