; LLVM IR from KhawajaAbaid/machine-learning-in-c :: datasets (normalize_mnist_images)

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

; 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: nounwind uwtable
define dso_local ptr @normalize_mnist_images(ptr noundef %0, i64 noundef %1, i64 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = mul i64 %11, %12
  %14 = call noalias ptr @calloc(i64 noundef %13, i64 noundef 8) #4
  store ptr %14, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %51, %4
  %16 = load i64, ptr %10, align 8, !tbaa !9
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = mul i64 %17, %18
  %20 = icmp ult i64 %16, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %54

22:                                               ; preds = %15
  %23 = load i32, ptr %8, align 4, !tbaa !11
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %38

25:                                               ; preds = %22
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i64, ptr %10, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %26, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !13
  %30 = zext i8 %29 to i32
  %31 = sitofp i32 %30 to float
  %32 = fsub float %31, 1.275000e+02
  %33 = fdiv float %32, 1.275000e+02
  %34 = fpext float %33 to double
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load i64, ptr %10, align 8, !tbaa !9
  %37 = getelementptr inbounds double, ptr %35, i64 %36
  store double %34, ptr %37, align 8, !tbaa !14
  br label %50

38:                                               ; preds = %22
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i64, ptr %10, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = zext i8 %42 to i32
  %44 = sitofp i32 %43 to float
  %45 = fdiv float %44, 2.550000e+02
  %46 = fpext float %45 to double
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load i64, ptr %10, align 8, !tbaa !9
  %49 = getelementptr inbounds double, ptr %47, i64 %48
  store double %46, ptr %49, align 8, !tbaa !14
  br label %50

50:                                               ; preds = %38, %25
  br label %51

51:                                               ; preds = %50
  %52 = load i64, ptr %10, align 8, !tbaa !9
  %53 = add i64 %52, 1
  store i64 %53, ptr %10, align 8, !tbaa !9
  br label %15, !llvm.loop !16

54:                                               ; preds = %21
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret ptr %55
}

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nounwind allocsize(0,1) "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 }
attributes #4 = { nounwind allocsize(0,1) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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: nofree nounwind memory(write, argmem: read, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @normalize_mnist_images(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = mul i64 %2, %1
  %6 = tail call noalias ptr @calloc(i64 noundef %5, i64 noundef 8) #2
  %.not16 = icmp eq i64 %5, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %.not = icmp eq i32 %3, 0
  %min.iters.check23 = icmp eq i64 %5, 1
  br i1 %.not, label %.lr.ph.split.us.preheader, label %.lr.ph.split.preheader

.lr.ph.split.preheader:                           ; preds = %.lr.ph
  br i1 %min.iters.check23, label %.lr.ph.split.preheader34, label %vector.ph

.lr.ph.split.preheader34:                         ; preds = %middle.block, %.lr.ph.split.preheader
  %.015.ph = phi i64 [ 0, %.lr.ph.split.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.split

vector.ph:                                        ; preds = %.lr.ph.split.preheader
  %n.vec = and i64 %5, -2
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %7 = getelementptr inbounds i8, ptr %0, i64 %index
  %wide.load = load <2 x i8>, ptr %7, align 1, !tbaa !5
  %8 = uitofp <2 x i8> %wide.load to <2 x float>
  %9 = fadd <2 x float> %8, <float -1.275000e+02, float -1.275000e+02>
  %10 = fdiv <2 x float> %9, <float 1.275000e+02, float 1.275000e+02>
  %11 = fpext <2 x float> %10 to <2 x double>
  %12 = getelementptr inbounds double, ptr %6, i64 %index
  store <2 x double> %11, ptr %12, align 8, !tbaa !8
  %index.next = add nuw i64 %index, 2
  %13 = icmp eq i64 %index.next, %n.vec
  br i1 %13, label %middle.block, label %vector.body, !llvm.loop !10

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %5, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.split.preheader34

.lr.ph.split.us.preheader:                        ; preds = %.lr.ph
  br i1 %min.iters.check23, label %.lr.ph.split.us.preheader33, label %vector.ph24

vector.ph24:                                      ; preds = %.lr.ph.split.us.preheader
  %n.vec26 = and i64 %5, -2
  br label %vector.body28

vector.body28:                                    ; preds = %vector.body28, %vector.ph24
  %index29 = phi i64 [ 0, %vector.ph24 ], [ %index.next31, %vector.body28 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 %index29
  %wide.load30 = load <2 x i8>, ptr %14, align 1, !tbaa !5
  %15 = uitofp <2 x i8> %wide.load30 to <2 x float>
  %16 = fdiv <2 x float> %15, <float 2.550000e+02, float 2.550000e+02>
  %17 = fpext <2 x float> %16 to <2 x double>
  %18 = getelementptr inbounds double, ptr %6, i64 %index29
  store <2 x double> %17, ptr %18, align 8, !tbaa !8
  %index.next31 = add nuw i64 %index29, 2
  %19 = icmp eq i64 %index.next31, %n.vec26
  br i1 %19, label %middle.block21, label %vector.body28, !llvm.loop !14

middle.block21:                                   ; preds = %vector.body28
  %cmp.n32 = icmp eq i64 %5, %n.vec26
  br i1 %cmp.n32, label %._crit_edge, label %.lr.ph.split.us.preheader33

.lr.ph.split.us.preheader33:                      ; preds = %middle.block21, %.lr.ph.split.us.preheader
  %.015.us.ph = phi i64 [ 0, %.lr.ph.split.us.preheader ], [ %n.vec26, %middle.block21 ]
  br label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us.preheader33, %.lr.ph.split.us
  %.015.us = phi i64 [ %26, %.lr.ph.split.us ], [ %.015.us.ph, %.lr.ph.split.us.preheader33 ]
  %20 = getelementptr inbounds i8, ptr %0, i64 %.015.us
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = uitofp i8 %21 to float
  %23 = fdiv float %22, 2.550000e+02
  %24 = fpext float %23 to double
  %25 = getelementptr inbounds double, ptr %6, i64 %.015.us
  store double %24, ptr %25, align 8, !tbaa !8
  %26 = add nuw i64 %.015.us, 1
  %exitcond18.not = icmp eq i64 %26, %5
  br i1 %exitcond18.not, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph.split, %.lr.ph.split.us, %middle.block, %middle.block21, %4
  ret ptr %6

.lr.ph.split:                                     ; preds = %.lr.ph.split.preheader34, %.lr.ph.split
  %.015 = phi i64 [ %34, %.lr.ph.split ], [ %.015.ph, %.lr.ph.split.preheader34 ]
  %27 = getelementptr inbounds i8, ptr %0, i64 %.015
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = uitofp i8 %28 to float
  %30 = fadd float %29, -1.275000e+02
  %31 = fdiv float %30, 1.275000e+02
  %32 = fpext float %31 to double
  %33 = getelementptr inbounds double, ptr %6, i64 %.015
  store double %32, ptr %33, align 8, !tbaa !8
  %34 = add nuw i64 %.015, 1
  %exitcond.not = icmp eq i64 %34, %5
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !16
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { nofree nounwind memory(write, argmem: read, inaccessiblemem: readwrite) 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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind allocsize(0,1) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"double", !6, i64 0}
!10 = distinct !{!10, !11, !12, !13}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !11, !12, !13}
!15 = distinct !{!15, !11, !13, !12}
!16 = distinct !{!16, !11, !13, !12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass