; LLVM IR from zchrissirhcz/pixel :: legacy/NaiveCNN/cnn (mat)

; 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.px_pad_t = type { i32, i32, i32, i32 }
%struct.px_size_t = type { i32, i32 }
%struct.matrix_t = type { 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i64 @px_create_size(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @create_matrix(i64) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @matrix_cut_make_border(ptr noundef %0, i64 %1, i64 %2) #2 {
  %4 = alloca %struct.px_pad_t, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.px_size_t, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 0
  store i64 %1, ptr %13, align 4
  %14 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 1
  store i64 %2, ptr %14, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.matrix_t, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 0
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = sub nsw i32 %17, %19
  %21 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !14
  %23 = sub nsw i32 %20, %22
  store i32 %23, ptr %6, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.matrix_t, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !16
  %27 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 2
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %29 = sub nsw i32 %26, %28
  %30 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 3
  %31 = load i32, ptr %30, align 4, !tbaa !18
  %32 = sub nsw i32 %29, %31
  store i32 %32, ptr %7, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %33 = load i32, ptr %6, align 4, !tbaa !15
  %34 = load i32, ptr %7, align 4, !tbaa !15
  %35 = call i64 @px_create_size(i32 noundef %33, i32 noundef %34)
  store i64 %35, ptr %8, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %36 = load i64, ptr %8, align 4
  %37 = call ptr @create_matrix(i64 %36)
  store ptr %37, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !15
  br label %38

38:                                               ; preds = %114, %3
  %39 = load i32, ptr %10, align 4, !tbaa !15
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.matrix_t, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !9
  %43 = icmp slt i32 %39, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %38
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %117

45:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !15
  br label %46

46:                                               ; preds = %110, %45
  %47 = load i32, ptr %12, align 4, !tbaa !15
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.matrix_t, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !16
  %51 = icmp slt i32 %47, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %46
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %113

53:                                               ; preds = %46
  %54 = load i32, ptr %10, align 4, !tbaa !15
  %55 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 0
  %56 = load i32, ptr %55, align 4, !tbaa !12
  %57 = icmp sge i32 %54, %56
  br i1 %57, label %58, label %109

58:                                               ; preds = %53
  %59 = load i32, ptr %12, align 4, !tbaa !15
  %60 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 2
  %61 = load i32, ptr %60, align 4, !tbaa !17
  %62 = icmp sge i32 %59, %61
  br i1 %62, label %63, label %109

63:                                               ; preds = %58
  %64 = load i32, ptr %10, align 4, !tbaa !15
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.matrix_t, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 0
  %69 = load i32, ptr %68, align 4, !tbaa !12
  %70 = sub nsw i32 %67, %69
  %71 = icmp slt i32 %64, %70
  br i1 %71, label %72, label %109

72:                                               ; preds = %63
  %73 = load i32, ptr %12, align 4, !tbaa !15
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.matrix_t, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !16
  %77 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 2
  %78 = load i32, ptr %77, align 4, !tbaa !17
  %79 = sub nsw i32 %76, %78
  %80 = icmp slt i32 %73, %79
  br i1 %80, label %81, label %109

81:                                               ; preds = %72
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.matrix_t, ptr %82, i32 0, i32 2
  %84 = load ptr, ptr %83, align 8, !tbaa !19
  %85 = load i32, ptr %10, align 4, !tbaa !15
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds ptr, ptr %84, i64 %86
  %88 = load ptr, ptr %87, align 8, !tbaa !5
  %89 = load i32, ptr %12, align 4, !tbaa !15
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds float, ptr %88, i64 %90
  %92 = load float, ptr %91, align 4, !tbaa !20
  %93 = load ptr, ptr %9, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.matrix_t, ptr %93, i32 0, i32 2
  %95 = load ptr, ptr %94, align 8, !tbaa !19
  %96 = load i32, ptr %10, align 4, !tbaa !15
  %97 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 0
  %98 = load i32, ptr %97, align 4, !tbaa !12
  %99 = sub nsw i32 %96, %98
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds ptr, ptr %95, i64 %100
  %102 = load ptr, ptr %101, align 8, !tbaa !5
  %103 = load i32, ptr %12, align 4, !tbaa !15
  %104 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 2
  %105 = load i32, ptr %104, align 4, !tbaa !17
  %106 = sub nsw i32 %103, %105
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds float, ptr %102, i64 %107
  store float %92, ptr %108, align 4, !tbaa !20
  br label %109

109:                                              ; preds = %81, %72, %63, %58, %53
  br label %110

110:                                              ; preds = %109
  %111 = load i32, ptr %12, align 4, !tbaa !15
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %12, align 4, !tbaa !15
  br label %46, !llvm.loop !22

113:                                              ; preds = %52
  br label %114

114:                                              ; preds = %113
  %115 = load i32, ptr %10, align 4, !tbaa !15
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %10, align 4, !tbaa !15
  br label %38, !llvm.loop !24

117:                                              ; preds = %44
  %118 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  ret ptr %118
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"matrix_t", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"px_pad_t", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!14 = !{!13, !11, i64 4}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !11, i64 4}
!17 = !{!13, !11, i64 8}
!18 = !{!13, !11, i64 12}
!19 = !{!10, !6, i64 8}
!20 = !{!21, !21, i64 0}
!21 = !{!"float", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !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"

declare i64 @px_create_size(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @create_matrix(i64) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @matrix_cut_make_border(ptr nocapture noundef readonly %0, i64 %1, i64 %2) local_unnamed_addr #1 {
  %.sroa.022.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.5.0.extract.shift = lshr i64 %1, 32
  %.sroa.5.0.extract.trunc = trunc nuw i64 %.sroa.5.0.extract.shift to i32
  %.sroa.6.8.extract.trunc = trunc i64 %2 to i32
  %.sroa.11.8.extract.shift = lshr i64 %2, 32
  %.sroa.11.8.extract.trunc = trunc nuw i64 %.sroa.11.8.extract.shift to i32
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = add i32 %.sroa.5.0.extract.trunc, %.sroa.022.0.extract.trunc
  %6 = sub i32 %4, %5
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = add i32 %.sroa.11.8.extract.trunc, %.sroa.6.8.extract.trunc
  %10 = sub i32 %8, %9
  %11 = tail call i64 @px_create_size(i32 noundef %6, i32 noundef %10) #2
  %12 = tail call ptr @create_matrix(i64 %11)
  %13 = load i32, ptr %0, align 8, !tbaa !5
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.preheader.lr.ph, label %._crit_edge38

.preheader.lr.ph:                                 ; preds = %3
  %15 = load i32, ptr %7, align 4, !tbaa !11
  %16 = icmp sgt i32 %15, 0
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = getelementptr inbounds i8, ptr %12, i64 8
  br i1 %16, label %.preheader.us.preheader, label %._crit_edge38

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %19 = sub nsw i32 %15, %.sroa.6.8.extract.trunc
  %20 = sub nsw i32 %13, %.sroa.022.0.extract.trunc
  %sext = shl i64 %2, 32
  %21 = ashr exact i64 %sext, 32
  %22 = sext i32 %19 to i64
  %sext54 = shl i64 %1, 32
  %23 = ashr exact i64 %sext54, 32
  %24 = sext i32 %20 to i64
  %wide.trip.count52 = zext nneg i32 %13 to i64
  %wide.trip.count = zext nneg i32 %15 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv49 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next50, %._crit_edge.us ]
  %.not.us = icmp slt i64 %indvars.iv49, %23
  %25 = sub nsw i64 %indvars.iv49, %23
  %.not.fr.us = freeze i1 %.not.us
  br i1 %.not.fr.us, label %._crit_edge.us, label %.lr.ph.split.us42

.lr.ph.split.split.us43:                          ; preds = %.lr.ph.split.us42, %38
  %indvars.iv = phi i64 [ %indvars.iv.next, %38 ], [ 0, %.lr.ph.split.us42 ]
  %.not31.us40 = icmp sge i64 %indvars.iv, %21
  %26 = icmp slt i64 %indvars.iv, %22
  %or.cond = select i1 %.not31.us40, i1 %26, i1 false
  br i1 %or.cond, label %27, label %38

27:                                               ; preds = %.lr.ph.split.split.us43
  %28 = load ptr, ptr %17, align 8, !tbaa !12
  %29 = getelementptr inbounds ptr, ptr %28, i64 %indvars.iv49
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = getelementptr inbounds float, ptr %30, i64 %indvars.iv
  %32 = load float, ptr %31, align 4, !tbaa !14
  %33 = load ptr, ptr %18, align 8, !tbaa !12
  %34 = getelementptr inbounds ptr, ptr %33, i64 %25
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = sub nsw i64 %indvars.iv, %21
  %37 = getelementptr inbounds float, ptr %35, i64 %36
  store float %32, ptr %37, align 4, !tbaa !14
  br label %38

38:                                               ; preds = %27, %.lr.ph.split.split.us43
  %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_edge.us, label %.lr.ph.split.split.us43, !llvm.loop !16

.lr.ph.split.us42:                                ; preds = %.preheader.us
  %39 = icmp slt i64 %indvars.iv49, %24
  %.fr.us = freeze i1 %39
  br i1 %.fr.us, label %.lr.ph.split.split.us43, label %._crit_edge.us

._crit_edge.us:                                   ; preds = %38, %.lr.ph.split.us42, %.preheader.us
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %exitcond53.not = icmp eq i64 %indvars.iv.next50, %wide.trip.count52
  br i1 %exitcond53.not, label %._crit_edge38, label %.preheader.us, !llvm.loop !18

._crit_edge38:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %3
  ret ptr %12
}

attributes #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 = { 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, !7, i64 0}
!6 = !{!"matrix_t", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 8}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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