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

; 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 @_Z20ImageEnlarge_NearestP5Imagef(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 float, align 4
  %9 = alloca float, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = 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) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %14 = load float, ptr %4, align 4, !tbaa !9
  %15 = fcmp ole float %14, 1.000000e+00
  br i1 %15, label %16, label %19

16:                                               ; preds = %2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call noundef ptr @_Z14CreateNewImageP5ImagePcif(ptr noundef %17, ptr noundef @.str.12, i32 noundef 2, float noundef 3.000000e+00)
  store ptr %18, ptr %7, align 8, !tbaa !5
  br label %23

19:                                               ; preds = %2
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load float, ptr %4, align 4, !tbaa !9
  %22 = call noundef ptr @_Z14CreateNewImageP5ImagePcif(ptr noundef %20, ptr noundef @.str.12, i32 noundef 3, float noundef %21)
  store ptr %22, ptr %7, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %19, %16
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Image, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  store ptr %26, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Image, ptr %27, i32 0, i32 3
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  store ptr %29, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !14
  br label %30

30:                                               ; preds = %101, %23
  %31 = load i32, ptr %10, align 4, !tbaa !14
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Image, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !15
  %35 = sub nsw i32 %34, 1
  %36 = icmp slt i32 %31, %35
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %30
  %39 = load i32, ptr %10, align 4, !tbaa !14
  %40 = sitofp i32 %39 to float
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Image, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !15
  %44 = sitofp i32 %43 to float
  %45 = fdiv float %40, %44
  store float %45, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !14
  br label %46

46:                                               ; preds = %97, %38
  %47 = load i32, ptr %12, align 4, !tbaa !14
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Image, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !16
  %51 = sub nsw i32 %50, 1
  %52 = icmp slt i32 %47, %51
  br i1 %52, label %54, label %53

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

54:                                               ; preds = %46
  %55 = load i32, ptr %12, align 4, !tbaa !14
  %56 = sitofp i32 %55 to float
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Image, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !16
  %60 = sitofp i32 %59 to float
  %61 = fdiv float %56, %60
  store float %61, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %62 = load ptr, ptr %3, 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 = sitofp i32 %64 to float
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.Image, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !15
  %69 = sitofp i32 %68 to float
  %70 = load float, ptr %9, align 4, !tbaa !9
  %71 = fmul float %69, %70
  %72 = call noundef float @_ZSt5roundf(float noundef %71)
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.Image, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 8, !tbaa !16
  %76 = sitofp i32 %75 to float
  %77 = load float, ptr %8, align 4, !tbaa !9
  %78 = fmul float %76, %77
  %79 = call noundef float @_ZSt5roundf(float noundef %78)
  %80 = call float @llvm.fmuladd.f32(float %65, float %72, float %79)
  %81 = fptosi float %80 to i32
  store i32 %81, ptr %13, align 4, !tbaa !14
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = load i32, ptr %13, align 4, !tbaa !14
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i8, ptr %82, i64 %84
  %86 = load i8, ptr %85, align 1, !tbaa !17
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.Image, ptr %88, i32 0, i32 0
  %90 = load i32, ptr %89, align 8, !tbaa !16
  %91 = load i32, ptr %10, align 4, !tbaa !14
  %92 = mul nsw i32 %90, %91
  %93 = load i32, ptr %12, align 4, !tbaa !14
  %94 = add nsw i32 %92, %93
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds i8, ptr %87, i64 %95
  store i8 %86, ptr %96, align 1, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %97

97:                                               ; preds = %54
  %98 = load i32, ptr %12, align 4, !tbaa !14
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %12, align 4, !tbaa !14
  br label %46, !llvm.loop !18

100:                                              ; preds = %53
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %10, align 4, !tbaa !14
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %10, align 4, !tbaa !14
  br label %30, !llvm.loop !20

104:                                              ; preds = %37
  %105 = 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) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret ptr %105
}

; 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"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 @_Z20ImageEnlarge_NearestP5Imagef(ptr noundef %0, float noundef %1) local_unnamed_addr #0 {
  %3 = fcmp ugt float %1, 1.000000e+00
  br i1 %3, label %6, label %4

4:                                                ; preds = %2
  %5 = tail call noundef ptr @_Z14CreateNewImageP5ImagePcif(ptr noundef %0, ptr noundef nonnull @.str.12, i32 noundef 2, float noundef 3.000000e+00)
  br label %8

6:                                                ; preds = %2
  %7 = tail call noundef ptr @_Z14CreateNewImageP5ImagePcif(ptr noundef %0, ptr noundef nonnull @.str.12, i32 noundef 3, float noundef %1)
  br label %8

8:                                                ; preds = %6, %4
  %.0 = phi ptr [ %5, %4 ], [ %7, %6 ]
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %.0, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.0, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = icmp sgt i32 %14, 1
  br i1 %15, label %.lr.ph33, label %._crit_edge34

.lr.ph33:                                         ; preds = %8
  %16 = getelementptr inbounds i8, ptr %0, i64 4
  %17 = load i32, ptr %.0, align 8, !tbaa !12
  %18 = icmp sgt i32 %17, 1
  br i1 %18, label %.lr.ph33.split, label %._crit_edge34

._crit_edge34:                                    ; preds = %._crit_edge, %.lr.ph33, %8
  ret ptr %.0

.lr.ph33.split:                                   ; preds = %.lr.ph33, %._crit_edge
  %19 = phi i32 [ %25, %._crit_edge ], [ %14, %.lr.ph33 ]
  %20 = phi i32 [ %26, %._crit_edge ], [ %17, %.lr.ph33 ]
  %.02831 = phi i32 [ %27, %._crit_edge ], [ 0, %.lr.ph33 ]
  %21 = uitofp nneg i32 %.02831 to float
  %22 = sitofp i32 %19 to float
  %23 = fdiv float %21, %22
  %24 = icmp sgt i32 %20, 1
  br i1 %24, label %.lr.ph, label %._crit_edge

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

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph33.split
  %25 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %19, %.lr.ph33.split ]
  %26 = phi i32 [ %55, %._crit_edge.loopexit ], [ %20, %.lr.ph33.split ]
  %27 = add nuw nsw i32 %.02831, 1
  %28 = add nsw i32 %25, -1
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %.lr.ph33.split, label %._crit_edge34, !llvm.loop !13

.lr.ph:                                           ; preds = %.lr.ph33.split, %.lr.ph
  %30 = phi i32 [ %55, %.lr.ph ], [ %20, %.lr.ph33.split ]
  %.02730 = phi i32 [ %54, %.lr.ph ], [ 0, %.lr.ph33.split ]
  %31 = uitofp nneg i32 %.02730 to float
  %32 = sitofp i32 %30 to float
  %33 = fdiv float %31, %32
  %34 = load i32, ptr %0, align 8, !tbaa !12
  %35 = sitofp i32 %34 to float
  %36 = load i32, ptr %16, align 4, !tbaa !11
  %37 = sitofp i32 %36 to float
  %38 = fmul float %23, %37
  %39 = tail call noundef float @_ZSt5roundf(float noundef %38)
  %40 = load i32, ptr %0, align 8, !tbaa !12
  %41 = sitofp i32 %40 to float
  %42 = fmul float %33, %41
  %43 = tail call noundef float @_ZSt5roundf(float noundef %42)
  %44 = tail call float @llvm.fmuladd.f32(float %35, float %39, float %43)
  %45 = fptosi float %44 to i32
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %10, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !16
  %49 = load i32, ptr %.0, align 8, !tbaa !12
  %50 = mul nsw i32 %49, %.02831
  %51 = add nsw i32 %50, %.02730
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %12, i64 %52
  store i8 %48, ptr %53, align 1, !tbaa !16
  %54 = add nuw nsw i32 %.02730, 1
  %55 = load i32, ptr %.0, align 8, !tbaa !12
  %56 = add nsw i32 %55, -1
  %57 = icmp slt i32 %54, %56
  br i1 %57, label %.lr.ph, 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

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


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