; LLVM IR from JessonYue/LeetCodeLearning :: Array/zhangjunwei/linked_list (isPalindrome_6_12)

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

%struct.ListNode_ = type { i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @isPalindrome1(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %8, ptr %4, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %12, %1
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %18

12:                                               ; preds = %9
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %3, align 4, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ListNode_, ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  store ptr %17, ptr %4, align 8, !tbaa !5
  br label %9, !llvm.loop !13

18:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = mul i64 4, %20
  %22 = call noalias ptr @malloc(i64 noundef %21) #4
  store ptr %22, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %23, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = sub nsw i32 %24, 1
  store i32 %25, ptr %6, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %29, %18
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %41

29:                                               ; preds = %26
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ListNode_, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !15
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = add nsw i32 %34, -1
  store i32 %35, ptr %6, align 4, !tbaa !9
  %36 = sext i32 %34 to i64
  %37 = getelementptr inbounds i32, ptr %33, i64 %36
  store i32 %32, ptr %37, align 4, !tbaa !9
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ListNode_, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  store ptr %40, ptr %4, align 8, !tbaa !5
  br label %26, !llvm.loop !16

41:                                               ; preds = %26
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %42, ptr %4, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  store i8 1, ptr %7, align 1, !tbaa !17
  br label %43

43:                                               ; preds = %57, %41
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %63

46:                                               ; preds = %43
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ListNode_, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !15
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %50, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = icmp ne i32 %49, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %46
  store i8 0, ptr %7, align 1, !tbaa !17
  br label %63

57:                                               ; preds = %46
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %6, align 4, !tbaa !9
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ListNode_, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  store ptr %62, ptr %4, align 8, !tbaa !5
  br label %43, !llvm.loop !19

63:                                               ; preds = %56, %43
  %64 = load i8, ptr %7, align 1, !tbaa !17, !range !20, !noundef !21
  %65 = trunc i8 %64 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, 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
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i1 %65
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #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 = { nounwind allocsize(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 #3 = { nounwind }
attributes #4 = { nounwind allocsize(0) }

!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 = !{!12, !6, i64 8}
!12 = !{!"ListNode_", !10, i64 0, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !10, i64 0}
!16 = distinct !{!16, !14}
!17 = !{!18, !18, i64 0}
!18 = !{!"_Bool", !7, i64 0}
!19 = distinct !{!19, !14}
!20 = !{i8 0, i8 2}
!21 = !{}


; 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(readwrite, argmem: read) uwtable
define dso_local noundef zeroext i1 @isPalindrome1(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not26 = icmp eq ptr %0, null
  br i1 %.not26, label %._crit_edge39, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.02028 = phi i32 [ %2, %.lr.ph ], [ 0, %1 ]
  %.02127 = phi ptr [ %4, %.lr.ph ], [ %0, %1 ]
  %2 = add nuw nsw i32 %.02028, 1
  %3 = getelementptr inbounds i8, ptr %.02127, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph
  %5 = zext nneg i32 %2 to i64
  %6 = shl nuw nsw i64 %5, 2
  %7 = tail call noalias ptr @malloc(i64 noundef %6) #2
  br i1 %.not26, label %._crit_edge39, label %.lr.ph33.preheader

.lr.ph33.preheader:                               ; preds = %._crit_edge
  %8 = zext nneg i32 %2 to i64
  br label %.lr.ph33

.preheader:                                       ; preds = %.lr.ph33
  br i1 %.not26, label %._crit_edge39, label %.lr.ph38

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %.lr.ph33
  %indvars.iv = phi i64 [ %8, %.lr.ph33.preheader ], [ %indvars.iv.next, %.lr.ph33 ]
  %.12230 = phi ptr [ %0, %.lr.ph33.preheader ], [ %12, %.lr.ph33 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %9 = load i32, ptr %.12230, align 8, !tbaa !13
  %10 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv.next
  store i32 %9, ptr %10, align 4, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %.12230, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %.not23 = icmp eq ptr %12, null
  br i1 %.not23, label %.preheader, label %.lr.ph33, !llvm.loop !15

.lr.ph38:                                         ; preds = %.preheader, %16
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %16 ], [ 0, %.preheader ]
  %.235 = phi ptr [ %18, %16 ], [ %0, %.preheader ]
  %13 = load i32, ptr %.235, align 8, !tbaa !13
  %14 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv44
  %15 = load i32, ptr %14, align 4, !tbaa !14
  %.not25 = icmp eq i32 %13, %15
  br i1 %.not25, label %16, label %._crit_edge39

16:                                               ; preds = %.lr.ph38
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %17 = getelementptr inbounds i8, ptr %.235, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %.not24 = icmp eq ptr %18, null
  br i1 %.not24, label %._crit_edge39, label %.lr.ph38, !llvm.loop !16

._crit_edge39:                                    ; preds = %16, %.lr.ph38, %1, %._crit_edge, %.preheader
  %.not24.lcssa = phi i1 [ true, %.preheader ], [ true, %._crit_edge ], [ true, %1 ], [ %.not25, %.lr.ph38 ], [ %.not25, %16 ]
  ret i1 %.not24.lcssa
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

attributes #0 = { nofree nounwind memory(readwrite, argmem: read) 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 allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind allocsize(0) }

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


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