; LLVM IR from cornell-zhang/rosetta :: optical-flow/imageLib/RefCntMem.ll (ZN10CRefCntMem10ReAllocateEiPvbPFvS0_E)

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

%class.CRefCntMem = type { ptr }
%struct.CRefCntMemPtr = type { ptr, i32, i32, i8, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10CRefCntMem14DecrementCountEv(ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10CRefCntMem10ReAllocateEiPvbPFvS0_E(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1, ptr noundef %2, i1 noundef zeroext %3, ptr noundef %4) #0 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  %11 = zext i1 %3 to i8
  store i8 %11, ptr %9, align 1, !tbaa !11
  store ptr %4, ptr %10, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8
  call void @_ZN10CRefCntMem14DecrementCountEv(ptr noundef nonnull align 8 dereferenceable(8) %12)
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %39

15:                                               ; preds = %5
  %16 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #2
  %17 = getelementptr inbounds %class.CRefCntMem, ptr %12, i32 0, i32 0
  store ptr %16, ptr %17, align 8, !tbaa !13
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = getelementptr inbounds %class.CRefCntMem, ptr %12, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds %struct.CRefCntMemPtr, ptr %20, i32 0, i32 2
  store i32 %18, ptr %21, align 4, !tbaa !15
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %class.CRefCntMem, ptr %12, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = getelementptr inbounds %struct.CRefCntMemPtr, ptr %24, i32 0, i32 0
  store ptr %22, ptr %25, align 8, !tbaa !17
  %26 = load i8, ptr %9, align 1, !tbaa !11, !range !18, !noundef !19
  %27 = trunc i8 %26 to i1
  %28 = getelementptr inbounds %class.CRefCntMem, ptr %12, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = getelementptr inbounds %struct.CRefCntMemPtr, ptr %29, i32 0, i32 3
  %31 = zext i1 %27 to i8
  store i8 %31, ptr %30, align 8, !tbaa !20
  %32 = getelementptr inbounds %class.CRefCntMem, ptr %12, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = getelementptr inbounds %struct.CRefCntMemPtr, ptr %33, i32 0, i32 1
  store i32 1, ptr %34, align 8, !tbaa !21
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %class.CRefCntMem, ptr %12, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  %38 = getelementptr inbounds %struct.CRefCntMemPtr, ptr %37, i32 0, i32 4
  store ptr %35, ptr %38, align 8, !tbaa !22
  br label %41

39:                                               ; preds = %5
  %40 = getelementptr inbounds %class.CRefCntMem, ptr %12, i32 0, i32 0
  store ptr null, ptr %40, align 8, !tbaa !13
  br label %41

41:                                               ; preds = %39, %15
  ret void
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #1

attributes #0 = { 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 #1 = { nobuiltin 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 #2 = { builtin allocsize(0) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS10CRefCntMem", !6, i64 0}
!15 = !{!16, !10, i64 12}
!16 = !{!"_ZTS13CRefCntMemPtr", !6, i64 0, !10, i64 8, !10, i64 12, !12, i64 16, !6, i64 24}
!17 = !{!16, !6, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!16, !12, i64 16}
!21 = !{!16, !10, i64 8}
!22 = !{!16, !6, i64 24}


; 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 uwtable
declare dso_local void @_ZN10CRefCntMem14DecrementCountEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10CRefCntMem10ReAllocateEiPvbPFvS0_E(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1, ptr noundef %2, i1 noundef zeroext %3, ptr noundef %4) local_unnamed_addr #0 align 2 {
  tail call void @_ZN10CRefCntMem14DecrementCountEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %13, label %6

6:                                                ; preds = %5
  %7 = zext i1 %3 to i8
  %8 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #2
  %9 = getelementptr inbounds i8, ptr %8, i64 12
  store i32 %1, ptr %9, align 4, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %8, i64 16
  store i8 %7, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %8, i64 8
  store i32 1, ptr %11, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %8, i64 24
  store ptr %4, ptr %12, align 8, !tbaa !15
  br label %13

13:                                               ; preds = %5, %6
  %.sink = phi ptr [ %8, %6 ], [ null, %5 ]
  store ptr %.sink, ptr %0, align 8
  ret void
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { nobuiltin 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 #2 = { builtin allocsize(0) }

!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 12}
!6 = !{!"_ZTS13CRefCntMemPtr", !7, i64 0, !10, i64 8, !10, i64 12, !11, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !11, i64 16}
!14 = !{!6, !10, i64 8}
!15 = !{!6, !7, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,SROAPass,TailCallElimPass