; LLVM IR from zchrissirhcz/pixel :: legacy/NaiveCNN/examples/nc_lenet.ll (Z8nc_inferP5NcNetP10px_image_t)

; 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.NcNet = type { i32, ptr, i32, ptr, ptr, ptr }
%struct.px_image_t = type { ptr, i32, i32, i32, i32 }
%struct.NcBlob = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr }
%struct.NcLayer = type { i32, ptr, ptr, ptr, ptr, ptr, 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: mustprogress uwtable
define dso_local void @_Z8nc_inferP5NcNetP10px_image_t(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %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
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.NcNet, ptr %8, i32 0, i32 3
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds ptr, ptr %10, i64 0
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.px_image_t, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.px_image_t, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.px_image_t, ptr %19, i32 0, i32 3
  %21 = load i32, ptr %20, align 8, !tbaa !15
  call void @nc_blob_data_realloc3d(ptr noundef %12, i32 noundef %15, i32 noundef %18, i32 noundef %21)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !16
  br label %22

22:                                               ; preds = %47, %2
  %23 = load i32, ptr %5, align 4, !tbaa !16
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.NcNet, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !17
  %27 = icmp slt i32 %23, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %50

29:                                               ; preds = %22
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.NcNet, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = load i32, ptr %5, align 4, !tbaa !16
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds ptr, ptr %32, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.NcBlob, ptr %36, i32 0, i32 6
  %38 = load i32, ptr %37, align 8, !tbaa !18
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.NcNet, ptr %39, i32 0, i32 3
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = load i32, ptr %5, align 4, !tbaa !16
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds ptr, ptr %41, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.NcBlob, ptr %45, i32 0, i32 7
  store i32 %38, ptr %46, align 4, !tbaa !21
  br label %47

47:                                               ; preds = %29
  %48 = load i32, ptr %5, align 4, !tbaa !16
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %5, align 4, !tbaa !16
  br label %22, !llvm.loop !22

50:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !16
  br label %51

51:                                               ; preds = %78, %50
  %52 = load i32, ptr %7, align 4, !tbaa !16
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.NcNet, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !24
  %56 = icmp slt i32 %52, %55
  br i1 %56, label %58, label %57

57:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %81

58:                                               ; preds = %51
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.NcNet, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !25
  %62 = load i32, ptr %7, align 4, !tbaa !16
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds ptr, ptr %61, i64 %63
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  store ptr %65, ptr %6, align 8, !tbaa !5
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.NcLayer, ptr %66, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !26
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.NcLayer, ptr %69, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !29
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.NcLayer, ptr %72, i32 0, i32 5
  %74 = load ptr, ptr %73, align 8, !tbaa !30
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.NcLayer, ptr %75, i32 0, i32 6
  %77 = load ptr, ptr %76, align 8, !tbaa !31
  call void %68(ptr noundef %71, ptr noundef %74, ptr noundef %77)
  br label %78

78:                                               ; preds = %58
  %79 = load i32, ptr %7, align 4, !tbaa !16
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %7, align 4, !tbaa !16
  br label %51, !llvm.loop !32

81:                                               ; preds = %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  ret void
}

declare void @nc_blob_data_realloc3d(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"_ZTS5NcNet", !11, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 12}
!13 = !{!"_ZTS10px_image_t", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!14 = !{!13, !11, i64 8}
!15 = !{!13, !11, i64 16}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !11, i64 16}
!18 = !{!19, !11, i64 24}
!19 = !{!"_ZTS6NcBlob", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !20, i64 32, !6, i64 40}
!20 = !{!"_ZTS14NcBlobDimOrder", !7, i64 0}
!21 = !{!19, !11, i64 28}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!10, !11, i64 0}
!25 = !{!10, !6, i64 8}
!26 = !{!27, !6, i64 32}
!27 = !{!"_ZTS7NcLayer", !28, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!28 = !{!"_ZTS11NcLayerType", !7, i64 0}
!29 = !{!27, !6, i64 8}
!30 = !{!27, !6, i64 40}
!31 = !{!27, !6, i64 48}
!32 = distinct !{!32, !23}


; 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 uwtable
define dso_local void @_Z8nc_inferP5NcNetP10px_image_t(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %1, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = load i32, ptr %10, align 8, !tbaa !15
  tail call void @nc_blob_data_realloc3d(ptr noundef %5, i32 noundef %7, i32 noundef %9, i32 noundef %11)
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load i32, ptr %12, align 8, !tbaa !16
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %wide.trip.count = zext nneg i32 %13 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %16 = icmp ult i32 %13, 4
  br i1 %16, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.new

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

.preheader.loopexit.unr-lcssa:                    ; preds = %25, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %25 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.epil.preheader

.epil.preheader:                                  ; preds = %.preheader.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %.preheader.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.preheader.loopexit.unr-lcssa ]
  %17 = getelementptr inbounds ptr, ptr %15, i64 %indvars.iv.epil
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %18, i64 24
  %20 = load i32, ptr %19, align 8, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %18, i64 28
  store i32 %20, ptr %21, align 4, !tbaa !20
  %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 %.preheader, label %.epil.preheader, !llvm.loop !21

.preheader:                                       ; preds = %.preheader.loopexit.unr-lcssa, %.epil.preheader, %2
  %22 = load i32, ptr %0, align 8, !tbaa !23
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph22, label %._crit_edge

.lr.ph22:                                         ; preds = %.preheader
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  br label %46

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

._crit_edge:                                      ; preds = %46, %.preheader
  ret void

46:                                               ; preds = %.lr.ph22, %46
  %indvars.iv24 = phi i64 [ 0, %.lr.ph22 ], [ %indvars.iv.next25, %46 ]
  %47 = load ptr, ptr %24, align 8, !tbaa !26
  %48 = getelementptr inbounds ptr, ptr %47, i64 %indvars.iv24
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  %50 = getelementptr inbounds i8, ptr %49, i64 32
  %51 = load ptr, ptr %50, align 8, !tbaa !27
  %52 = getelementptr inbounds i8, ptr %49, i64 8
  %53 = load ptr, ptr %52, align 8, !tbaa !30
  %54 = getelementptr inbounds i8, ptr %49, i64 40
  %55 = load ptr, ptr %54, align 8, !tbaa !31
  %56 = getelementptr inbounds i8, ptr %49, i64 48
  %57 = load ptr, ptr %56, align 8, !tbaa !32
  tail call void %51(ptr noundef %53, ptr noundef %55, ptr noundef %57)
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %58 = load i32, ptr %0, align 8, !tbaa !23
  %59 = sext i32 %58 to i64
  %60 = icmp slt i64 %indvars.iv.next25, %59
  br i1 %60, label %46, label %._crit_edge, !llvm.loop !33
}

declare void @nc_blob_data_realloc3d(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { "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, !10, i64 24}
!6 = !{!"_ZTS5NcNet", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!13, !7, i64 12}
!13 = !{!"_ZTS10px_image_t", !10, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!14 = !{!13, !7, i64 8}
!15 = !{!13, !7, i64 16}
!16 = !{!6, !7, i64 16}
!17 = !{!18, !7, i64 24}
!18 = !{!"_ZTS6NcBlob", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !19, i64 32, !10, i64 40}
!19 = !{!"_ZTS14NcBlobDimOrder", !8, i64 0}
!20 = !{!18, !7, i64 28}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.unroll.disable"}
!23 = !{!6, !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!6, !10, i64 8}
!27 = !{!28, !10, i64 32}
!28 = !{!"_ZTS7NcLayer", !29, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48}
!29 = !{!"_ZTS11NcLayerType", !8, i64 0}
!30 = !{!28, !10, i64 8}
!31 = !{!28, !10, i64 40}
!32 = !{!28, !10, i64 48}
!33 = distinct !{!33, !25}


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