; LLVM IR from Wilson-ZheLin/Introduction-to-Digital-Image-Processing :: 2. Image Reduction, Enlargement and Negative/src (main)

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

22:                                               ; preds = %75, %2
  %23 = load i32, ptr %10, align 4, !tbaa !14
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Image, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = icmp slt i32 %23, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %22
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %78

29:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !14
  br label %30

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

36:                                               ; preds = %30
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %74

37:                                               ; preds = %30
  %38 = load i32, ptr %12, align 4, !tbaa !14
  %39 = sitofp i32 %38 to float
  %40 = load float, ptr %4, align 4, !tbaa !9
  %41 = fdiv float %39, %40
  %42 = call noundef float @_ZSt5roundf(float noundef %41)
  %43 = fptosi float %42 to i32
  store i32 %43, ptr %8, align 4, !tbaa !14
  %44 = load i32, ptr %10, align 4, !tbaa !14
  %45 = sitofp i32 %44 to float
  %46 = load float, ptr %4, align 4, !tbaa !9
  %47 = fdiv float %45, %46
  %48 = call noundef float @_ZSt5roundf(float noundef %47)
  %49 = fptosi float %48 to i32
  store i32 %49, ptr %9, align 4, !tbaa !14
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.Image, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !16
  %54 = load i32, ptr %9, align 4, !tbaa !14
  %55 = mul nsw i32 %53, %54
  %56 = load i32, ptr %8, align 4, !tbaa !14
  %57 = add nsw i32 %55, %56
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %50, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !17
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Image, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %63, align 8, !tbaa !16
  %65 = load i32, ptr %10, align 4, !tbaa !14
  %66 = mul nsw i32 %64, %65
  %67 = load i32, ptr %12, align 4, !tbaa !14
  %68 = add nsw i32 %66, %67
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %61, i64 %69
  store i8 %60, ptr %70, align 1, !tbaa !17
  br label %71

71:                                               ; preds = %37
  %72 = load i32, ptr %12, align 4, !tbaa !14
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %12, align 4, !tbaa !14
  br label %30, !llvm.loop !18

74:                                               ; preds = %36
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %10, align 4, !tbaa !14
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %10, align 4, !tbaa !14
  br label %22, !llvm.loop !20

78:                                               ; preds = %28
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %79
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5roundf(float noundef) #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 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS5Image", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16, !7, i64 24, !13, i64 1524}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 4}
!16 = !{!12, !13, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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.12 = external hidden unnamed_addr constant [21 x i8], align 1

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

.preheader.lr.ph:                                 ; preds = %2
  %11 = load i32, ptr %3, align 8, !tbaa !12
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.preheader, label %._crit_edge25

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %13 = phi i32 [ %18, %._crit_edge ], [ %9, %.preheader.lr.ph ]
  %14 = phi i32 [ %19, %._crit_edge ], [ %11, %.preheader.lr.ph ]
  %.02224 = phi i32 [ %20, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %16 = uitofp nneg i32 %.02224 to float
  %17 = fdiv float %16, %1
  br label %22

._crit_edge25:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %2
  ret ptr %3

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

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %18 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %13, %.preheader ]
  %19 = phi i32 [ %41, %._crit_edge.loopexit ], [ %14, %.preheader ]
  %20 = add nuw nsw i32 %.02224, 1
  %21 = icmp slt i32 %20, %18
  br i1 %21, label %.preheader, label %._crit_edge25, !llvm.loop !13

22:                                               ; preds = %.lr.ph, %22
  %.023 = phi i32 [ 0, %.lr.ph ], [ %40, %22 ]
  %23 = uitofp nneg i32 %.023 to float
  %24 = fdiv float %23, %1
  %25 = tail call noundef float @_ZSt5roundf(float noundef %24)
  %26 = fptosi float %25 to i32
  %27 = tail call noundef float @_ZSt5roundf(float noundef %17)
  %28 = fptosi float %27 to i32
  %29 = load i32, ptr %0, align 8, !tbaa !12
  %30 = mul nsw i32 %29, %28
  %31 = add nsw i32 %30, %26
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %5, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !16
  %35 = load i32, ptr %3, align 8, !tbaa !12
  %36 = mul nsw i32 %35, %.02224
  %37 = add nsw i32 %36, %.023
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %7, i64 %38
  store i8 %34, ptr %39, align 1, !tbaa !16
  %40 = add nuw nsw i32 %.023, 1
  %41 = load i32, ptr %3, align 8, !tbaa !12
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %22, label %._crit_edge.loopexit, !llvm.loop !17
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5roundf(float 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 = { 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" }

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


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