; LLVM IR from zchrissirhcz/pixel :: legacy/NaiveCNN/src (naive_infer)

; 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.NcLayerBottomTop = type { i32, ptr, ptr }
%struct.NcNet = type { i32, ptr, i32, ptr, ptr, ptr }
%struct.NcBlob = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr }

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; 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 ptr @nc_infer_create_layer_input(i32 noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = call noalias ptr @malloc(i64 noundef 24) #4
  store ptr %9, ptr %7, align 8, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load ptr, ptr %7, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.NcLayerBottomTop, ptr %11, i32 0, i32 0
  store i32 %10, ptr %12, align 8, !tbaa !11
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = mul i64 8, %14
  %16 = call noalias ptr @malloc(i64 noundef %15) #4
  %17 = load ptr, ptr %7, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.NcLayerBottomTop, ptr %17, i32 0, i32 1
  store ptr %16, ptr %18, align 8, !tbaa !13
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = mul i64 4, %20
  %22 = call noalias ptr @malloc(i64 noundef %21) #4
  %23 = load ptr, ptr %7, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.NcLayerBottomTop, ptr %23, i32 0, i32 2
  store ptr %22, ptr %24, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %73, %3
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %76

30:                                               ; preds = %25
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr %31, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.NcLayerBottomTop, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i32, ptr %38, i64 %40
  store i32 %35, ptr %41, align 4, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.NcNet, ptr %42, i32 0, i32 3
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = load ptr, ptr %5, align 8, !tbaa !9
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr %45, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds ptr, ptr %44, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.NcLayerBottomTop, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds ptr, ptr %55, i64 %57
  store ptr %52, ptr %58, align 8, !tbaa !9
  %59 = load ptr, ptr %6, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.NcNet, ptr %59, i32 0, i32 3
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  %62 = load ptr, ptr %5, align 8, !tbaa !9
  %63 = load i32, ptr %8, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i32, ptr %62, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds ptr, ptr %61, i64 %67
  %69 = load ptr, ptr %68, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.NcBlob, ptr %69, i32 0, i32 6
  %71 = load i32, ptr %70, align 8, !tbaa !17
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %70, align 8, !tbaa !17
  br label %73

73:                                               ; preds = %30
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %8, align 4, !tbaa !5
  br label %25, !llvm.loop !19

76:                                               ; preds = %29
  %77 = load ptr, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret ptr %77
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 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 }
attributes #4 = { nounwind allocsize(0) }

!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, !6, i64 0}
!12 = !{!"NcLayerBottomTop", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 16}
!15 = !{!16, !10, i64 24}
!16 = !{!"NcNet", !6, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!17 = !{!18, !6, i64 24}
!18 = !{!"NcBlob", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !10, i64 40}
!19 = distinct !{!19, !20}
!20 = !{!"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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local noalias noundef ptr @nc_infer_create_layer_input(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #2
  store i32 %0, ptr %4, align 8, !tbaa !5
  %5 = sext i32 %0 to i64
  %6 = shl nsw i64 %5, 3
  %7 = tail call noalias ptr @malloc(i64 noundef %6) #2
  %8 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %7, ptr %8, align 8, !tbaa !11
  %9 = shl nsw i64 %5, 2
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #2
  %11 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %10, ptr %11, align 8, !tbaa !12
  %12 = icmp sgt i32 %0, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %13 = getelementptr inbounds i8, ptr %2, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %wide.trip.count = zext nneg i32 %0 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %15 = icmp eq i32 %0, 1
  br i1 %15, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %26, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %26 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %16 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.unr
  %17 = load i32, ptr %16, align 4, !tbaa !15
  %18 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.unr
  store i32 %17, ptr %18, align 4, !tbaa !15
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds ptr, ptr %14, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv.unr
  store ptr %21, ptr %22, align 8, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %21, i64 24
  %24 = load i32, ptr %23, align 8, !tbaa !17
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %23, align 8, !tbaa !17
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %3
  ret ptr %4

26:                                               ; preds = %26, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %26 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %26 ]
  %27 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv
  %28 = load i32, ptr %27, align 4, !tbaa !15
  %29 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv
  store i32 %28, ptr %29, align 4, !tbaa !15
  %30 = sext i32 %28 to i64
  %31 = getelementptr inbounds ptr, ptr %14, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv
  store ptr %32, ptr %33, align 8, !tbaa !16
  %34 = getelementptr inbounds i8, ptr %32, i64 24
  %35 = load i32, ptr %34, align 8, !tbaa !17
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %34, align 8, !tbaa !17
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %37 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next
  %38 = load i32, ptr %37, align 4, !tbaa !15
  %39 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.next
  store i32 %38, ptr %39, align 4, !tbaa !15
  %40 = sext i32 %38 to i64
  %41 = getelementptr inbounds ptr, ptr %14, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv.next
  store ptr %42, ptr %43, align 8, !tbaa !16
  %44 = getelementptr inbounds i8, ptr %42, i64 24
  %45 = load i32, ptr %44, align 8, !tbaa !17
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %44, align 8, !tbaa !17
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 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.loopexit.unr-lcssa, label %26, !llvm.loop !19
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #1 = { nofree 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 allocsize(0) }

!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 = !{!"NcLayerBottomTop", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 16}
!13 = !{!14, !10, i64 24}
!14 = !{!"NcNet", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!15 = !{!7, !7, i64 0}
!16 = !{!10, !10, i64 0}
!17 = !{!18, !7, i64 24}
!18 = !{!"NcBlob", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !10, i64 40}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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