; LLVM IR from microsoft/LightAIMD :: src (matrix)

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

; 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 i64 @is_symmetric(ptr noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %53, %3
  %13 = load i64, ptr %8, align 8, !tbaa !9
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 2, ptr %9, align 4
  br label %56

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = load i64, ptr %7, align 8, !tbaa !9
  %20 = mul i64 %18, %19
  store i64 %20, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %44, %17
  %22 = load i64, ptr %11, align 8, !tbaa !9
  %23 = load i64, ptr %7, align 8, !tbaa !9
  %24 = icmp ult i64 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 5, ptr %9, align 4
  br label %47

26:                                               ; preds = %21
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = add i64 %28, %29
  %31 = getelementptr inbounds double, ptr %27, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i64, ptr %11, align 8, !tbaa !9
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = mul i64 %34, %35
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = add i64 %36, %37
  %39 = getelementptr inbounds double, ptr %33, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = fcmp une double %32, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %26
  store i64 0, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %47

43:                                               ; preds = %26
  br label %44

44:                                               ; preds = %43
  %45 = load i64, ptr %11, align 8, !tbaa !9
  %46 = add i64 %45, 1
  store i64 %46, ptr %11, align 8, !tbaa !9
  br label %21, !llvm.loop !13

47:                                               ; preds = %42, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %48 = load i32, ptr %9, align 4
  switch i32 %48, label %50 [
    i32 5, label %49
  ]

49:                                               ; preds = %47
  store i32 0, ptr %9, align 4
  br label %50

50:                                               ; preds = %49, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %51 = load i32, ptr %9, align 4
  switch i32 %51, label %56 [
    i32 0, label %52
  ]

52:                                               ; preds = %50
  br label %53

53:                                               ; preds = %52
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = add i64 %54, 1
  store i64 %55, ptr %8, align 8, !tbaa !9
  br label %12, !llvm.loop !15

56:                                               ; preds = %50, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %57 = load i32, ptr %9, align 4
  switch i32 %57, label %61 [
    i32 2, label %58
    i32 1, label %59
  ]

58:                                               ; preds = %56
  store i64 1, ptr %4, align 8
  br label %59

59:                                               ; preds = %58, %56
  %60 = load i64, ptr %4, align 8
  ret i64 %60

61:                                               ; preds = %56
  unreachable
}

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 }

!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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i64 @is_symmetric(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not2531 = icmp eq i64 %1, 0
  %.not29.not = icmp eq i64 %2, 0
  %or.cond = or i1 %.not2531, %.not29.not
  br i1 %or.cond, label %.thread, label %.lr.ph.us

.lr.ph.us:                                        ; preds = %3, %._crit_edge.us
  %.not2533.us = phi i1 [ %.not25.us, %._crit_edge.us ], [ false, %3 ]
  %.02232.us = phi i64 [ %14, %._crit_edge.us ], [ 0, %3 ]
  %4 = mul i64 %.02232.us, %2
  %invariant.gep.us = getelementptr double, ptr %0, i64 %.02232.us
  %5 = getelementptr double, ptr %0, i64 %4
  br label %8

6:                                                ; preds = %8
  %7 = add nuw i64 %.030.us, 1
  %exitcond.not = icmp eq i64 %7, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %8, !llvm.loop !5

8:                                                ; preds = %.lr.ph.us, %6
  %.030.us = phi i64 [ 0, %.lr.ph.us ], [ %7, %6 ]
  %9 = getelementptr double, ptr %5, i64 %.030.us
  %10 = load double, ptr %9, align 8, !tbaa !7
  %11 = mul i64 %.030.us, %2
  %gep.us = getelementptr double, ptr %invariant.gep.us, i64 %11
  %12 = load double, ptr %gep.us, align 8, !tbaa !7
  %13 = fcmp une double %10, %12
  br i1 %13, label %.thread, label %6

._crit_edge.us:                                   ; preds = %6
  %14 = add nuw i64 %.02232.us, 1
  %.not25.us = icmp uge i64 %14, %1
  %exitcond40 = icmp eq i64 %14, %1
  br i1 %exitcond40, label %.thread, label %.lr.ph.us, !llvm.loop !11

.thread:                                          ; preds = %._crit_edge.us, %8, %3
  %.not2528 = phi i1 [ true, %3 ], [ %.not2533.us, %8 ], [ %.not25.us, %._crit_edge.us ]
  %spec.select = zext i1 %.not2528 to i64
  ret i64 %spec.select
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = distinct !{!11, !6}


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