; 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_copy_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 = add 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 = add 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 = add 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 = add 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 = %121, %3
  %39 = load i32, ptr %10, align 4, !tbaa !15
  %40 = load i32, ptr %6, align 4, !tbaa !15
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

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

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

44:                                               ; preds = %117, %43
  %45 = load i32, ptr %12, align 4, !tbaa !15
  %46 = load i32, ptr %7, align 4, !tbaa !15
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %49, label %48

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

49:                                               ; preds = %44
  %50 = load i32, ptr %10, align 4, !tbaa !15
  %51 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 0
  %52 = load i32, ptr %51, align 4, !tbaa !12
  %53 = icmp slt i32 %50, %52
  br i1 %53, label %77, label %54

54:                                               ; preds = %49
  %55 = load i32, ptr %12, align 4, !tbaa !15
  %56 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 2
  %57 = load i32, ptr %56, align 4, !tbaa !17
  %58 = icmp slt i32 %55, %57
  br i1 %58, label %77, label %59

59:                                               ; preds = %54
  %60 = load i32, ptr %10, align 4, !tbaa !15
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.matrix_t, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 0
  %65 = load i32, ptr %64, align 4, !tbaa !12
  %66 = add nsw i32 %63, %65
  %67 = icmp sge i32 %60, %66
  br i1 %67, label %77, label %68

68:                                               ; preds = %59
  %69 = load i32, ptr %12, align 4, !tbaa !15
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.matrix_t, ptr %70, i32 0, i32 1
  %72 = load i32, ptr %71, align 4, !tbaa !16
  %73 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 2
  %74 = load i32, ptr %73, align 4, !tbaa !17
  %75 = add nsw i32 %72, %74
  %76 = icmp sge i32 %69, %75
  br i1 %76, label %77, label %88

77:                                               ; preds = %68, %59, %54, %49
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.matrix_t, ptr %78, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !19
  %81 = load i32, ptr %10, align 4, !tbaa !15
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds ptr, ptr %80, i64 %82
  %84 = load ptr, ptr %83, align 8, !tbaa !5
  %85 = load i32, ptr %12, align 4, !tbaa !15
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds float, ptr %84, i64 %86
  store float 0.000000e+00, ptr %87, align 4, !tbaa !20
  br label %116

88:                                               ; preds = %68
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.matrix_t, ptr %89, i32 0, i32 2
  %91 = load ptr, ptr %90, align 8, !tbaa !19
  %92 = load i32, ptr %10, align 4, !tbaa !15
  %93 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 0
  %94 = load i32, ptr %93, align 4, !tbaa !12
  %95 = sub nsw i32 %92, %94
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds ptr, ptr %91, i64 %96
  %98 = load ptr, ptr %97, align 8, !tbaa !5
  %99 = load i32, ptr %12, align 4, !tbaa !15
  %100 = getelementptr inbounds %struct.px_pad_t, ptr %4, i32 0, i32 2
  %101 = load i32, ptr %100, align 4, !tbaa !17
  %102 = sub nsw i32 %99, %101
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds float, ptr %98, i64 %103
  %105 = load float, ptr %104, align 4, !tbaa !20
  %106 = load ptr, ptr %9, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.matrix_t, ptr %106, i32 0, i32 2
  %108 = load ptr, ptr %107, align 8, !tbaa !19
  %109 = load i32, ptr %10, align 4, !tbaa !15
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds ptr, ptr %108, i64 %110
  %112 = load ptr, ptr %111, align 8, !tbaa !5
  %113 = load i32, ptr %12, align 4, !tbaa !15
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds float, ptr %112, i64 %114
  store float %105, ptr %115, align 4, !tbaa !20
  br label %116

116:                                              ; preds = %88, %77
  br label %117

117:                                              ; preds = %116
  %118 = load i32, ptr %12, align 4, !tbaa !15
  %119 = add nsw i32 %118, 1
  store i32 %119, ptr %12, align 4, !tbaa !15
  br label %44, !llvm.loop !22

120:                                              ; preds = %48
  br label %121

121:                                              ; preds = %120
  %122 = load i32, ptr %10, align 4, !tbaa !15
  %123 = add nsw i32 %122, 1
  store i32 %123, ptr %10, align 4, !tbaa !15
  br label %38, !llvm.loop !24

124:                                              ; preds = %42
  %125 = 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 %125
}

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_copy_make_border(ptr nocapture noundef readonly %0, i64 %1, i64 %2) local_unnamed_addr #1 {
  %.sroa.025.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.025.0.extract.trunc
  %6 = add i32 %5, %4
  %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 = add i32 %9, %8
  %11 = tail call i64 @px_create_size(i32 noundef %6, i32 noundef %10) #3
  %12 = tail call ptr @create_matrix(i64 %11)
  %13 = icmp sgt i32 %6, 0
  br i1 %13, label %.preheader.lr.ph, label %._crit_edge37

.preheader.lr.ph:                                 ; preds = %3
  %14 = icmp sgt i32 %10, 0
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = getelementptr inbounds i8, ptr %12, i64 8
  br i1 %14, label %.preheader.us.preheader, label %._crit_edge37

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %sext = shl i64 %2, 32
  %17 = ashr exact i64 %sext, 32
  %18 = add i32 %8, %.sroa.6.8.extract.trunc
  %19 = add i32 %18, %.sroa.11.8.extract.trunc
  %20 = add i32 %19, -1
  %21 = zext i32 %20 to i64
  %22 = shl nuw nsw i64 %21, 2
  %23 = add nuw nsw i64 %22, 4
  %sext52 = shl i64 %1, 32
  %24 = ashr exact i64 %sext52, 32
  %wide.trip.count50 = zext nneg i32 %6 to i64
  %wide.trip.count = zext nneg i32 %10 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv47 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next48, %._crit_edge.us ]
  %25 = icmp slt i64 %indvars.iv47, %24
  %26 = sub nsw i64 %indvars.iv47, %24
  %.fr.us = freeze i1 %25
  br i1 %.fr.us, label %.lr.ph.split.us.us, label %.lr.ph.split.us40.preheader

.lr.ph.split.us40.preheader:                      ; preds = %.preheader.us
  %27 = load ptr, ptr %16, align 8, !tbaa !12
  %28 = getelementptr inbounds ptr, ptr %27, i64 %indvars.iv47
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  br label %.lr.ph.split.us40

.lr.ph.split.us40:                                ; preds = %.lr.ph.split.us40.preheader, %46
  %indvars.iv = phi i64 [ %indvars.iv.next, %46 ], [ 0, %.lr.ph.split.us40.preheader ]
  %30 = icmp slt i64 %indvars.iv, %17
  br i1 %30, label %46, label %31

31:                                               ; preds = %.lr.ph.split.us40
  %32 = load i32, ptr %0, align 8, !tbaa !5
  %33 = add nsw i32 %32, %.sroa.025.0.extract.trunc
  %34 = sext i32 %33 to i64
  %.not.us = icmp slt i64 %indvars.iv47, %34
  br i1 %.not.us, label %35, label %46

35:                                               ; preds = %31
  %36 = load i32, ptr %7, align 4, !tbaa !11
  %37 = add nsw i32 %36, %.sroa.6.8.extract.trunc
  %38 = sext i32 %37 to i64
  %.not33.us = icmp slt i64 %indvars.iv, %38
  br i1 %.not33.us, label %39, label %46

39:                                               ; preds = %35
  %40 = load ptr, ptr %15, align 8, !tbaa !12
  %41 = getelementptr inbounds ptr, ptr %40, i64 %26
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = sub nsw i64 %indvars.iv, %17
  %44 = getelementptr inbounds float, ptr %42, i64 %43
  %45 = load float, ptr %44, align 4, !tbaa !14
  br label %46

46:                                               ; preds = %.lr.ph.split.us40, %31, %35, %39
  %.sink = phi float [ %45, %39 ], [ 0.000000e+00, %35 ], [ 0.000000e+00, %31 ], [ 0.000000e+00, %.lr.ph.split.us40 ]
  %47 = getelementptr inbounds float, ptr %29, i64 %indvars.iv
  store float %.sink, ptr %47, align 4, !tbaa !14
  %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.us40, !llvm.loop !16

._crit_edge.us:                                   ; preds = %46, %.lr.ph.split.us.us
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %exitcond51.not = icmp eq i64 %indvars.iv.next48, %wide.trip.count50
  br i1 %exitcond51.not, label %._crit_edge37, label %.preheader.us, !llvm.loop !18

.lr.ph.split.us.us:                               ; preds = %.preheader.us
  %48 = load ptr, ptr %16, align 8, !tbaa !12
  %49 = getelementptr inbounds ptr, ptr %48, i64 %indvars.iv47
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %50, i8 0, i64 %23, i1 false), !tbaa !14
  br label %._crit_edge.us

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !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,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass