; LLVM IR from TheNachoBIT/GeoFenix-Engine :: Libraries/SOIL2/include (image_helper)

; 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 i32 @scale_image_RGB_to_NTSC_safe(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca [256 x i8], align 16
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store float 0x402F008320000000, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store float 0x406D6FF7C0000000, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %17 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %17, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 256, ptr %15) #2
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 1
  br i1 %19, label %29, label %20

20:                                               ; preds = %4
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = icmp slt i32 %21, 1
  br i1 %22, label %29, label %23

23:                                               ; preds = %20
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 1
  br i1 %25, label %29, label %26

26:                                               ; preds = %23
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %30

29:                                               ; preds = %26, %23, %20, %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %92

30:                                               ; preds = %26
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %44, %30
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = icmp slt i32 %32, 256
  br i1 %33, label %34, label %47

34:                                               ; preds = %31
  %35 = load i32, ptr %12, align 4, !tbaa !9
  %36 = sitofp i32 %35 to float
  %37 = fmul float 0x406B7FEF80000000, %36
  %38 = fdiv float %37, 2.550000e+02
  %39 = fadd float %38, 0x402F008320000000
  %40 = fptoui float %39 to i8
  %41 = load i32, ptr %12, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [256 x i8], ptr %15, i64 0, i64 %42
  store i8 %40, ptr %43, align 1, !tbaa !13
  br label %44

44:                                               ; preds = %34
  %45 = load i32, ptr %12, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %12, align 4, !tbaa !9
  br label %31, !llvm.loop !14

47:                                               ; preds = %31
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = and i32 %48, 1
  %50 = sub nsw i32 1, %49
  %51 = load i32, ptr %14, align 4, !tbaa !9
  %52 = sub nsw i32 %51, %50
  store i32 %52, ptr %14, align 4, !tbaa !9
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %87, %47
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = mul nsw i32 %55, %56
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = mul nsw i32 %57, %58
  %60 = icmp slt i32 %54, %59
  br i1 %60, label %61, label %91

61:                                               ; preds = %53
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %83, %61
  %63 = load i32, ptr %13, align 4, !tbaa !9
  %64 = load i32, ptr %14, align 4, !tbaa !9
  %65 = icmp slt i32 %63, %64
  br i1 %65, label %66, label %86

66:                                               ; preds = %62
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load i32, ptr %12, align 4, !tbaa !9
  %69 = load i32, ptr %13, align 4, !tbaa !9
  %70 = add nsw i32 %68, %69
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i8, ptr %67, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !13
  %74 = zext i8 %73 to i64
  %75 = getelementptr inbounds [256 x i8], ptr %15, i64 0, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !13
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = load i32, ptr %12, align 4, !tbaa !9
  %79 = load i32, ptr %13, align 4, !tbaa !9
  %80 = add nsw i32 %78, %79
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i8, ptr %77, i64 %81
  store i8 %76, ptr %82, align 1, !tbaa !13
  br label %83

83:                                               ; preds = %66
  %84 = load i32, ptr %13, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %13, align 4, !tbaa !9
  br label %62, !llvm.loop !16

86:                                               ; preds = %62
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = load i32, ptr %12, align 4, !tbaa !9
  %90 = add nsw i32 %89, %88
  store i32 %90, ptr %12, align 4, !tbaa !9
  br label %53, !llvm.loop !17

91:                                               ; preds = %53
  store i32 1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %92

92:                                               ; preds = %91, %29
  call void @llvm.lifetime.end.p0(i64 256, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %93 = load i32, ptr %5, align 4
  ret i32 %93
}

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 }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local range(i32 0, 2) i32 @scale_image_RGB_to_NTSC_safe(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca [256 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %5) #2
  %6 = icmp slt i32 %1, 1
  %7 = icmp slt i32 %2, 1
  %or.cond = or i1 %6, %7
  %8 = icmp slt i32 %3, 1
  %or.cond3 = or i1 %or.cond, %8
  %9 = icmp eq ptr %0, null
  %or.cond5 = or i1 %9, %or.cond3
  br i1 %or.cond5, label %.loopexit, label %vector.body

vector.body:                                      ; preds = %4, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %4 ]
  %vec.ind = phi <16 x i32> [ %vec.ind.next, %vector.body ], [ <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>, %4 ]
  %10 = uitofp <16 x i32> %vec.ind to <16 x float>
  %11 = fmul <16 x float> %10, <float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000, float 0x406B7FEF80000000>
  %12 = fdiv <16 x float> %11, <float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02>
  %13 = fadd <16 x float> %12, <float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000, float 0x402F008320000000>
  %14 = fptoui <16 x float> %13 to <16 x i8>
  %15 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %index
  store <16 x i8> %14, ptr %15, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 16
  %vec.ind.next = add <16 x i32> %vec.ind, <i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16>
  %16 = icmp eq i64 %index.next, 256
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %17 = and i32 %3, 1
  %18 = xor i32 %17, 1
  %19 = sub nsw i32 %3, %18
  %20 = mul nuw nsw i32 %2, %1
  %21 = mul nuw nsw i32 %20, %3
  %22 = icmp sgt i32 %21, 0
  %23 = icmp sgt i32 %19, 0
  %or.cond50 = select i1 %22, i1 %23, i1 false
  br i1 %or.cond50, label %.preheader.us.preheader, label %.loopexit

.preheader.us.preheader:                          ; preds = %middle.block
  %24 = zext nneg i32 %3 to i64
  %wide.trip.count = zext nneg i32 %19 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %25 = icmp ult i32 %19, 4
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv47 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next48, %._crit_edge.us ]
  %invariant.gep = getelementptr inbounds i8, ptr %0, i64 %indvars.iv47
  br i1 %25, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv43 = phi i64 [ %indvars.iv.next44.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %gep = getelementptr inbounds i8, ptr %invariant.gep, i64 %indvars.iv43
  %26 = load i8, ptr %gep, align 1, !tbaa !5
  %27 = zext i8 %26 to i64
  %28 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !5
  store i8 %29, ptr %gep, align 1, !tbaa !5
  %indvars.iv.next44 = or disjoint i64 %indvars.iv43, 1
  %gep.1 = getelementptr inbounds i8, ptr %invariant.gep, i64 %indvars.iv.next44
  %30 = load i8, ptr %gep.1, align 1, !tbaa !5
  %31 = zext i8 %30 to i64
  %32 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !5
  store i8 %33, ptr %gep.1, align 1, !tbaa !5
  %indvars.iv.next44.1 = or disjoint i64 %indvars.iv43, 2
  %gep.2 = getelementptr inbounds i8, ptr %invariant.gep, i64 %indvars.iv.next44.1
  %34 = load i8, ptr %gep.2, align 1, !tbaa !5
  %35 = zext i8 %34 to i64
  %36 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !5
  store i8 %37, ptr %gep.2, align 1, !tbaa !5
  %indvars.iv.next44.2 = or disjoint i64 %indvars.iv43, 3
  %gep.3 = getelementptr inbounds i8, ptr %invariant.gep, i64 %indvars.iv.next44.2
  %38 = load i8, ptr %gep.3, align 1, !tbaa !5
  %39 = zext i8 %38 to i64
  %40 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !5
  store i8 %41, ptr %gep.3, align 1, !tbaa !5
  %indvars.iv.next44.3 = add nuw nsw i64 %indvars.iv43, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !12

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %indvars.iv43.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next44.3, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %indvars.iv43.epil = phi i64 [ %indvars.iv.next44.epil, %.epil.preheader ], [ %indvars.iv43.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %gep.epil = getelementptr inbounds i8, ptr %invariant.gep, i64 %indvars.iv43.epil
  %42 = load i8, ptr %gep.epil, align 1, !tbaa !5
  %43 = zext i8 %42 to i64
  %44 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !5
  store i8 %45, ptr %gep.epil, align 1, !tbaa !5
  %indvars.iv.next44.epil = add nuw nsw i64 %indvars.iv43.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !13

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, %24
  %46 = trunc nuw i64 %indvars.iv.next48 to i32
  %47 = icmp sgt i32 %21, %46
  br i1 %47, label %.preheader.us, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %._crit_edge.us, %middle.block, %4
  %.032 = phi i32 [ 0, %4 ], [ 1, %middle.block ], [ 1, %._crit_edge.us ]
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %5) #2
  ret i32 %.032
}

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


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