; 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.matrix_t = type { i32, i32, ptr }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; 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
define dso_local void @matrix_add(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.matrix_t, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.matrix_t, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = icmp ne i32 %12, %15
  br i1 %16, label %25, label %17

17:                                               ; preds = %3
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.matrix_t, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !12
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.matrix_t, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !12
  %24 = icmp ne i32 %20, %23
  br i1 %24, label %25, label %32

25:                                               ; preds = %17, %3
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr @stderr, align 8, !tbaa !5
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str) #3
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str.1) #3
  br label %31

31:                                               ; preds = %26
  br label %89

32:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !13
  br label %33

33:                                               ; preds = %86, %32
  %34 = load i32, ptr %7, align 4, !tbaa !13
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.matrix_t, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !12
  %38 = icmp slt i32 %34, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %33
  store i32 4, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %89

40:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %41

41:                                               ; preds = %82, %40
  %42 = load i32, ptr %9, align 4, !tbaa !13
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.matrix_t, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = icmp slt i32 %42, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %41
  store i32 7, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %85

48:                                               ; preds = %41
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.matrix_t, ptr %49, i32 0, i32 2
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  %52 = load i32, ptr %7, align 4, !tbaa !13
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds ptr, ptr %51, i64 %53
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = load i32, ptr %9, align 4, !tbaa !13
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds float, ptr %55, i64 %57
  %59 = load float, ptr %58, align 4, !tbaa !15
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.matrix_t, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !14
  %63 = load i32, ptr %7, align 4, !tbaa !13
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds ptr, ptr %62, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !13
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds float, ptr %66, i64 %68
  %70 = load float, ptr %69, align 4, !tbaa !15
  %71 = fadd float %59, %70
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.matrix_t, ptr %72, i32 0, i32 2
  %74 = load ptr, ptr %73, align 8, !tbaa !14
  %75 = load i32, ptr %7, align 4, !tbaa !13
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds ptr, ptr %74, i64 %76
  %78 = load ptr, ptr %77, align 8, !tbaa !5
  %79 = load i32, ptr %9, align 4, !tbaa !13
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds float, ptr %78, i64 %80
  store float %71, ptr %81, align 4, !tbaa !15
  br label %82

82:                                               ; preds = %48
  %83 = load i32, ptr %9, align 4, !tbaa !13
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %9, align 4, !tbaa !13
  br label %41, !llvm.loop !17

85:                                               ; preds = %47
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %7, align 4, !tbaa !13
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %7, align 4, !tbaa !13
  br label %33, !llvm.loop !19

89:                                               ; preds = %39, %31
  ret void
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

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 "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 4}
!10 = !{!"matrix_t", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @matrix_add(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %5, %7
  br i1 %.not, label %8, label %71

8:                                                ; preds = %3
  %9 = load i32, ptr %0, align 8, !tbaa !11
  %10 = load i32, ptr %1, align 8, !tbaa !11
  %.not19 = icmp eq i32 %9, %10
  br i1 %.not19, label %.preheader20, label %71

.preheader20:                                     ; preds = %8
  %11 = icmp sgt i32 %9, 0
  %12 = icmp sgt i32 %5, 0
  %or.cond = and i1 %11, %12
  br i1 %or.cond, label %.preheader.lr.ph.split.us, label %.loopexit

.preheader.lr.ph.split.us:                        ; preds = %.preheader20
  %13 = getelementptr inbounds i8, ptr %2, i64 8
  %14 = getelementptr inbounds i8, ptr %1, i64 8
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = load ptr, ptr %14, align 8, !tbaa !12
  %18 = load ptr, ptr %13, align 8, !tbaa !12
  %wide.trip.count28 = zext nneg i32 %9 to i64
  %wide.trip.count = zext nneg i32 %5 to i64
  %min.iters.check = icmp ult i32 %5, 8
  %n.vec = and i64 %wide.trip.count, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph.split.us
  %indvars.iv25 = phi i64 [ %indvars.iv.next26, %._crit_edge.us ], [ 0, %.preheader.lr.ph.split.us ]
  %19 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv25
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds ptr, ptr %17, i64 %indvars.iv25
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds ptr, ptr %18, i64 %indvars.iv25
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.preheader.us
  %25 = ptrtoint ptr %24 to i64
  %26 = ptrtoint ptr %22 to i64
  %27 = ptrtoint ptr %20 to i64
  %28 = sub i64 %25, %27
  %diff.check = icmp ult i64 %28, 32
  %29 = sub i64 %25, %26
  %diff.check30 = icmp ult i64 %29, 32
  %conflict.rdx = or i1 %diff.check, %diff.check30
  br i1 %conflict.rdx, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %vector.memcheck, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.memcheck ]
  %30 = getelementptr inbounds float, ptr %20, i64 %index
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  %wide.load = load <4 x float>, ptr %30, align 4, !tbaa !14
  %wide.load31 = load <4 x float>, ptr %31, align 4, !tbaa !14
  %32 = getelementptr inbounds float, ptr %22, i64 %index
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  %wide.load32 = load <4 x float>, ptr %32, align 4, !tbaa !14
  %wide.load33 = load <4 x float>, ptr %33, align 4, !tbaa !14
  %34 = fadd <4 x float> %wide.load, %wide.load32
  %35 = fadd <4 x float> %wide.load31, %wide.load33
  %36 = getelementptr inbounds float, ptr %24, i64 %index
  %37 = getelementptr inbounds i8, ptr %36, i64 16
  store <4 x float> %34, ptr %36, align 4, !tbaa !14
  store <4 x float> %35, ptr %37, align 4, !tbaa !14
  %index.next = add nuw i64 %index, 8
  %38 = icmp eq i64 %index.next, %n.vec
  br i1 %38, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.preheader.us
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  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.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %39 = getelementptr inbounds float, ptr %20, i64 %indvars.iv.prol
  %40 = load float, ptr %39, align 4, !tbaa !14
  %41 = getelementptr inbounds float, ptr %22, i64 %indvars.iv.prol
  %42 = load float, ptr %41, align 4, !tbaa !14
  %43 = fadd float %40, %42
  %44 = getelementptr inbounds float, ptr %24, i64 %indvars.iv.prol
  store float %43, ptr %44, align 4, !tbaa !14
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.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 !20

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %45 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %46 = icmp ugt i64 %45, -4
  br i1 %46, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %47 = getelementptr inbounds float, ptr %20, i64 %indvars.iv
  %48 = load float, ptr %47, align 4, !tbaa !14
  %49 = getelementptr inbounds float, ptr %22, i64 %indvars.iv
  %50 = load float, ptr %49, align 4, !tbaa !14
  %51 = fadd float %48, %50
  %52 = getelementptr inbounds float, ptr %24, i64 %indvars.iv
  store float %51, ptr %52, align 4, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %53 = getelementptr inbounds float, ptr %20, i64 %indvars.iv.next
  %54 = load float, ptr %53, align 4, !tbaa !14
  %55 = getelementptr inbounds float, ptr %22, i64 %indvars.iv.next
  %56 = load float, ptr %55, align 4, !tbaa !14
  %57 = fadd float %54, %56
  %58 = getelementptr inbounds float, ptr %24, i64 %indvars.iv.next
  store float %57, ptr %58, align 4, !tbaa !14
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %59 = getelementptr inbounds float, ptr %20, i64 %indvars.iv.next.1
  %60 = load float, ptr %59, align 4, !tbaa !14
  %61 = getelementptr inbounds float, ptr %22, i64 %indvars.iv.next.1
  %62 = load float, ptr %61, align 4, !tbaa !14
  %63 = fadd float %60, %62
  %64 = getelementptr inbounds float, ptr %24, i64 %indvars.iv.next.1
  store float %63, ptr %64, align 4, !tbaa !14
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %65 = getelementptr inbounds float, ptr %20, i64 %indvars.iv.next.2
  %66 = load float, ptr %65, align 4, !tbaa !14
  %67 = getelementptr inbounds float, ptr %22, i64 %indvars.iv.next.2
  %68 = load float, ptr %67, align 4, !tbaa !14
  %69 = fadd float %66, %68
  %70 = getelementptr inbounds float, ptr %24, i64 %indvars.iv.next.2
  store float %69, ptr %70, align 4, !tbaa !14
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge.us, label %scalar.ph, !llvm.loop !22

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next26, %wide.trip.count28
  br i1 %exitcond29.not, label %.loopexit, label %.preheader.us, !llvm.loop !23

71:                                               ; preds = %3, %8
  %72 = load ptr, ptr @stderr, align 8, !tbaa !13
  %73 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %72, ptr noundef nonnull @.str) #2
  %74 = load ptr, ptr @stderr, align 8, !tbaa !13
  %75 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef nonnull @.str.1) #2
  br label %.loopexit

.loopexit:                                        ; preds = %._crit_edge.us, %.preheader20, %71
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { 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 #1 = { nofree nounwind "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 = { cold 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 4}
!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 0}
!12 = !{!6, !10, i64 8}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !8, i64 0}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}
!22 = distinct !{!22, !17, !18}
!23 = distinct !{!23, !17}


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