; LLVM IR from skywind3000/ml :: NeuralNetwork (ineuron)

; 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.INEURALNET = type { i32, i32, i32, ptr, [1 x ptr] }
%struct.INLAYER = type { i32, i32, ptr, [1 x ptr] }

; 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
declare dso_local void @inlayer_compute(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @inn_compute(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = 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) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %36, %2
  %9 = load i32, ptr %7, align 4, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.INEURALNET, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp slt i32 %9, %12
  br i1 %13, label %14, label %39

14:                                               ; preds = %8
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %15, ptr %6, align 8, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %28

18:                                               ; preds = %14
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.INEURALNET, ptr %19, i32 0, i32 4
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sub nsw i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1 x ptr], ptr %20, i64 0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.INLAYER, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  store ptr %27, ptr %6, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %18, %14
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.INEURALNET, ptr %29, i32 0, i32 4
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1 x ptr], ptr %30, i64 0, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  call void @inlayer_compute(ptr noundef %34, ptr noundef %35)
  br label %36

36:                                               ; preds = %28
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %7, align 4, !tbaa !9
  br label %8, !llvm.loop !15

39:                                               ; preds = %8
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.INEURALNET, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.INEURALNET, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !11
  %45 = sub nsw i32 %44, 1
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1 x ptr], ptr %41, i64 0, i64 %46
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  store ptr %48, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %69, %39
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.INLAYER, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !17
  %54 = icmp slt i32 %50, %53
  br i1 %54, label %55, label %72

55:                                               ; preds = %49
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.INLAYER, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  %59 = load i32, ptr %7, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds double, ptr %58, i64 %60
  %62 = load double, ptr %61, align 8, !tbaa !18
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.INEURALNET, ptr %63, i32 0, i32 3
  %65 = load ptr, ptr %64, align 8, !tbaa !20
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds double, ptr %65, i64 %67
  store double %62, ptr %68, align 8, !tbaa !18
  br label %69

69:                                               ; preds = %55
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %7, align 4, !tbaa !9
  br label %49, !llvm.loop !21

72:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

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, !10, i64 0}
!12 = !{!"INEURALNET", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !7, i64 24}
!13 = !{!14, !6, i64 8}
!14 = !{!"INLAYER", !10, i64 0, !10, i64 4, !6, i64 8, !7, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!14, !10, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !7, i64 0}
!20 = !{!12, !6, i64 16}
!21 = distinct !{!21, !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: nounwind uwtable
declare dso_local void @inlayer_compute(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @inn_compute(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %5, label %._crit_edge

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  tail call void @inlayer_compute(ptr noundef %7, ptr noundef %1)
  %8 = load i32, ptr %0, align 8, !tbaa !5
  %9 = icmp sgt i32 %8, 1
  br i1 %9, label %.peel.next, label %._crit_edge

.peel.next:                                       ; preds = %5, %.peel.next
  %indvars.iv = phi i64 [ %indvars.iv.next, %.peel.next ], [ 1, %5 ]
  %10 = add nsw i64 %indvars.iv, -1
  %11 = getelementptr inbounds [1 x ptr], ptr %6, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds [1 x ptr], ptr %6, i64 0, i64 %indvars.iv
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  tail call void @inlayer_compute(ptr noundef %16, ptr noundef %14)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i32, ptr %0, align 8, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = icmp slt i64 %indvars.iv.next, %18
  br i1 %19, label %.peel.next, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.peel.next, %5, %2
  %.lcssa = phi i32 [ %3, %2 ], [ %8, %5 ], [ %17, %.peel.next ]
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = add nsw i32 %.lcssa, -1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1 x ptr], ptr %20, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = load i32, ptr %24, align 8, !tbaa !17
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph23, label %._crit_edge24

.lr.ph23:                                         ; preds = %._crit_edge
  %27 = getelementptr inbounds i8, ptr %24, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  %29 = getelementptr inbounds i8, ptr %0, i64 16
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %wide.trip.count = zext nneg i32 %25 to i64
  %min.iters.check = icmp ult i32 %25, 6
  %31 = ptrtoint ptr %30 to i64
  %32 = ptrtoint ptr %28 to i64
  %33 = sub i64 %31, %32
  %diff.check = icmp ult i64 %33, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph23
  %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 ]
  %34 = getelementptr inbounds double, ptr %28, i64 %index
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %wide.load = load <2 x double>, ptr %34, align 8, !tbaa !19
  %wide.load34 = load <2 x double>, ptr %35, align 8, !tbaa !19
  %36 = getelementptr inbounds double, ptr %30, i64 %index
  %37 = getelementptr inbounds i8, ptr %36, i64 16
  store <2 x double> %wide.load, ptr %36, align 8, !tbaa !19
  store <2 x double> %wide.load34, ptr %37, align 8, !tbaa !19
  %index.next = add nuw i64 %index, 4
  %38 = icmp eq i64 %index.next, %n.vec
  br i1 %38, label %middle.block, label %vector.body, !llvm.loop !21

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge24, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph23
  %indvars.iv28.ph = phi i64 [ 0, %.lr.ph23 ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv28.prol = phi i64 [ %indvars.iv.next29.prol, %scalar.ph.prol ], [ %indvars.iv28.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %39 = getelementptr inbounds double, ptr %28, i64 %indvars.iv28.prol
  %40 = load double, ptr %39, align 8, !tbaa !19
  %41 = getelementptr inbounds double, ptr %30, i64 %indvars.iv28.prol
  store double %40, ptr %41, align 8, !tbaa !19
  %indvars.iv.next29.prol = add nuw nsw i64 %indvars.iv28.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !24

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv28.unr = phi i64 [ %indvars.iv28.ph, %scalar.ph.preheader ], [ %indvars.iv.next29.prol, %scalar.ph.prol ]
  %42 = sub nsw i64 %indvars.iv28.ph, %wide.trip.count
  %43 = icmp ugt i64 %42, -4
  br i1 %43, label %._crit_edge24, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv28 = phi i64 [ %indvars.iv.next29.3, %scalar.ph ], [ %indvars.iv28.unr, %scalar.ph.prol.loopexit ]
  %44 = getelementptr inbounds double, ptr %28, i64 %indvars.iv28
  %45 = load double, ptr %44, align 8, !tbaa !19
  %46 = getelementptr inbounds double, ptr %30, i64 %indvars.iv28
  store double %45, ptr %46, align 8, !tbaa !19
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %47 = getelementptr inbounds double, ptr %28, i64 %indvars.iv.next29
  %48 = load double, ptr %47, align 8, !tbaa !19
  %49 = getelementptr inbounds double, ptr %30, i64 %indvars.iv.next29
  store double %48, ptr %49, align 8, !tbaa !19
  %indvars.iv.next29.1 = add nuw nsw i64 %indvars.iv28, 2
  %50 = getelementptr inbounds double, ptr %28, i64 %indvars.iv.next29.1
  %51 = load double, ptr %50, align 8, !tbaa !19
  %52 = getelementptr inbounds double, ptr %30, i64 %indvars.iv.next29.1
  store double %51, ptr %52, align 8, !tbaa !19
  %indvars.iv.next29.2 = add nuw nsw i64 %indvars.iv28, 3
  %53 = getelementptr inbounds double, ptr %28, i64 %indvars.iv.next29.2
  %54 = load double, ptr %53, align 8, !tbaa !19
  %55 = getelementptr inbounds double, ptr %30, i64 %indvars.iv.next29.2
  store double %54, ptr %55, align 8, !tbaa !19
  %indvars.iv.next29.3 = add nuw nsw i64 %indvars.iv28, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next29.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge24, label %scalar.ph, !llvm.loop !26

._crit_edge24:                                    ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %._crit_edge
  ret void
}

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

!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 0}
!6 = !{!"INEURALNET", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !8, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!13, !10, i64 8}
!13 = !{!"INLAYER", !7, i64 0, !7, i64 4, !10, i64 8, !8, i64 16}
!14 = distinct !{!14, !15, !16}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.peeled.count", i32 1}
!17 = !{!13, !7, i64 0}
!18 = !{!6, !10, i64 16}
!19 = !{!20, !20, i64 0}
!20 = !{!"double", !8, i64 0}
!21 = distinct !{!21, !15, !22, !23}
!22 = !{!"llvm.loop.isvectorized", i32 1}
!23 = !{!"llvm.loop.unroll.runtime.disable"}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.unroll.disable"}
!26 = distinct !{!26, !15, !22}


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