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

; 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.CShape = type { i32, i32, i32 }
%class.CImage = type <{ %struct.CImageAttributes, %struct.CShape, [4 x i8], ptr, i32, i32, i32, [4 x i8], ptr, %class.CRefCntMem, i32, [4 x i8] }>
%struct.CImageAttributes = type { i32, [2 x i32], i32 }
%class.CRefCntMem = type { ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN6CShapeeqERKS_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12)) #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6CImage10ReAllocateE6CShapeRKSt9type_infoiPvbi(ptr noundef nonnull align 8 dereferenceable(76), i64, i32, ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, ptr noundef, i1 noundef zeroext, i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6CImage10ReAllocateE6CShapeRKSt9type_infoib(ptr noundef nonnull align 8 dereferenceable(76) %0, i64 %1, i32 %2, ptr noundef nonnull align 8 dereferenceable(16) %3, i32 noundef %4, i1 noundef zeroext %5) #2 align 2 {
  %7 = alloca %struct.CShape, align 4
  %8 = alloca { i64, i32 }, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i8, align 1
  %13 = alloca %struct.CShape, align 4
  %14 = alloca { i64, i32 }, align 4
  %15 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  store i64 %1, ptr %15, align 4
  %16 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  store i32 %2, ptr %16, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %8, i64 12, i1 false)
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  %17 = zext i1 %5 to i8
  store i8 %17, ptr %12, align 1, !tbaa !11
  %18 = load ptr, ptr %9, align 8
  %19 = load i8, ptr %12, align 1, !tbaa !11, !range !13, !noundef !14
  %20 = trunc i8 %19 to i1
  br i1 %20, label %35, label %21

21:                                               ; preds = %6
  %22 = getelementptr inbounds %class.CImage, ptr %18, i32 0, i32 1
  %23 = call noundef zeroext i1 @_ZN6CShapeeqERKS_(ptr noundef nonnull align 4 dereferenceable(12) %7, ptr noundef nonnull align 4 dereferenceable(12) %22)
  br i1 %23, label %24, label %35

24:                                               ; preds = %21
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.CImage, ptr %18, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = call noundef zeroext i1 @_ZNKSt9type_infoeqERKS_(ptr noundef nonnull align 8 dereferenceable(16) %25, ptr noundef nonnull align 8 dereferenceable(16) %27) #4
  br i1 %28, label %29, label %35

29:                                               ; preds = %24
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = getelementptr inbounds %class.CImage, ptr %18, i32 0, i32 4
  %32 = load i32, ptr %31, align 8, !tbaa !21
  %33 = icmp eq i32 %30, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  br label %42

35:                                               ; preds = %29, %24, %21, %6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %7, i64 12, i1 false), !tbaa.struct !22
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %13, i64 12, i1 false)
  %38 = getelementptr inbounds { i64, i32 }, ptr %14, i32 0, i32 0
  %39 = load i64, ptr %38, align 4
  %40 = getelementptr inbounds { i64, i32 }, ptr %14, i32 0, i32 1
  %41 = load i32, ptr %40, align 4
  call void @_ZN6CImage10ReAllocateE6CShapeRKSt9type_infoiPvbi(ptr noundef nonnull align 8 dereferenceable(76) %18, i64 %39, i32 %41, ptr noundef nonnull align 8 dereferenceable(16) %36, i32 noundef %37, ptr noundef null, i1 noundef zeroext true, i32 noundef 0)
  br label %42

42:                                               ; preds = %35, %34
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt9type_infoeqERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #4 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !6, i64 32}
!16 = !{!"_ZTS6CImage", !17, i64 0, !19, i64 16, !6, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !6, i64 56, !20, i64 64, !10, i64 72}
!17 = !{!"_ZTS16CImageAttributes", !10, i64 0, !7, i64 4, !18, i64 12}
!18 = !{!"_ZTS11EBorderMode", !7, i64 0}
!19 = !{!"_ZTS6CShape", !10, i64 0, !10, i64 4, !10, i64 8}
!20 = !{!"_ZTS10CRefCntMem", !6, i64 0}
!21 = !{!16, !10, i64 40}
!22 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9}


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

%struct.CShape = type { i32, i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN6CShapeeqERKS_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6CImage10ReAllocateE6CShapeRKSt9type_infoiPvbi(ptr noundef nonnull align 8 dereferenceable(76), i64, i32, ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, ptr noundef, i1 noundef zeroext, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6CImage10ReAllocateE6CShapeRKSt9type_infoib(ptr noundef nonnull align 8 dereferenceable(76) %0, i64 %1, i32 %2, ptr noundef nonnull align 8 dereferenceable(16) %3, i32 noundef %4, i1 noundef zeroext %5) local_unnamed_addr #1 align 2 {
  %7 = alloca %struct.CShape, align 8
  store i64 %1, ptr %7, align 8
  %.sroa.28.0..sroa_idx = getelementptr inbounds i8, ptr %7, i64 8
  store i32 %2, ptr %.sroa.28.0..sroa_idx, align 8
  br i1 %5, label %18, label %8

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = call noundef zeroext i1 @_ZN6CShapeeqERKS_(ptr noundef nonnull align 4 dereferenceable(12) %7, ptr noundef nonnull align 4 dereferenceable(12) %9)
  br i1 %10, label %11, label %18

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = call noundef zeroext i1 @_ZNKSt9type_infoeqERKS_(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(16) %13) #3
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  %16 = load i32, ptr %15, align 8
  %17 = icmp eq i32 %16, %4
  %or.cond = select i1 %14, i1 %17, i1 false
  br i1 %or.cond, label %19, label %18

18:                                               ; preds = %11, %8, %6
  %.sroa.01.0.copyload = load i64, ptr %7, align 8
  %.sroa.22.0.copyload = load i32, ptr %.sroa.28.0..sroa_idx, align 8, !tbaa !15
  call void @_ZN6CImage10ReAllocateE6CShapeRKSt9type_infoiPvbi(ptr noundef nonnull align 8 dereferenceable(76) %0, i64 %.sroa.01.0.copyload, i32 %.sroa.22.0.copyload, ptr noundef nonnull align 8 dereferenceable(16) %3, i32 noundef %4, ptr noundef null, i1 noundef zeroext true, i32 noundef 0)
  br label %19

19:                                               ; preds = %11, %18
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt9type_infoeqERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2 align 2

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" }
attributes #2 = { inlinehint 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 #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, !13, i64 32}
!6 = !{!"_ZTS6CImage", !7, i64 0, !12, i64 16, !13, i64 32, !8, i64 40, !8, i64 44, !8, i64 48, !13, i64 56, !14, i64 64, !8, i64 72}
!7 = !{!"_ZTS16CImageAttributes", !8, i64 0, !9, i64 4, !11, i64 12}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTS11EBorderMode", !9, i64 0}
!12 = !{!"_ZTS6CShape", !8, i64 0, !8, i64 4, !8, i64 8}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!"_ZTS10CRefCntMem", !13, i64 0}
!15 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass