; LLVM IR from oservo/aiFi :: mlpLayer (mlpLayerPropagateForward)

; 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.mlpLayer = type { i32, i32, i32, i32, double, double, i32, i32, i32, double, double, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.activation = type { i32, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @mlpLayerPropagateForward(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 0.000000e+00, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %79, %2
  %10 = load i32, ptr %6, align 4, !tbaa !11
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.mlpLayer, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = icmp slt i32 %10, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %9
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %82

16:                                               ; preds = %9
  store double 0.000000e+00, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %17

17:                                               ; preds = %49, %16
  %18 = load i32, ptr %8, align 4, !tbaa !11
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.mlpLayer, ptr %19, i32 0, i32 11
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = load i32, ptr %6, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %21, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = icmp slt i32 %18, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %17
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %52

28:                                               ; preds = %17
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mlpLayer, ptr %29, i32 0, i32 14
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = load i32, ptr %8, align 4, !tbaa !11
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds double, ptr %31, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !9
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.mlpLayer, ptr %36, i32 0, i32 13
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  %39 = load i32, ptr %6, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds ptr, ptr %38, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !11
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %42, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !9
  %47 = load double, ptr %5, align 8, !tbaa !9
  %48 = call double @llvm.fmuladd.f64(double %35, double %46, double %47)
  store double %48, ptr %5, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %28
  %50 = load i32, ptr %8, align 4, !tbaa !11
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %8, align 4, !tbaa !11
  br label %17, !llvm.loop !18

52:                                               ; preds = %27
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mlpLayer, ptr %53, i32 0, i32 19
  %55 = load ptr, ptr %54, align 8, !tbaa !20
  %56 = load i32, ptr %6, align 4, !tbaa !11
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds double, ptr %55, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !9
  %60 = load double, ptr %5, align 8, !tbaa !9
  %61 = fadd double %60, %59
  store double %61, ptr %5, align 8, !tbaa !9
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.mlpLayer, ptr %62, i32 0, i32 22
  %64 = load ptr, ptr %63, align 8, !tbaa !21
  %65 = load i32, ptr %6, align 4, !tbaa !11
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds ptr, ptr %64, i64 %66
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.activation, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !22
  %71 = load double, ptr %5, align 8, !tbaa !9
  %72 = call double %70(double noundef %71)
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.mlpLayer, ptr %73, i32 0, i32 14
  %75 = load ptr, ptr %74, align 8, !tbaa !16
  %76 = load i32, ptr %6, align 4, !tbaa !11
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds double, ptr %75, i64 %77
  store double %72, ptr %78, align 8, !tbaa !9
  br label %79

79:                                               ; preds = %52
  %80 = load i32, ptr %6, align 4, !tbaa !11
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %6, align 4, !tbaa !11
  br label %9, !llvm.loop !24

82:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 4}
!14 = !{!"mlpLayer", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !10, i64 16, !10, i64 24, !12, i64 32, !12, i64 36, !12, i64 40, !10, i64 48, !10, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168}
!15 = !{!14, !6, i64 64}
!16 = !{!14, !6, i64 88}
!17 = !{!14, !6, i64 80}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!14, !6, i64 128}
!21 = !{!14, !6, i64 152}
!22 = !{!23, !6, i64 8}
!23 = !{!"activation", !12, i64 0, !6, i64 8, !6, i64 16}
!24 = distinct !{!24, !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"

; Function Attrs: nounwind uwtable
define dso_local void @mlpLayerPropagateForward(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader.lr.ph, label %._crit_edge26

.preheader.lr.ph:                                 ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 64
  %7 = getelementptr inbounds i8, ptr %0, i64 88
  %8 = getelementptr inbounds i8, ptr %1, i64 80
  %9 = getelementptr inbounds i8, ptr %1, i64 128
  %10 = getelementptr inbounds i8, ptr %1, i64 152
  %11 = getelementptr inbounds i8, ptr %1, i64 88
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %indvars.iv28 = phi i64 [ 0, %.preheader.lr.ph ], [ %indvars.iv.next29, %._crit_edge ]
  %12 = load ptr, ptr %6, align 8, !tbaa !12
  %13 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv28
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %16 = load ptr, ptr %7, align 8, !tbaa !14
  %17 = load ptr, ptr %8, align 8, !tbaa !15
  %18 = getelementptr inbounds ptr, ptr %17, i64 %indvars.iv28
  %19 = load ptr, ptr %18, align 8, !tbaa !16
  %wide.trip.count = zext nneg i32 %14 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %20 = icmp ult i32 %14, 4
  br i1 %20, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %41

._crit_edge26:                                    ; preds = %._crit_edge, %2
  ret void

._crit_edge.loopexit.unr-lcssa:                   ; preds = %41, %.lr.ph
  %.lcssa.ph = phi double [ poison, %.lr.ph ], [ %61, %41 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %41 ]
  %.02122.unr = phi double [ 0.000000e+00, %.lr.ph ], [ %61, %41 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.02122.epil = phi double [ %25, %.epil.preheader ], [ %.02122.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %21 = getelementptr inbounds double, ptr %16, i64 %indvars.iv.epil
  %22 = load double, ptr %21, align 8, !tbaa !17
  %23 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.epil
  %24 = load double, ptr %23, align 8, !tbaa !17
  %25 = tail call double @llvm.fmuladd.f64(double %22, double %24, double %.02122.epil)
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.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, label %.epil.preheader, !llvm.loop !18

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %.preheader
  %.021.lcssa = phi double [ 0.000000e+00, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %25, %.epil.preheader ]
  %26 = load ptr, ptr %9, align 8, !tbaa !20
  %27 = getelementptr inbounds double, ptr %26, i64 %indvars.iv28
  %28 = load double, ptr %27, align 8, !tbaa !17
  %29 = fadd double %.021.lcssa, %28
  %30 = load ptr, ptr %10, align 8, !tbaa !21
  %31 = getelementptr inbounds ptr, ptr %30, i64 %indvars.iv28
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  %34 = load ptr, ptr %33, align 8, !tbaa !22
  %35 = tail call double %34(double noundef %29) #2
  %36 = load ptr, ptr %11, align 8, !tbaa !14
  %37 = getelementptr inbounds double, ptr %36, i64 %indvars.iv28
  store double %35, ptr %37, align 8, !tbaa !17
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = icmp slt i64 %indvars.iv.next29, %39
  br i1 %40, label %.preheader, label %._crit_edge26, !llvm.loop !24

41:                                               ; preds = %41, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %41 ]
  %.02122 = phi double [ 0.000000e+00, %.lr.ph.new ], [ %61, %41 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %41 ]
  %42 = getelementptr inbounds double, ptr %16, i64 %indvars.iv
  %43 = load double, ptr %42, align 8, !tbaa !17
  %44 = getelementptr inbounds double, ptr %19, i64 %indvars.iv
  %45 = load double, ptr %44, align 8, !tbaa !17
  %46 = tail call double @llvm.fmuladd.f64(double %43, double %45, double %.02122)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %47 = getelementptr inbounds double, ptr %16, i64 %indvars.iv.next
  %48 = load double, ptr %47, align 8, !tbaa !17
  %49 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.next
  %50 = load double, ptr %49, align 8, !tbaa !17
  %51 = tail call double @llvm.fmuladd.f64(double %48, double %50, double %46)
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %52 = getelementptr inbounds double, ptr %16, i64 %indvars.iv.next.1
  %53 = load double, ptr %52, align 8, !tbaa !17
  %54 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.next.1
  %55 = load double, ptr %54, align 8, !tbaa !17
  %56 = tail call double @llvm.fmuladd.f64(double %53, double %55, double %51)
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %57 = getelementptr inbounds double, ptr %16, i64 %indvars.iv.next.2
  %58 = load double, ptr %57, align 8, !tbaa !17
  %59 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.next.2
  %60 = load double, ptr %59, align 8, !tbaa !17
  %61 = tail call double @llvm.fmuladd.f64(double %58, double %60, double %56)
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 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.loopexit.unr-lcssa, label %41, !llvm.loop !26
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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 speculatable willreturn memory(none) }
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, !7, i64 4}
!6 = !{!"mlpLayer", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24, !7, i64 32, !7, i64 36, !7, i64 40, !10, i64 48, !10, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152, !11, i64 160, !11, i64 168}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 64}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !11, i64 88}
!15 = !{!6, !11, i64 80}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !10, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = !{!6, !11, i64 128}
!21 = !{!6, !11, i64 152}
!22 = !{!23, !11, i64 8}
!23 = !{!"activation", !7, i64 0, !11, i64 8, !11, i64 16}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}


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