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

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

@.str = external hidden unnamed_addr constant [48 x i8], align 1
@_ZTI6CError = external dso_local constant { ptr, ptr, ptr }, align 8

; 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) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6CImage10ReAllocateE6CShapeRKSt9type_infoiPvbi(ptr noundef nonnull align 8 dereferenceable(76) %0, i64 %1, i32 %2, ptr noundef nonnull align 8 dereferenceable(16) %3, i32 noundef %4, ptr noundef %5, i1 noundef zeroext %6, i32 noundef %7) #1 align 2 personality ptr @__gxx_personality_v0 {
  %9 = alloca %struct.CShape, align 4
  %10 = alloca { i64, i32 }, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i8, align 1
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  %20 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 0
  store i64 %1, ptr %20, align 4
  %21 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 1
  store i32 %2, ptr %21, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %10, i64 12, i1 false)
  store ptr %0, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store i32 %4, ptr %13, align 4, !tbaa !9
  store ptr %5, ptr %14, align 8, !tbaa !5
  %22 = zext i1 %6 to i8
  store i8 %22, ptr %15, align 1, !tbaa !11
  store i32 %7, ptr %16, align 4, !tbaa !9
  %23 = load ptr, ptr %11, align 8
  %24 = getelementptr inbounds %class.CImage, ptr %23, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %24, ptr align 4 %9, i64 12, i1 false), !tbaa.struct !13
  %25 = load ptr, ptr %12, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.CImage, ptr %23, i32 0, i32 3
  store ptr %25, ptr %26, align 8, !tbaa !14
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = getelementptr inbounds %class.CImage, ptr %23, i32 0, i32 4
  store i32 %27, ptr %28, align 8, !tbaa !20
  %29 = getelementptr inbounds %class.CImage, ptr %23, i32 0, i32 4
  %30 = load i32, ptr %29, align 8, !tbaa !20
  %31 = getelementptr inbounds %struct.CShape, ptr %9, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !21
  %33 = mul nsw i32 %30, %32
  %34 = getelementptr inbounds %class.CImage, ptr %23, i32 0, i32 5
  store i32 %33, ptr %34, align 4, !tbaa !22
  %35 = load i32, ptr %16, align 4, !tbaa !9
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %8
  %38 = load i32, ptr %16, align 4, !tbaa !9
  br label %47

39:                                               ; preds = %8
  %40 = getelementptr inbounds %class.CImage, ptr %23, i32 0, i32 5
  %41 = load i32, ptr %40, align 4, !tbaa !22
  %42 = getelementptr inbounds %struct.CShape, ptr %9, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !23
  %44 = mul nsw i32 %41, %43
  %45 = add nsw i32 %44, 7
  %46 = and i32 %45, -8
  br label %47

47:                                               ; preds = %39, %37
  %48 = phi i32 [ %38, %37 ], [ %46, %39 ]
  %49 = getelementptr inbounds %class.CImage, ptr %23, i32 0, i32 6
  store i32 %48, ptr %49, align 8, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #8
  %50 = getelementptr inbounds %class.CImage, ptr %23, i32 0, i32 6
  %51 = load i32, ptr %50, align 8, !tbaa !24
  %52 = getelementptr inbounds %struct.CShape, ptr %9, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !25
  %54 = mul nsw i32 %51, %53
  store i32 %54, ptr %17, align 4, !tbaa !9
  %55 = load ptr, ptr %14, align 8, !tbaa !5
  %56 = icmp eq ptr %55, null
  br i1 %56, label %57, label %81

57:                                               ; preds = %47
  %58 = load i32, ptr %17, align 4, !tbaa !9
  %59 = icmp sgt i32 %58, 0
  br i1 %59, label %60, label %81

60:                                               ; preds = %57
  %61 = load i32, ptr %17, align 4, !tbaa !9
  %62 = add nsw i32 %61, 7
  %63 = sdiv i32 %62, 8
  %64 = sext i32 %63 to i64
  %65 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %64, i64 8)
  %66 = extractvalue { i64, i1 } %65, 1
  %67 = extractvalue { i64, i1 } %65, 0
  %68 = select i1 %66, i64 -1, i64 %67
  %69 = call noalias noundef nonnull ptr @_Znam(i64 noundef %68) #9
  store ptr %69, ptr %14, align 8, !tbaa !5
  %70 = load ptr, ptr %14, align 8, !tbaa !5
  %71 = icmp eq ptr %70, null
  br i1 %71, label %72, label %80

72:                                               ; preds = %60
  %73 = call ptr @__cxa_allocate_exception(i64 1032) #8
  %74 = load i32, ptr %17, align 4, !tbaa !9
  invoke void @_ZN6CErrorC2EPKci(ptr noundef nonnull align 8 dereferenceable(1032) %73, ptr noundef @.str, i32 noundef %74)
          to label %75 unwind label %76

75:                                               ; preds = %72
  call void @__cxa_throw(ptr %73, ptr @_ZTI6CError, ptr @_ZNSt9exceptionD2Ev) #10
  unreachable

76:                                               ; preds = %72
  %77 = landingpad { ptr, i32 }
          cleanup
  %78 = extractvalue { ptr, i32 } %77, 0
  store ptr %78, ptr %18, align 8
  %79 = extractvalue { ptr, i32 } %77, 1
  store i32 %79, ptr %19, align 4
  call void @__cxa_free_exception(ptr %73) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #8
  br label %89

80:                                               ; preds = %60
  br label %81

81:                                               ; preds = %80, %57, %47
  %82 = load ptr, ptr %14, align 8, !tbaa !5
  %83 = getelementptr inbounds %class.CImage, ptr %23, i32 0, i32 8
  store ptr %82, ptr %83, align 8, !tbaa !26
  %84 = getelementptr inbounds %class.CImage, ptr %23, i32 0, i32 9
  %85 = load i32, ptr %17, align 4, !tbaa !9
  %86 = load ptr, ptr %14, align 8, !tbaa !5
  %87 = load i8, ptr %15, align 1, !tbaa !11, !range !27, !noundef !28
  %88 = trunc i8 %87 to i1
  call void @_ZN10CRefCntMem10ReAllocateEiPvbPFvS0_E(ptr noundef nonnull align 8 dereferenceable(8) %84, i32 noundef %85, ptr noundef %86, i1 noundef zeroext %88, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #8
  ret void

89:                                               ; preds = %76
  %90 = load ptr, ptr %18, align 8
  %91 = load i32, ptr %19, align 4
  %92 = insertvalue { ptr, i32 } poison, ptr %90, 0
  %93 = insertvalue { ptr, i32 } %92, i32 %91, 1
  resume { ptr, i32 } %93
}

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

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

declare ptr @__cxa_allocate_exception(i64)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6CErrorC2EPKci(ptr noundef nonnull align 8 dereferenceable(1032), ptr noundef, i32 noundef) unnamed_addr #5 align 2

declare void @__cxa_free_exception(ptr)

; Function Attrs: nounwind
declare void @_ZNSt9exceptionD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #6

declare void @__cxa_throw(ptr, ptr, ptr)

declare void @_ZN10CRefCntMem10ReAllocateEiPvbPFvS0_E(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef, ptr noundef, i1 noundef zeroext, ptr noundef) #7

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { 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 #6 = { nounwind "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 #7 = { "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 #8 = { nounwind }
attributes #9 = { builtin allocsize(0) }
attributes #10 = { noreturn }

!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 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9}
!14 = !{!15, !6, i64 32}
!15 = !{!"_ZTS6CImage", !16, i64 0, !18, i64 16, !6, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !6, i64 56, !19, i64 64, !10, i64 72}
!16 = !{!"_ZTS16CImageAttributes", !10, i64 0, !7, i64 4, !17, i64 12}
!17 = !{!"_ZTS11EBorderMode", !7, i64 0}
!18 = !{!"_ZTS6CShape", !10, i64 0, !10, i64 4, !10, i64 8}
!19 = !{!"_ZTS10CRefCntMem", !6, i64 0}
!20 = !{!15, !10, i64 40}
!21 = !{!18, !10, i64 8}
!22 = !{!15, !10, i64 44}
!23 = !{!18, !10, i64 0}
!24 = !{!15, !10, i64 48}
!25 = !{!18, !10, i64 4}
!26 = !{!15, !6, i64 56}
!27 = !{i8 0, i8 2}
!28 = !{}


; 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
define dso_local void @_ZN6CImage10ReAllocateE6CShapeRKSt9type_infoiPvbi(ptr noundef nonnull align 8 dereferenceable(76) %0, i64 %1, i32 %2, ptr noundef nonnull align 8 dereferenceable(16) %3, i32 noundef %4, ptr noundef %5, i1 noundef zeroext %6, i32 noundef %7) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %.sroa.014.sroa.3.0.extract.shift = lshr i64 %1, 32
  %.sroa.014.sroa.3.0.extract.trunc = trunc nuw i64 %.sroa.014.sroa.3.0.extract.shift to i32
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %1, ptr %9, align 8
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %2, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %3, ptr %10, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 %4, ptr %11, align 8, !tbaa !16
  %12 = mul nsw i32 %4, %2
  %13 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 %12, ptr %13, align 4, !tbaa !17
  %.not = icmp eq i32 %7, 0
  %.sroa.014.sroa.0.0.extract.trunc = trunc i64 %1 to i32
  %14 = mul nsw i32 %12, %.sroa.014.sroa.0.0.extract.trunc
  %15 = add nsw i32 %14, 7
  %16 = and i32 %15, -8
  %17 = select i1 %.not, i32 %16, i32 %7
  %18 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %17, ptr %18, align 8, !tbaa !18
  %19 = mul nsw i32 %17, %.sroa.014.sroa.3.0.extract.trunc
  %20 = icmp eq ptr %5, null
  %21 = icmp sgt i32 %19, 0
  %or.cond = select i1 %20, i1 %21, i1 false
  br i1 %or.cond, label %22, label %27

22:                                               ; preds = %8
  %23 = add nuw nsw i32 %19, 7
  %24 = and i32 %23, 2147483640
  %25 = zext nneg i32 %24 to i64
  %26 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %25) #3
  br label %27

27:                                               ; preds = %22, %8
  %.0 = phi ptr [ %26, %22 ], [ %5, %8 ]
  %28 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %.0, ptr %28, align 8, !tbaa !19
  %29 = getelementptr inbounds i8, ptr %0, i64 64
  tail call void @_ZN10CRefCntMem10ReAllocateEiPvbPFvS0_E(ptr noundef nonnull align 8 dereferenceable(8) %29, i32 noundef %19, ptr noundef %.0, i1 noundef zeroext %6, ptr noundef null)
  ret void
}

declare i32 @__gxx_personality_v0(...)

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

declare void @_ZN10CRefCntMem10ReAllocateEiPvbPFvS0_E(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef, ptr noundef, i1 noundef zeroext, ptr noundef) local_unnamed_addr #2

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


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