; LLVM IR from int32bit/leetcode :: algorithms/RemoveDuplicatesfromSortedList2 (solve)

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

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

8:                                                ; preds = %69, %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %70

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ListNode, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  store i8 0, ptr %6, align 1, !tbaa !12
  br label %15

15:                                               ; preds = %28, %11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %26

18:                                               ; preds = %15
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ListNode, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !14
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ListNode, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !14
  %25 = icmp eq i32 %21, %24
  br label %26

26:                                               ; preds = %18, %15
  %27 = phi i1 [ false, %15 ], [ %25, %18 ]
  br i1 %27, label %28, label %40

28:                                               ; preds = %26
  store i8 1, ptr %6, align 1, !tbaa !12
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ListNode, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.ListNode, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ListNode, ptr %34, i32 0, i32 1
  store ptr %33, ptr %35, align 8, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %36) #3
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ListNode, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  store ptr %39, ptr %5, align 8, !tbaa !5
  br label %15, !llvm.loop !15

40:                                               ; preds = %26
  %41 = load i8, ptr %6, align 1, !tbaa !12, !range !17, !noundef !18
  %42 = trunc i8 %41 to i1
  br i1 %42, label %43, label %64

43:                                               ; preds = %40
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = icmp eq ptr %44, %45
  br i1 %46, label %47, label %53

47:                                               ; preds = %43
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ListNode, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  store ptr %50, ptr %2, align 8, !tbaa !5
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %51) #3
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %52, ptr %3, align 8, !tbaa !5
  br label %63

53:                                               ; preds = %43
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ListNode, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.ListNode, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ListNode, ptr %59, i32 0, i32 1
  store ptr %58, ptr %60, align 8, !tbaa !9
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %61) #3
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %62, ptr %3, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %53, %47
  br label %69

64:                                               ; preds = %40
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %65, ptr %4, align 8, !tbaa !5
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ListNode, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !9
  store ptr %68, ptr %3, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %64, %63
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %8, !llvm.loop !19

70:                                               ; preds = %8
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %71
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 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 #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 = !{!10, !6, i64 8}
!10 = !{!"ListNode", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!10, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !16}


; 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 willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @deleteDuplicates(ptr noundef %0) local_unnamed_addr #1 {
  %.not37 = icmp eq ptr %0, null
  br i1 %.not37, label %._crit_edge, label %.lr.ph41

.lr.ph41:                                         ; preds = %1, %.critedge.thread
  %.02340 = phi ptr [ %.1, %.critedge.thread ], [ null, %1 ]
  %.02439 = phi ptr [ %.022.lcssa45, %.critedge.thread ], [ %0, %1 ]
  %.02638 = phi ptr [ %.127, %.critedge.thread ], [ %0, %1 ]
  %2 = getelementptr inbounds i8, ptr %.02439, i64 8
  %.02229 = load ptr, ptr %2, align 8, !tbaa !5
  %.not2830 = icmp eq ptr %.02229, null
  br i1 %.not2830, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph41
  %3 = load i32, ptr %.02229, align 8, !tbaa !11
  %4 = load i32, ptr %.02439, align 8, !tbaa !11
  %5 = icmp eq i32 %3, %4
  br i1 %5, label %6, label %.critedge.thread

6:                                                ; preds = %.lr.ph.preheader
  %7 = getelementptr inbounds i8, ptr %.02229, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %8, ptr %2, align 8, !tbaa !5
  tail call void @free(ptr noundef nonnull %.02229) #2
  %.022.peel = load ptr, ptr %2, align 8, !tbaa !5
  %.not28.peel = icmp eq ptr %.022.peel, null
  br i1 %.not28.peel, label %.critedge.thread46, label %.lr.ph

.lr.ph:                                           ; preds = %6, %12
  %.02232 = phi ptr [ %.022, %12 ], [ %.022.peel, %6 ]
  %9 = load i32, ptr %.02232, align 8, !tbaa !11
  %10 = load i32, ptr %.02439, align 8, !tbaa !11
  %11 = icmp eq i32 %9, %10
  br i1 %11, label %12, label %.critedge

12:                                               ; preds = %.lr.ph
  %13 = getelementptr inbounds i8, ptr %.02232, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %14, ptr %2, align 8, !tbaa !5
  tail call void @free(ptr noundef nonnull %.02232) #2
  %.022 = load ptr, ptr %2, align 8, !tbaa !5
  %.not28 = icmp eq ptr %.022, null
  br i1 %.not28, label %.critedge, label %.lr.ph, !llvm.loop !12

.critedge:                                        ; preds = %.lr.ph, %12
  %.022.lcssa = phi ptr [ null, %12 ], [ %.02232, %.lr.ph ]
  br i1 %5, label %.critedge.thread46, label %.critedge.thread

.critedge.thread46:                               ; preds = %6, %.critedge
  %.022.lcssa49 = phi ptr [ %.022.lcssa, %.critedge ], [ null, %6 ]
  %15 = icmp eq ptr %.02439, %.02638
  br i1 %15, label %.critedge.thread.sink.split, label %16

16:                                               ; preds = %.critedge.thread46
  %17 = getelementptr inbounds i8, ptr %.02340, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %20, ptr %17, align 8, !tbaa !5
  br label %.critedge.thread.sink.split

.critedge.thread.sink.split:                      ; preds = %.critedge.thread46, %16
  %.127.ph = phi ptr [ %.02638, %16 ], [ %.022.lcssa49, %.critedge.thread46 ]
  tail call void @free(ptr noundef nonnull %.02439) #2
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %.critedge.thread.sink.split, %.lr.ph.preheader, %.critedge
  %.022.lcssa45 = phi ptr [ %.022.lcssa, %.critedge ], [ %.02229, %.lr.ph.preheader ], [ %.022.lcssa49, %.critedge.thread.sink.split ]
  %.127 = phi ptr [ %.02638, %.critedge ], [ %.02638, %.lr.ph.preheader ], [ %.127.ph, %.critedge.thread.sink.split ]
  %.1 = phi ptr [ %.02439, %.critedge ], [ %.02439, %.lr.ph.preheader ], [ %.02340, %.critedge.thread.sink.split ]
  %.not = icmp eq ptr %.022.lcssa45, null
  br i1 %.not, label %._crit_edge, label %.lr.ph41, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph41, %.critedge.thread, %1
  %.026.lcssa = phi ptr [ null, %1 ], [ %.02638, %.lr.ph41 ], [ %.127, %.critedge.thread ]
  ret ptr %.026.lcssa
}

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #1 = { 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 = { 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, !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 = !{!6, !7, i64 0}
!12 = distinct !{!12, !13, !14}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.peeled.count", i32 1}
!15 = distinct !{!15, !13}


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