; LLVM IR from venumb/ZSPACE :: cpp/depends/alglib/cpp/src/ap.ll (ZN11alglib_impl18ae_smart_ptr_clearEPv)

; 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.alglib_impl::ae_smart_ptr" = type { ptr, ptr, i8, i8, ptr, %"struct.alglib_impl::ae_dyn_block" }
%"struct.alglib_impl::ae_dyn_block" = type { ptr, ptr, ptr, 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: mustprogress nounwind uwtable
declare dso_local void @_ZN11alglib_impl7ae_freeEPv(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl18ae_smart_ptr_clearEPv(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %4, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %"struct.alglib_impl::ae_smart_ptr", ptr %5, i32 0, i32 2
  %7 = load i8, ptr %6, align 8, !tbaa !9, !range !13, !noundef !14
  %8 = trunc i8 %7 to i1
  br i1 %8, label %9, label %30

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %"struct.alglib_impl::ae_smart_ptr", ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %30

14:                                               ; preds = %9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.alglib_impl::ae_smart_ptr", ptr %15, i32 0, i32 4
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.alglib_impl::ae_smart_ptr", ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  call void %17(ptr noundef %20)
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.alglib_impl::ae_smart_ptr", ptr %21, i32 0, i32 3
  %23 = load i8, ptr %22, align 1, !tbaa !17, !range !13, !noundef !14
  %24 = trunc i8 %23 to i1
  br i1 %24, label %25, label %29

25:                                               ; preds = %14
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.alglib_impl::ae_smart_ptr", ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  call void @_ZN11alglib_impl7ae_freeEPv(ptr noundef %28)
  br label %29

29:                                               ; preds = %25, %14
  br label %30

30:                                               ; preds = %29, %9, %1
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.alglib_impl::ae_smart_ptr", ptr %31, i32 0, i32 2
  store i8 0, ptr %32, align 8, !tbaa !9
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.alglib_impl::ae_smart_ptr", ptr %33, i32 0, i32 3
  store i8 0, ptr %34, align 1, !tbaa !17
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.alglib_impl::ae_smart_ptr", ptr %35, i32 0, i32 1
  store ptr null, ptr %36, align 8, !tbaa !15
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.alglib_impl::ae_smart_ptr", ptr %37, i32 0, i32 4
  store ptr null, ptr %38, align 8, !tbaa !16
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.alglib_impl::ae_smart_ptr", ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %47

43:                                               ; preds = %30
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.alglib_impl::ae_smart_ptr", ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  store ptr null, ptr %46, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %43, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !11, i64 16}
!10 = !{!"_ZTSN11alglib_impl12ae_smart_ptrE", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 17, !6, i64 24, !12, i64 32}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!10, !6, i64 8}
!16 = !{!10, !6, i64 24}
!17 = !{!10, !11, i64 17}
!18 = !{!10, !6, i64 0}


; 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 uwtable
declare dso_local void @_ZN11alglib_impl7ae_freeEPv(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl18ae_smart_ptr_clearEPv(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i8, ptr %2, align 8, !tbaa !5, !range !12, !noundef !13
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %5, label %16

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %16, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  tail call void %10(ptr noundef nonnull %7)
  %11 = getelementptr inbounds i8, ptr %0, i64 17
  %12 = load i8, ptr %11, align 1, !tbaa !16, !range !12, !noundef !13
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %14, label %16

14:                                               ; preds = %8
  %15 = load ptr, ptr %6, align 8, !tbaa !14
  tail call void @_ZN11alglib_impl7ae_freeEPv(ptr noundef %15)
  br label %16

16:                                               ; preds = %8, %14, %5, %1
  store i8 0, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 17
  store i8 0, ptr %17, align 1, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %18, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr null, ptr %19, align 8, !tbaa !15
  %20 = load ptr, ptr %0, align 8, !tbaa !17
  %.not14 = icmp eq ptr %20, null
  br i1 %.not14, label %22, label %21

21:                                               ; preds = %16
  store ptr null, ptr %20, align 8, !tbaa !18
  br label %22

22:                                               ; preds = %21, %16
  ret void
}

attributes #0 = { 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 #1 = { mustprogress 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, !10, i64 16}
!6 = !{!"_ZTSN11alglib_impl12ae_smart_ptrE", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 17, !7, i64 24, !11, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !7, i64 24}
!16 = !{!6, !10, i64 17}
!17 = !{!6, !7, i64 0}
!18 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass