; LLVM IR from rdguez-mariano/fast_imas_IPOL :: io_png (io_png)

; 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: nounwind uwtable
declare hidden ptr @read_png_raw(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @read_png_f32_rgb(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call ptr @read_png_raw(ptr noundef %15, ptr noundef %16, ptr noundef %17, ptr noundef %8, i32 noundef 2, i32 noundef 2)
  store ptr %18, ptr %9, align 8, !tbaa !5
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp eq ptr null, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %76

22:                                               ; preds = %3
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = icmp eq i64 3, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %22
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %26, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %76

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = mul i64 3, %30
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = mul i64 %31, %33
  %35 = mul i64 %34, 4
  %36 = call ptr @realloc(ptr noundef %28, i64 noundef %35) #4
  store ptr %36, ptr %9, align 8, !tbaa !5
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %37, ptr %11, align 8, !tbaa !5
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = mul i64 %40, %42
  %44 = getelementptr inbounds float, ptr %38, i64 %43
  store ptr %44, ptr %14, align 8, !tbaa !5
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = mul i64 %47, %49
  %51 = getelementptr inbounds float, ptr %45, i64 %50
  store ptr %51, ptr %12, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i64, ptr %53, align 8, !tbaa !9
  %55 = mul i64 2, %54
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load i64, ptr %56, align 8, !tbaa !9
  %58 = mul i64 %55, %57
  %59 = getelementptr inbounds float, ptr %52, i64 %58
  store ptr %59, ptr %13, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %64, %27
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  %63 = icmp ult ptr %61, %62
  br i1 %63, label %64, label %74

64:                                               ; preds = %60
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = load float, ptr %65, align 4, !tbaa !11
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  %68 = getelementptr inbounds float, ptr %67, i32 1
  store ptr %68, ptr %12, align 8, !tbaa !5
  store float %66, ptr %67, align 4, !tbaa !11
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = getelementptr inbounds float, ptr %69, i32 1
  store ptr %70, ptr %11, align 8, !tbaa !5
  %71 = load float, ptr %69, align 4, !tbaa !11
  %72 = load ptr, ptr %13, align 8, !tbaa !5
  %73 = getelementptr inbounds float, ptr %72, i32 1
  store ptr %73, ptr %13, align 8, !tbaa !5
  store float %71, ptr %72, align 4, !tbaa !11
  br label %60, !llvm.loop !13

74:                                               ; preds = %60
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %75, ptr %4, align 8
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %76

76:                                               ; preds = %74, %25, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %77 = load ptr, ptr %4, align 8
  ret ptr %77
}

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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(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 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: nounwind uwtable
declare hidden ptr @read_png_raw(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @read_png_f32_rgb(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %5 = call ptr @read_png_raw(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef nonnull %4, i32 noundef 2, i32 noundef 2)
  %6 = icmp eq ptr %5, null
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %3
  %8 = load i64, ptr %4, align 8, !tbaa !5
  %9 = icmp eq i64 %8, 3
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %7
  %11 = load i64, ptr %1, align 8, !tbaa !5
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = mul i64 %11, 12
  %14 = mul i64 %13, %12
  %15 = call ptr @realloc(ptr noundef nonnull %5, i64 noundef %14) #5
  %16 = load i64, ptr %1, align 8, !tbaa !5
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = mul i64 %17, %16
  %19 = getelementptr float, ptr %15, i64 %18
  %20 = icmp sgt i64 %18, 0
  br i1 %20, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %10
  %21 = ptrtoint ptr %15 to i64
  %22 = shl i64 %16, 1
  %23 = mul i64 %22, %17
  %24 = getelementptr float, ptr %15, i64 %23
  %25 = mul i64 %17, %16
  %26 = shl i64 %25, 2
  %27 = add i64 %26, %21
  %28 = add i64 %21, 4
  %umax = call i64 @llvm.umax.i64(i64 %27, i64 %28)
  %29 = xor i64 %21, -1
  %30 = add i64 %umax, %29
  %31 = lshr i64 %30, 2
  %32 = add nuw nsw i64 %31, 1
  %min.iters.check = icmp ult i64 %30, 76
  br i1 %min.iters.check, label %.lr.ph.preheader46, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %33 = mul i64 %17, %16
  %34 = and i64 %33, 4611686018427387896
  %diff.check = icmp eq i64 %34, 0
  %35 = and i64 %33, 2305843009213693948
  %diff.check33 = icmp eq i64 %35, 0
  %conflict.rdx = or i1 %diff.check, %diff.check33
  br i1 %conflict.rdx, label %.lr.ph.preheader46, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %32, 9223372036854775800
  %36 = shl i64 %n.vec, 2
  %ind.end = getelementptr i8, ptr %24, i64 %36
  %37 = shl i64 %n.vec, 2
  %ind.end34 = getelementptr i8, ptr %19, i64 %37
  %38 = shl i64 %n.vec, 2
  %ind.end36 = getelementptr i8, ptr %15, i64 %38
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %24, i64 %offset.idx
  %offset.idx39 = shl i64 %index, 2
  %next.gep40 = getelementptr i8, ptr %19, i64 %offset.idx39
  %offset.idx42 = shl i64 %index, 2
  %next.gep43 = getelementptr i8, ptr %15, i64 %offset.idx42
  %39 = getelementptr i8, ptr %next.gep43, i64 16
  %wide.load = load <4 x float>, ptr %next.gep43, align 4, !tbaa !9
  %wide.load45 = load <4 x float>, ptr %39, align 4, !tbaa !9
  %40 = getelementptr i8, ptr %next.gep40, i64 16
  store <4 x float> %wide.load, ptr %next.gep40, align 4, !tbaa !9
  store <4 x float> %wide.load45, ptr %40, align 4, !tbaa !9
  %41 = getelementptr i8, ptr %next.gep, i64 16
  store <4 x float> %wide.load, ptr %next.gep, align 4, !tbaa !9
  store <4 x float> %wide.load45, ptr %41, align 4, !tbaa !9
  %index.next = add nuw i64 %index, 8
  %42 = icmp eq i64 %index.next, %n.vec
  br i1 %42, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %32, %n.vec
  br i1 %cmp.n, label %.loopexit, label %.lr.ph.preheader46

.lr.ph.preheader46:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %.02632.ph = phi ptr [ %24, %vector.memcheck ], [ %24, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.02731.ph = phi ptr [ %19, %vector.memcheck ], [ %19, %.lr.ph.preheader ], [ %ind.end34, %middle.block ]
  %.02830.ph = phi ptr [ %15, %vector.memcheck ], [ %15, %.lr.ph.preheader ], [ %ind.end36, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader46, %.lr.ph
  %.02632 = phi ptr [ %46, %.lr.ph ], [ %.02632.ph, %.lr.ph.preheader46 ]
  %.02731 = phi ptr [ %44, %.lr.ph ], [ %.02731.ph, %.lr.ph.preheader46 ]
  %.02830 = phi ptr [ %45, %.lr.ph ], [ %.02830.ph, %.lr.ph.preheader46 ]
  %43 = load float, ptr %.02830, align 4, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %.02731, i64 4
  store float %43, ptr %.02731, align 4, !tbaa !9
  %45 = getelementptr inbounds i8, ptr %.02830, i64 4
  %46 = getelementptr inbounds i8, ptr %.02632, i64 4
  store float %43, ptr %.02632, align 4, !tbaa !9
  %47 = icmp ult ptr %45, %19
  br i1 %47, label %.lr.ph, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph, %middle.block, %10, %7, %3
  %.0 = phi ptr [ null, %3 ], [ %5, %7 ], [ %15, %10 ], [ %15, %middle.block ], [ %15, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret ptr %.0
}

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

attributes #0 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { nounwind allocsize(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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !13}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass