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

; 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.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 }
%struct.CShape = type { i32, i32, i32 }
%class.CRefCntMem = type { 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 uwtable
define dso_local void @_ZN6CImage11SetSubImageEiiii(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = call noundef ptr @_ZN6CImage12PixelAddressEiii(ptr noundef nonnull align 8 dereferenceable(76) %13, i32 noundef %14, i32 noundef %15, i32 noundef 0)
  %17 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 8
  store ptr %16, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %18 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %19 = getelementptr inbounds %struct.CShape, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !17
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = add nsw i32 %21, %22
  %24 = icmp slt i32 %20, %23
  br i1 %24, label %25, label %29

25:                                               ; preds = %5
  %26 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %27 = getelementptr inbounds %struct.CShape, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !17
  br label %33

29:                                               ; preds = %5
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = add nsw i32 %30, %31
  br label %33

33:                                               ; preds = %29, %25
  %34 = phi i32 [ %28, %25 ], [ %32, %29 ]
  store i32 %34, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %35 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %36 = getelementptr inbounds %struct.CShape, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !18
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = add nsw i32 %38, %39
  %41 = icmp slt i32 %37, %40
  br i1 %41, label %42, label %46

42:                                               ; preds = %33
  %43 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %44 = getelementptr inbounds %struct.CShape, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !18
  br label %50

46:                                               ; preds = %33
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = add nsw i32 %47, %48
  br label %50

50:                                               ; preds = %46, %42
  %51 = phi i32 [ %45, %42 ], [ %49, %46 ]
  store i32 %51, ptr %12, align 4, !tbaa !9
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %54 = getelementptr inbounds %struct.CShape, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !17
  %56 = icmp slt i32 %52, %55
  br i1 %56, label %57, label %59

57:                                               ; preds = %50
  %58 = load i32, ptr %7, align 4, !tbaa !9
  br label %63

59:                                               ; preds = %50
  %60 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %61 = getelementptr inbounds %struct.CShape, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !17
  br label %63

63:                                               ; preds = %59, %57
  %64 = phi i32 [ %58, %57 ], [ %62, %59 ]
  %65 = icmp sgt i32 0, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %63
  br label %81

67:                                               ; preds = %63
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %70 = getelementptr inbounds %struct.CShape, ptr %69, i32 0, i32 0
  %71 = load i32, ptr %70, align 8, !tbaa !17
  %72 = icmp slt i32 %68, %71
  br i1 %72, label %73, label %75

73:                                               ; preds = %67
  %74 = load i32, ptr %7, align 4, !tbaa !9
  br label %79

75:                                               ; preds = %67
  %76 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %77 = getelementptr inbounds %struct.CShape, ptr %76, i32 0, i32 0
  %78 = load i32, ptr %77, align 8, !tbaa !17
  br label %79

79:                                               ; preds = %75, %73
  %80 = phi i32 [ %74, %73 ], [ %78, %75 ]
  br label %81

81:                                               ; preds = %79, %66
  %82 = phi i32 [ 0, %66 ], [ %80, %79 ]
  store i32 %82, ptr %7, align 4, !tbaa !9
  %83 = load i32, ptr %8, align 4, !tbaa !9
  %84 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %85 = getelementptr inbounds %struct.CShape, ptr %84, i32 0, i32 1
  %86 = load i32, ptr %85, align 4, !tbaa !18
  %87 = icmp slt i32 %83, %86
  br i1 %87, label %88, label %90

88:                                               ; preds = %81
  %89 = load i32, ptr %8, align 4, !tbaa !9
  br label %94

90:                                               ; preds = %81
  %91 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %92 = getelementptr inbounds %struct.CShape, ptr %91, i32 0, i32 1
  %93 = load i32, ptr %92, align 4, !tbaa !18
  br label %94

94:                                               ; preds = %90, %88
  %95 = phi i32 [ %89, %88 ], [ %93, %90 ]
  %96 = icmp sgt i32 0, %95
  br i1 %96, label %97, label %98

97:                                               ; preds = %94
  br label %112

98:                                               ; preds = %94
  %99 = load i32, ptr %8, align 4, !tbaa !9
  %100 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %101 = getelementptr inbounds %struct.CShape, ptr %100, i32 0, i32 1
  %102 = load i32, ptr %101, align 4, !tbaa !18
  %103 = icmp slt i32 %99, %102
  br i1 %103, label %104, label %106

104:                                              ; preds = %98
  %105 = load i32, ptr %8, align 4, !tbaa !9
  br label %110

106:                                              ; preds = %98
  %107 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %108 = getelementptr inbounds %struct.CShape, ptr %107, i32 0, i32 1
  %109 = load i32, ptr %108, align 4, !tbaa !18
  br label %110

110:                                              ; preds = %106, %104
  %111 = phi i32 [ %105, %104 ], [ %109, %106 ]
  br label %112

112:                                              ; preds = %110, %97
  %113 = phi i32 [ 0, %97 ], [ %111, %110 ]
  store i32 %113, ptr %8, align 4, !tbaa !9
  %114 = load i32, ptr %11, align 4, !tbaa !9
  %115 = load i32, ptr %7, align 4, !tbaa !9
  %116 = sub nsw i32 %114, %115
  %117 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %118 = getelementptr inbounds %struct.CShape, ptr %117, i32 0, i32 0
  store i32 %116, ptr %118, align 8, !tbaa !17
  %119 = load i32, ptr %12, align 4, !tbaa !9
  %120 = load i32, ptr %8, align 4, !tbaa !9
  %121 = sub nsw i32 %119, %120
  %122 = getelementptr inbounds %class.CImage, ptr %13, i32 0, i32 1
  %123 = getelementptr inbounds %struct.CShape, ptr %122, i32 0, i32 1
  store i32 %121, ptr %123, align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN6CImage12PixelAddressEiii(ptr noundef nonnull align 8 dereferenceable(76), i32 noundef, i32 noundef, i32 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync 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 = { 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, !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, !6, i64 56}
!12 = !{!"_ZTS6CImage", !13, i64 0, !15, i64 16, !6, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !6, i64 56, !16, i64 64, !10, i64 72}
!13 = !{!"_ZTS16CImageAttributes", !10, i64 0, !7, i64 4, !14, i64 12}
!14 = !{!"_ZTS11EBorderMode", !7, i64 0}
!15 = !{!"_ZTS6CShape", !10, i64 0, !10, i64 4, !10, i64 8}
!16 = !{!"_ZTS10CRefCntMem", !6, i64 0}
!17 = !{!12, !10, i64 16}
!18 = !{!12, !10, i64 20}


; 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
define dso_local void @_ZN6CImage11SetSubImageEiiii(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 align 2 {
  %6 = tail call noundef ptr @_ZN6CImage12PixelAddressEiii(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef %1, i32 noundef %2, i32 noundef 0)
  %7 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %6, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i32, ptr %8, align 8
  %10 = add nsw i32 %3, %1
  %. = tail call i32 @llvm.smin.i32(i32 %9, i32 %10)
  %11 = getelementptr inbounds i8, ptr %0, i64 20
  %12 = load i32, ptr %11, align 4
  %13 = add nsw i32 %4, %2
  %14 = tail call i32 @llvm.smin.i32(i32 %12, i32 %13)
  %15 = tail call i32 @llvm.smin.i32(i32 %9, i32 %1)
  %16 = tail call i32 @llvm.smax.i32(i32 %15, i32 0)
  %17 = tail call i32 @llvm.smin.i32(i32 %12, i32 %2)
  %18 = tail call i32 @llvm.smax.i32(i32 %17, i32 0)
  %19 = sub nsw i32 %., %16
  store i32 %19, ptr %8, align 8, !tbaa !15
  %20 = sub nsw i32 %14, %18
  store i32 %20, ptr %11, align 4, !tbaa !16
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN6CImage12PixelAddressEiii(ptr noundef nonnull align 8 dereferenceable(76), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 56}
!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 = !{!6, !8, i64 16}
!16 = !{!6, !8, i64 20}


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