; LLVM IR from JessonYue/LeetCodeLearning :: Array/caiweixiong/c (homework_015)

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

@carr = external hidden global [20000 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: nounwind uwtable
define dso_local ptr @removeDuplicates(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %9, label %8

8:                                                ; preds = %1
  store ptr null, ptr %2, align 8
  br label %69

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %20, label %14

14:                                               ; preds = %9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 1
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %14, %9
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %21, ptr %2, align 8
  br label %69

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

24:                                               ; preds = %63, %22
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %64

29:                                               ; preds = %24
  %30 = load i32, ptr %5, align 4, !tbaa !10
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %40

32:                                               ; preds = %29
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i32 1
  store ptr %34, ptr %4, align 8, !tbaa !5
  %35 = load i8, ptr %33, align 1, !tbaa !9
  %36 = load i32, ptr %5, align 4, !tbaa !10
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %5, align 4, !tbaa !10
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [20000 x i8], ptr @carr, i64 0, i64 %38
  store i8 %35, ptr %39, align 1, !tbaa !9
  br label %63

40:                                               ; preds = %29
  %41 = load i32, ptr %5, align 4, !tbaa !10
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [20000 x i8], ptr @carr, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = sext i8 %44 to i32
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i8, ptr %46, align 1, !tbaa !9
  %48 = sext i8 %47 to i32
  %49 = icmp eq i32 %45, %48
  br i1 %49, label %50, label %53

50:                                               ; preds = %40
  %51 = load i32, ptr %5, align 4, !tbaa !10
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr %5, align 4, !tbaa !10
  br label %60

53:                                               ; preds = %40
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load i8, ptr %54, align 1, !tbaa !9
  %56 = load i32, ptr %5, align 4, !tbaa !10
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %5, align 4, !tbaa !10
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [20000 x i8], ptr @carr, i64 0, i64 %58
  store i8 %55, ptr %59, align 1, !tbaa !9
  br label %60

60:                                               ; preds = %53, %50
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i32 1
  store ptr %62, ptr %4, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %60, %32
  br label %24, !llvm.loop !12

64:                                               ; preds = %24
  %65 = load i32, ptr %5, align 4, !tbaa !10
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %5, align 4, !tbaa !10
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [20000 x i8], ptr @carr, i64 0, i64 %67
  store i8 0, ptr %68, align 1, !tbaa !9
  store ptr @carr, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %69

69:                                               ; preds = %64, %20, %8
  %70 = load ptr, ptr %2, align 8
  ret ptr %70
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@carr = external hidden global [20000 x i8], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local noundef ptr @removeDuplicates(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %28, label %2

2:                                                ; preds = %1
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %4 = icmp eq i8 %3, 0
  br i1 %4, label %28, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 1
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = icmp eq i8 %7, 0
  br i1 %8, label %28, label %.lr.ph

.lr.ph:                                           ; preds = %5, %23
  %9 = phi i8 [ %24, %23 ], [ %3, %5 ]
  %.024 = phi i32 [ %.2, %23 ], [ -1, %5 ]
  %.01623 = phi ptr [ %.117, %23 ], [ %0, %5 ]
  %10 = icmp eq i32 %.024, -1
  br i1 %10, label %11, label %12

11:                                               ; preds = %.lr.ph
  store i8 %9, ptr @carr, align 16, !tbaa !5
  br label %23

12:                                               ; preds = %.lr.ph
  %13 = sext i32 %.024 to i64
  %14 = getelementptr inbounds [20000 x i8], ptr @carr, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = icmp eq i8 %15, %9
  br i1 %16, label %17, label %19

17:                                               ; preds = %12
  %18 = add nsw i32 %.024, -1
  br label %23

19:                                               ; preds = %12
  %20 = add nuw nsw i32 %.024, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [20000 x i8], ptr @carr, i64 0, i64 %21
  store i8 %9, ptr %22, align 1, !tbaa !5
  br label %23

23:                                               ; preds = %17, %19, %11
  %.2 = phi i32 [ 0, %11 ], [ %18, %17 ], [ %20, %19 ]
  %.117 = getelementptr inbounds i8, ptr %.01623, i64 1
  %24 = load i8, ptr %.117, align 1, !tbaa !5
  %.not21 = icmp eq i8 %24, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %23
  %25 = add nsw i32 %.2, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [20000 x i8], ptr @carr, i64 0, i64 %26
  store i8 0, ptr %27, align 1, !tbaa !5
  br label %28

28:                                               ; preds = %2, %5, %1, %._crit_edge
  %.018 = phi ptr [ @carr, %._crit_edge ], [ null, %1 ], [ %0, %5 ], [ %0, %2 ]
  ret ptr %.018
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: read, 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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