; LLVM IR from certik/mlc :: mlc_clib (kernels)

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

; Function Attrs: nounwind uwtable
define dso_local void @saxpy_f16(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %76, %6
  %17 = load i32, ptr %13, align 4, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %79

21:                                               ; preds = %16
  %22 = load ptr, ptr %12, align 8, !tbaa !9
  %23 = load i32, ptr %13, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds half, ptr %22, i64 %24
  store half 0xH0000, ptr %25, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %57, %21
  %27 = load i32, ptr %15, align 4, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %60

31:                                               ; preds = %26
  %32 = load ptr, ptr %9, align 8, !tbaa !9
  %33 = load i32, ptr %13, align 4, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = mul nsw i32 %33, %34
  %36 = load i32, ptr %15, align 4, !tbaa !5
  %37 = add nsw i32 %35, %36
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds float, ptr %32, i64 %38
  %40 = load float, ptr %39, align 4, !tbaa !13
  %41 = fptrunc float %40 to half
  %42 = fpext half %41 to float
  %43 = load ptr, ptr %10, align 8, !tbaa !9
  %44 = load i32, ptr %15, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds half, ptr %43, i64 %45
  %47 = load half, ptr %46, align 2, !tbaa !11
  %48 = fpext half %47 to float
  %49 = load ptr, ptr %12, align 8, !tbaa !9
  %50 = load i32, ptr %13, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds half, ptr %49, i64 %51
  %53 = load half, ptr %52, align 2, !tbaa !11
  %54 = fpext half %53 to float
  %55 = call float @llvm.fmuladd.f32(float %42, float %48, float %54)
  %56 = fptrunc float %55 to half
  store half %56, ptr %52, align 2, !tbaa !11
  br label %57

57:                                               ; preds = %31
  %58 = load i32, ptr %15, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %15, align 4, !tbaa !5
  br label %26, !llvm.loop !15

60:                                               ; preds = %30
  %61 = load ptr, ptr %11, align 8, !tbaa !9
  %62 = load i32, ptr %13, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds float, ptr %61, i64 %63
  %65 = load float, ptr %64, align 4, !tbaa !13
  %66 = fptrunc float %65 to half
  %67 = fpext half %66 to float
  %68 = load ptr, ptr %12, align 8, !tbaa !9
  %69 = load i32, ptr %13, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds half, ptr %68, i64 %70
  %72 = load half, ptr %71, align 2, !tbaa !11
  %73 = fpext half %72 to float
  %74 = fadd float %73, %67
  %75 = fptrunc float %74 to half
  store half %75, ptr %71, align 2, !tbaa !11
  br label %76

76:                                               ; preds = %60
  %77 = load i32, ptr %13, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %13, align 4, !tbaa !5
  br label %16, !llvm.loop !17

79:                                               ; preds = %20
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Float16", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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 speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @saxpy_f16(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #1 {
  %7 = icmp sgt i32 %0, 0
  br i1 %7, label %.lr.ph24, label %._crit_edge25

.lr.ph24:                                         ; preds = %6
  %8 = icmp sgt i32 %1, 0
  br i1 %8, label %.lr.ph.us.preheader, label %.lr.ph24.split.preheader

.lr.ph24.split.preheader:                         ; preds = %.lr.ph24
  %wide.trip.count = zext nneg i32 %0 to i64
  %min.iters.check = icmp ult i32 %0, 4
  br i1 %min.iters.check, label %.lr.ph24.split.preheader40, label %vector.ph

.lr.ph24.split.preheader40:                       ; preds = %middle.block, %.lr.ph24.split.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph24.split.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph24.split

vector.ph:                                        ; preds = %.lr.ph24.split.preheader
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %9 = getelementptr inbounds half, ptr %5, i64 %index
  %10 = getelementptr inbounds float, ptr %4, i64 %index
  %wide.load = load <4 x float>, ptr %10, align 4, !tbaa !5
  %11 = fptrunc <4 x float> %wide.load to <4 x half>
  %12 = fadd <4 x half> %11, zeroinitializer
  store <4 x half> %12, ptr %9, align 2, !tbaa !9
  %index.next = add nuw i64 %index, 4
  %13 = icmp eq i64 %index.next, %n.vec
  br i1 %13, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge25, label %.lr.ph24.split.preheader40

.lr.ph.us.preheader:                              ; preds = %.lr.ph24
  %14 = zext nneg i32 %1 to i64
  %wide.trip.count36 = zext nneg i32 %0 to i64
  %xtraiter = and i64 %14, 1
  %15 = icmp eq i32 %1, 1
  %unroll_iter = and i64 %14, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv33 = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next34, %._crit_edge.us ]
  %16 = getelementptr inbounds half, ptr %5, i64 %indvars.iv33
  store half 0xH0000, ptr %16, align 2, !tbaa !9
  %17 = mul nuw nsw i64 %indvars.iv33, %14
  %invariant.gep = getelementptr inbounds float, ptr %2, i64 %17
  br i1 %15, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %indvars.iv28 = phi i64 [ %indvars.iv.next29.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %18 = phi half [ %36, %.lr.ph.us.new ], [ 0xH0000, %.lr.ph.us ]
  %niter = phi i64 [ %niter.next.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %gep = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv28
  %19 = load float, ptr %gep, align 4, !tbaa !5
  %20 = fptrunc float %19 to half
  %21 = fpext half %20 to float
  %22 = getelementptr inbounds half, ptr %3, i64 %indvars.iv28
  %23 = load half, ptr %22, align 2, !tbaa !9
  %24 = fpext half %23 to float
  %25 = fpext half %18 to float
  %26 = tail call float @llvm.fmuladd.f32(float %21, float %24, float %25)
  %27 = fptrunc float %26 to half
  store half %27, ptr %16, align 2, !tbaa !9
  %indvars.iv.next29 = or disjoint i64 %indvars.iv28, 1
  %gep.1 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next29
  %28 = load float, ptr %gep.1, align 4, !tbaa !5
  %29 = fptrunc float %28 to half
  %30 = fpext half %29 to float
  %31 = getelementptr inbounds half, ptr %3, i64 %indvars.iv.next29
  %32 = load half, ptr %31, align 2, !tbaa !9
  %33 = fpext half %32 to float
  %34 = fpext half %27 to float
  %35 = tail call float @llvm.fmuladd.f32(float %30, float %33, float %34)
  %36 = fptrunc float %35 to half
  store half %36, ptr %16, align 2, !tbaa !9
  %indvars.iv.next29.1 = add nuw nsw i64 %indvars.iv28, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new, !llvm.loop !15

._crit_edge.us.unr-lcssa:                         ; preds = %.lr.ph.us.new, %.lr.ph.us
  %.lcssa.ph = phi half [ poison, %.lr.ph.us ], [ %36, %.lr.ph.us.new ]
  %indvars.iv28.unr = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next29.1, %.lr.ph.us.new ]
  %.unr = phi half [ 0xH0000, %.lr.ph.us ], [ %36, %.lr.ph.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %gep.epil = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv28.unr
  %37 = load float, ptr %gep.epil, align 4, !tbaa !5
  %38 = fptrunc float %37 to half
  %39 = fpext half %38 to float
  %40 = getelementptr inbounds half, ptr %3, i64 %indvars.iv28.unr
  %41 = load half, ptr %40, align 2, !tbaa !9
  %42 = fpext half %41 to float
  %43 = fpext half %.unr to float
  %44 = tail call float @llvm.fmuladd.f32(float %39, float %42, float %43)
  %45 = fptrunc float %44 to half
  store half %45, ptr %16, align 2, !tbaa !9
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.lcssa = phi half [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %45, %._crit_edge.us.epilog-lcssa ]
  %46 = getelementptr inbounds float, ptr %4, i64 %indvars.iv33
  %47 = load float, ptr %46, align 4, !tbaa !5
  %48 = fptrunc float %47 to half
  %49 = fadd half %.lcssa, %48
  store half %49, ptr %16, align 2, !tbaa !9
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next34, %wide.trip.count36
  br i1 %exitcond37.not, label %._crit_edge25, label %.lr.ph.us, !llvm.loop !16

._crit_edge25:                                    ; preds = %.lr.ph24.split, %._crit_edge.us, %middle.block, %6
  ret void

.lr.ph24.split:                                   ; preds = %.lr.ph24.split.preheader40, %.lr.ph24.split
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph24.split ], [ %indvars.iv.ph, %.lr.ph24.split.preheader40 ]
  %50 = getelementptr inbounds half, ptr %5, i64 %indvars.iv
  %51 = getelementptr inbounds float, ptr %4, i64 %indvars.iv
  %52 = load float, ptr %51, align 4, !tbaa !5
  %53 = fptrunc float %52 to half
  %54 = fadd half %53, 0xH0000
  store half %54, ptr %50, align 2, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge25, label %.lr.ph24.split, !llvm.loop !17
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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" }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Float16", !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}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12, !14, !13}


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