; LLVM IR from Wilson-ZheLin/Introduction-to-Digital-Image-Processing :: 3. Affine Transformation and Smoothing/src/main.ll (Z14Shear_verticalP5Image)

; 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.Image = type { i32, i32, i32, ptr, [15 x [100 x i8]], i32 }

@.str.10 = external hidden unnamed_addr constant [18 x i8], align 1

; 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 noundef ptr @_Z14Shear_verticalP5Image(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %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
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call noundef ptr @_Z14CreateNewImageP5ImagePci(ptr noundef %12, ptr noundef @.str.10, i32 noundef 1)
  store ptr %13, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Image, ptr %14, i32 0, i32 3
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Image, ptr %17, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  store ptr %19, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %20

20:                                               ; preds = %50, %1
  %21 = load i32, ptr %6, align 4, !tbaa !12
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Image, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !13
  %25 = icmp slt i32 %21, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %20
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %53

27:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !12
  br label %28

28:                                               ; preds = %46, %27
  %29 = load i32, ptr %8, align 4, !tbaa !12
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Image, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !14
  %33 = icmp slt i32 %29, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %28
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %49

35:                                               ; preds = %28
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.Image, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !14
  %40 = load i32, ptr %6, align 4, !tbaa !12
  %41 = mul nsw i32 %39, %40
  %42 = load i32, ptr %8, align 4, !tbaa !12
  %43 = add nsw i32 %41, %42
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %36, i64 %44
  store i8 0, ptr %45, align 1, !tbaa !15
  br label %46

46:                                               ; preds = %35
  %47 = load i32, ptr %8, align 4, !tbaa !12
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %8, align 4, !tbaa !12
  br label %28, !llvm.loop !16

49:                                               ; preds = %34
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %6, align 4, !tbaa !12
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %6, align 4, !tbaa !12
  br label %20, !llvm.loop !18

53:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !12
  br label %54

54:                                               ; preds = %113, %53
  %55 = load i32, ptr %9, align 4, !tbaa !12
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.Image, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 4, !tbaa !13
  %59 = icmp slt i32 %55, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %54
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %116

61:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !12
  br label %62

62:                                               ; preds = %109, %61
  %63 = load i32, ptr %10, align 4, !tbaa !12
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.Image, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 8, !tbaa !14
  %67 = icmp slt i32 %63, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %62
  store i32 11, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %112

69:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %70 = load i32, ptr %9, align 4, !tbaa !12
  %71 = sitofp i32 %70 to double
  %72 = load i32, ptr %10, align 4, !tbaa !12
  %73 = sitofp i32 %72 to float
  %74 = fpext float %73 to double
  %75 = call double @llvm.fmuladd.f64(double %74, double 5.000000e-01, double %71)
  %76 = call double @llvm.round.f64(double %75)
  %77 = fptosi double %76 to i32
  store i32 %77, ptr %11, align 4, !tbaa !12
  %78 = load i32, ptr %11, align 4, !tbaa !12
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.Image, ptr %79, i32 0, i32 1
  %81 = load i32, ptr %80, align 4, !tbaa !13
  %82 = icmp sge i32 %78, %81
  br i1 %82, label %83, label %84

83:                                               ; preds = %69
  store i32 13, ptr %7, align 4
  br label %106

84:                                               ; preds = %69
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.Image, ptr %86, i32 0, i32 0
  %88 = load i32, ptr %87, align 8, !tbaa !14
  %89 = load i32, ptr %9, align 4, !tbaa !12
  %90 = mul nsw i32 %88, %89
  %91 = load i32, ptr %10, align 4, !tbaa !12
  %92 = add nsw i32 %90, %91
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds i8, ptr %85, i64 %93
  %95 = load i8, ptr %94, align 1, !tbaa !15
  %96 = load ptr, ptr %4, align 8, !tbaa !5
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.Image, ptr %97, i32 0, i32 0
  %99 = load i32, ptr %98, align 8, !tbaa !14
  %100 = load i32, ptr %11, align 4, !tbaa !12
  %101 = mul nsw i32 %99, %100
  %102 = load i32, ptr %10, align 4, !tbaa !12
  %103 = add nsw i32 %101, %102
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds i8, ptr %96, i64 %104
  store i8 %95, ptr %105, align 1, !tbaa !15
  store i32 0, ptr %7, align 4
  br label %106

106:                                              ; preds = %84, %83
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %107 = load i32, ptr %7, align 4
  switch i32 %107, label %118 [
    i32 0, label %108
    i32 13, label %109
  ]

108:                                              ; preds = %106
  br label %109

109:                                              ; preds = %108, %106
  %110 = load i32, ptr %10, align 4, !tbaa !12
  %111 = add nsw i32 %110, 1
  store i32 %111, ptr %10, align 4, !tbaa !12
  br label %62, !llvm.loop !19

112:                                              ; preds = %68
  br label %113

113:                                              ; preds = %112
  %114 = load i32, ptr %9, align 4, !tbaa !12
  %115 = add nsw i32 %114, 1
  store i32 %115, ptr %9, align 4, !tbaa !12
  br label %54, !llvm.loop !20

116:                                              ; preds = %60
  %117 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %117

118:                                              ; preds = %106
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z14CreateNewImageP5ImagePci(ptr noundef, ptr noundef, i32 noundef) #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.round.f64(double) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !6, i64 16}
!10 = !{!"_ZTS5Image", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !7, i64 24, !11, i64 1524}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!10, !11, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}
!20 = distinct !{!20, !17}


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

@.str.10 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z14Shear_verticalP5Image(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef ptr @_Z14CreateNewImageP5ImagePci(ptr noundef %0, ptr noundef nonnull @.str.10, i32 noundef 1)
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %2, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %2, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.preheader38.lr.ph, label %.preheader37

.preheader38.lr.ph:                               ; preds = %1
  %10 = load i32, ptr %2, align 8, !tbaa !12
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.preheader38, label %.preheader37

.preheader38:                                     ; preds = %.preheader38.lr.ph, %._crit_edge
  %12 = phi i32 [ %20, %._crit_edge ], [ %8, %.preheader38.lr.ph ]
  %13 = phi i32 [ %21, %._crit_edge ], [ %10, %.preheader38.lr.ph ]
  %.040 = phi i32 [ %22, %._crit_edge ], [ 0, %.preheader38.lr.ph ]
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.preheader37:                                     ; preds = %._crit_edge, %.preheader38.lr.ph, %1
  %15 = getelementptr inbounds i8, ptr %0, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.preheader.lr.ph, label %._crit_edge45

.preheader.lr.ph:                                 ; preds = %.preheader37
  %18 = load i32, ptr %0, align 8, !tbaa !12
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.preheader, label %._crit_edge45

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %7, align 4, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader38
  %20 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %12, %.preheader38 ]
  %21 = phi i32 [ %30, %._crit_edge.loopexit ], [ %13, %.preheader38 ]
  %22 = add nuw nsw i32 %.040, 1
  %23 = icmp slt i32 %22, %20
  br i1 %23, label %.preheader38, label %.preheader37, !llvm.loop !13

.lr.ph:                                           ; preds = %.preheader38, %.lr.ph
  %24 = phi i32 [ %30, %.lr.ph ], [ %13, %.preheader38 ]
  %.03339 = phi i32 [ %29, %.lr.ph ], [ 0, %.preheader38 ]
  %25 = mul nsw i32 %24, %.040
  %26 = add nsw i32 %25, %.03339
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %6, i64 %27
  store i8 0, ptr %28, align 1, !tbaa !16
  %29 = add nuw nsw i32 %.03339, 1
  %30 = load i32, ptr %2, align 8, !tbaa !12
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !17

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge43
  %32 = phi i32 [ %37, %._crit_edge43 ], [ %16, %.preheader.lr.ph ]
  %33 = phi i32 [ %38, %._crit_edge43 ], [ %18, %.preheader.lr.ph ]
  %34 = phi i32 [ %39, %._crit_edge43 ], [ %18, %.preheader.lr.ph ]
  %.03244 = phi i32 [ %40, %._crit_edge43 ], [ 0, %.preheader.lr.ph ]
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %.lr.ph42, label %._crit_edge43

.lr.ph42:                                         ; preds = %.preheader
  %36 = uitofp nneg i32 %.03244 to double
  br label %42

._crit_edge45:                                    ; preds = %._crit_edge43, %.preheader.lr.ph, %.preheader37
  ret ptr %2

._crit_edge43.loopexit:                           ; preds = %62
  %.pre49 = load i32, ptr %15, align 4, !tbaa !11
  br label %._crit_edge43

._crit_edge43:                                    ; preds = %._crit_edge43.loopexit, %.preheader
  %37 = phi i32 [ %.pre49, %._crit_edge43.loopexit ], [ %32, %.preheader ]
  %38 = phi i32 [ %63, %._crit_edge43.loopexit ], [ %33, %.preheader ]
  %39 = phi i32 [ %63, %._crit_edge43.loopexit ], [ %34, %.preheader ]
  %40 = add nuw nsw i32 %.03244, 1
  %41 = icmp slt i32 %40, %37
  br i1 %41, label %.preheader, label %._crit_edge45, !llvm.loop !18

42:                                               ; preds = %.lr.ph42, %62
  %43 = phi i32 [ %33, %.lr.ph42 ], [ %63, %62 ]
  %44 = phi i32 [ %34, %.lr.ph42 ], [ %63, %62 ]
  %.03141 = phi i32 [ 0, %.lr.ph42 ], [ %64, %62 ]
  %45 = uitofp nneg i32 %.03141 to float
  %46 = fpext float %45 to double
  %47 = tail call double @llvm.fmuladd.f64(double %46, double 5.000000e-01, double %36)
  %48 = tail call double @llvm.round.f64(double %47)
  %49 = fptosi double %48 to i32
  %50 = load i32, ptr %7, align 4, !tbaa !11
  %.not = icmp sgt i32 %50, %49
  br i1 %.not, label %51, label %62

51:                                               ; preds = %42
  %52 = mul nsw i32 %44, %.03244
  %53 = add nsw i32 %52, %.03141
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i8, ptr %4, i64 %54
  %56 = load i8, ptr %55, align 1, !tbaa !16
  %57 = load i32, ptr %2, align 8, !tbaa !12
  %58 = mul nsw i32 %57, %49
  %59 = add nsw i32 %58, %.03141
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %6, i64 %60
  store i8 %56, ptr %61, align 1, !tbaa !16
  %.pre48 = load i32, ptr %0, align 8, !tbaa !12
  br label %62

62:                                               ; preds = %42, %51
  %63 = phi i32 [ %43, %42 ], [ %.pre48, %51 ]
  %64 = add nuw nsw i32 %.03141, 1
  %65 = icmp slt i32 %64, %63
  br i1 %65, label %42, label %._crit_edge43.loopexit, !llvm.loop !19
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z14CreateNewImageP5ImagePci(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.round.f64(double) #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 = { mustprogress 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, !10, i64 16}
!6 = !{!"_ZTS5Image", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !8, i64 24, !7, i64 1524}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 0}
!13 = distinct !{!13, !14, !15}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.unswitch.partial.disable"}
!16 = !{!8, !8, i64 0}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14, !15}
!19 = distinct !{!19, !14}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass