; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (1047)

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

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

9:                                                ; preds = %56, %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !11
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %13, label %57

13:                                               ; preds = %9
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = icmp sge i32 %14, 1
  br i1 %15, label %16, label %33

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = sub nsw i32 %18, 1
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %17, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = sext i8 %22 to i32
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = sext i8 %25 to i32
  %27 = icmp eq i32 %23, %26
  br i1 %27, label %28, label %33

28:                                               ; preds = %16
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr %3, align 4, !tbaa !9
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i32 1
  store ptr %32, ptr %2, align 8, !tbaa !5
  br label %56

33:                                               ; preds = %16, %13
  %34 = load i32, ptr %3, align 4, !tbaa !9
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = sub nsw i32 %35, 1
  %37 = icmp eq i32 %34, %36
  br i1 %37, label %38, label %47

38:                                               ; preds = %33
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = sitofp i32 %39 to double
  %41 = fmul double %40, 1.500000e+00
  %42 = fptosi double %41 to i32
  store i32 %42, ptr %4, align 4, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = call ptr @realloc(ptr noundef %43, i64 noundef %45) #6
  store ptr %46, ptr %5, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %38, %33
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %2, align 8, !tbaa !5
  %50 = load i8, ptr %48, align 1, !tbaa !11
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load i32, ptr %3, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %3, align 4, !tbaa !9
  %54 = sext i32 %52 to i64
  %55 = getelementptr inbounds i8, ptr %51, i64 %54
  store i8 %50, ptr %55, align 1, !tbaa !11
  br label %56

56:                                               ; preds = %47, %28
  br label %9, !llvm.loop !12

57:                                               ; preds = %9
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load i32, ptr %3, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %58, i64 %60
  store i8 0, ptr %61, align 1, !tbaa !11
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret ptr %62
}

; 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: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

; 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 allocsize(1) "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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { nounwind allocsize(1) }

!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 = !{!7, !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"

; Function Attrs: nounwind uwtable
define dso_local noalias ptr @removeDuplicates(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = tail call noalias dereferenceable_or_null(20) ptr @malloc(i64 noundef 20) #3
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %.not26 = icmp eq i8 %3, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %26
  %4 = phi i8 [ %27, %26 ], [ %3, %1 ]
  %.030 = phi ptr [ %.2, %26 ], [ %2, %1 ]
  %.01829 = phi i32 [ %.220, %26 ], [ 20, %1 ]
  %.02128 = phi i32 [ %.122, %26 ], [ 0, %1 ]
  %.02327 = phi ptr [ %.124, %26 ], [ %0, %1 ]
  %5 = icmp sgt i32 %.02128, 0
  br i1 %5, label %6, label %12

6:                                                ; preds = %.lr.ph
  %7 = add nsw i32 %.02128, -1
  %8 = zext nneg i32 %7 to i64
  %9 = getelementptr inbounds i8, ptr %.030, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = icmp eq i8 %10, %4
  br i1 %11, label %26, label %12

12:                                               ; preds = %6, %.lr.ph
  %13 = add nsw i32 %.01829, -1
  %14 = icmp eq i32 %.02128, %13
  br i1 %14, label %15, label %21

15:                                               ; preds = %12
  %16 = sitofp i32 %.01829 to double
  %17 = fmul double %16, 1.500000e+00
  %18 = fptosi double %17 to i32
  %19 = sext i32 %18 to i64
  %20 = tail call ptr @realloc(ptr noundef %.030, i64 noundef %19) #4
  %.pre = load i8, ptr %.02327, align 1, !tbaa !5
  br label %21

21:                                               ; preds = %15, %12
  %22 = phi i8 [ %.pre, %15 ], [ %4, %12 ]
  %.119 = phi i32 [ %18, %15 ], [ %.01829, %12 ]
  %.1 = phi ptr [ %20, %15 ], [ %.030, %12 ]
  %23 = add nsw i32 %.02128, 1
  %24 = sext i32 %.02128 to i64
  %25 = getelementptr inbounds i8, ptr %.1, i64 %24
  store i8 %22, ptr %25, align 1, !tbaa !5
  br label %26

26:                                               ; preds = %6, %21
  %.122 = phi i32 [ %23, %21 ], [ %7, %6 ]
  %.220 = phi i32 [ %.119, %21 ], [ %.01829, %6 ]
  %.2 = phi ptr [ %.1, %21 ], [ %.030, %6 ]
  %.124 = getelementptr inbounds i8, ptr %.02327, i64 1
  %27 = load i8, ptr %.124, align 1, !tbaa !5
  %.not = icmp eq i8 %27, 0
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !8

._crit_edge.loopexit:                             ; preds = %26
  %28 = sext i32 %.122 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.021.lcssa = phi i64 [ 0, %1 ], [ %28, %._crit_edge.loopexit ]
  %.0.lcssa = phi ptr [ %2, %1 ], [ %.2, %._crit_edge.loopexit ]
  %29 = getelementptr inbounds i8, ptr %.0.lcssa, i64 %.021.lcssa
  store i8 0, ptr %29, align 1, !tbaa !5
  ret ptr %.0.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

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

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 = { 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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) 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 #3 = { nounwind allocsize(0) }
attributes #4 = { nounwind allocsize(1) }

!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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass