; LLVM IR from codeIIEST/Algorithms :: Competitive Coding/Linked List/Linked_Lists_based_on_POINTERS/Removing_duplicates/eba01f2c (Duplicatesv)

; 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.Node = type { i32, ptr }

@head = external dso_local global ptr, align 8
@hasht = external dso_local global [1000001 x [2 x i8]], align 16

; 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: mustprogress nounwind uwtable
define dso_local void @_Z17Remove_Duplicatesv() #1 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store ptr null, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %3 = load ptr, ptr @head, align 8, !tbaa !5
  store ptr %3, ptr %2, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %72, %0
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %73

7:                                                ; preds = %4
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp sge i32 %10, 0
  br i1 %11, label %12, label %41

12:                                               ; preds = %7
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Node, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1000001 x [2 x i8]], ptr @hasht, i64 0, i64 %16
  %18 = getelementptr inbounds [2 x i8], ptr %17, i64 0, i64 0
  %19 = load i8, ptr %18, align 2, !tbaa !12, !range !14, !noundef !15
  %20 = trunc i8 %19 to i1
  %21 = zext i1 %20 to i32
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %23, label %29

23:                                               ; preds = %12
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Node, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = load ptr, ptr %1, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Node, ptr %27, i32 0, i32 1
  store ptr %26, ptr %28, align 8, !tbaa !16
  br label %37

29:                                               ; preds = %12
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Node, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1000001 x [2 x i8]], ptr @hasht, i64 0, i64 %33
  %35 = getelementptr inbounds [2 x i8], ptr %34, i64 0, i64 0
  store i8 1, ptr %35, align 2, !tbaa !12
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %36, ptr %1, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %29, %23
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.Node, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  store ptr %40, ptr %2, align 8, !tbaa !5
  br label %72

41:                                               ; preds = %7
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Node, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !9
  %45 = call i32 @llvm.abs.i32(i32 %44, i1 true)
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1000001 x [2 x i8]], ptr @hasht, i64 0, i64 %46
  %48 = getelementptr inbounds [2 x i8], ptr %47, i64 0, i64 1
  %49 = load i8, ptr %48, align 1, !tbaa !12, !range !14, !noundef !15
  %50 = trunc i8 %49 to i1
  %51 = zext i1 %50 to i32
  %52 = icmp eq i32 %51, 1
  br i1 %52, label %53, label %59

53:                                               ; preds = %41
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Node, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = load ptr, ptr %1, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Node, ptr %57, i32 0, i32 1
  store ptr %56, ptr %58, align 8, !tbaa !16
  br label %68

59:                                               ; preds = %41
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Node, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !9
  %63 = call i32 @llvm.abs.i32(i32 %62, i1 true)
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1000001 x [2 x i8]], ptr @hasht, i64 0, i64 %64
  %66 = getelementptr inbounds [2 x i8], ptr %65, i64 0, i64 1
  store i8 1, ptr %66, align 1, !tbaa !12
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %67, ptr %1, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %59, %53
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.Node, ptr %69, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !16
  store ptr %71, ptr %2, align 8, !tbaa !5
  br label %72

72:                                               ; preds = %68, %37
  br label %4, !llvm.loop !17

73:                                               ; preds = %4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

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


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

@head = external dso_local local_unnamed_addr global ptr, align 8
@hasht = external dso_local local_unnamed_addr global [1000001 x [2 x i8]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z17Remove_Duplicatesv() local_unnamed_addr #0 {
  %.018 = load ptr, ptr @head, align 8, !tbaa !5
  %.not19 = icmp eq ptr %.018, null
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %24
  %.021 = phi ptr [ %.0, %24 ], [ %.018, %0 ]
  %.01420 = phi ptr [ %.3, %24 ], [ null, %0 ]
  %1 = load i32, ptr %.021, align 8, !tbaa !9
  %2 = icmp sgt i32 %1, -1
  br i1 %2, label %3, label %13

3:                                                ; preds = %.lr.ph
  %4 = zext nneg i32 %1 to i64
  %5 = getelementptr inbounds [1000001 x [2 x i8]], ptr @hasht, i64 0, i64 %4
  %6 = load i8, ptr %5, align 2, !tbaa !12, !range !14, !noundef !15
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %8, label %12

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %.021, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !16
  %11 = getelementptr inbounds i8, ptr %.01420, i64 8
  store ptr %10, ptr %11, align 8, !tbaa !16
  br label %24

12:                                               ; preds = %3
  store i8 1, ptr %5, align 2, !tbaa !12
  br label %24

13:                                               ; preds = %.lr.ph
  %14 = sub nsw i32 0, %1
  %15 = zext nneg i32 %14 to i64
  %16 = getelementptr inbounds [1000001 x [2 x i8]], ptr @hasht, i64 0, i64 %15, i64 1
  %17 = load i8, ptr %16, align 1, !tbaa !12, !range !14, !noundef !15
  %18 = trunc nuw i8 %17 to i1
  br i1 %18, label %19, label %23

19:                                               ; preds = %13
  %20 = getelementptr inbounds i8, ptr %.021, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %.01420, i64 8
  store ptr %21, ptr %22, align 8, !tbaa !16
  br label %24

23:                                               ; preds = %13
  store i8 1, ptr %16, align 1, !tbaa !12
  br label %24

24:                                               ; preds = %19, %23, %8, %12
  %.3 = phi ptr [ %.01420, %8 ], [ %.021, %12 ], [ %.01420, %19 ], [ %.021, %23 ]
  %.1.in = getelementptr inbounds i8, ptr %.021, i64 8
  %.0 = load ptr, ptr %.1.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %24, %0
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, 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" }

!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, !11, i64 0}
!10 = !{!"_ZTS4Node", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!10, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass