; LLVM IR from HarshCasper/NeoAlgo :: C/math (matrix_subtraction)

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

@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @input(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = zext i32 %14 to i64
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = zext i32 %16 to i64
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = zext i32 %18 to i64
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = zext i32 %20 to i64
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %48, %4
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %51

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %44, %28
  %30 = load i32, ptr %11, align 4, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %47

34:                                               ; preds = %29
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = load i32, ptr %9, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = mul nsw i64 %37, %17
  %39 = getelementptr inbounds i32, ptr %35, i64 %38
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %39, i64 %41
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef %42)
  br label %44

44:                                               ; preds = %34
  %45 = load i32, ptr %11, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %11, align 4, !tbaa !5
  br label %29, !llvm.loop !11

47:                                               ; preds = %33
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %9, align 4, !tbaa !5
  br label %23, !llvm.loop !13

51:                                               ; preds = %27
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %78, %51
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %58, label %57

57:                                               ; preds = %53
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %81

58:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %74, %58
  %60 = load i32, ptr %13, align 4, !tbaa !5
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = icmp slt i32 %60, %61
  br i1 %62, label %64, label %63

63:                                               ; preds = %59
  store i32 11, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %77

64:                                               ; preds = %59
  %65 = load ptr, ptr %8, align 8, !tbaa !9
  %66 = load i32, ptr %12, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = mul nsw i64 %67, %21
  %69 = getelementptr inbounds i32, ptr %65, i64 %68
  %70 = load i32, ptr %13, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i32, ptr %69, i64 %71
  %73 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef %72)
  br label %74

74:                                               ; preds = %64
  %75 = load i32, ptr %13, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %13, align 4, !tbaa !5
  br label %59, !llvm.loop !14

77:                                               ; preds = %63
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %12, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %12, align 4, !tbaa !5
  br label %53, !llvm.loop !15

81:                                               ; preds = %57
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  ret void
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

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


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

@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @input(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = zext i32 %1 to i64
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %7 = icmp sgt i32 %0, 0
  %8 = icmp sgt i32 %1, 0
  %or.cond52 = and i1 %7, %8
  br i1 %or.cond52, label %.preheader25.us.preheader, label %._crit_edge31.sink.split

.preheader25.us.preheader:                        ; preds = %4
  %wide.trip.count39 = zext nneg i32 %0 to i64
  br label %.preheader25.us

.preheader25.us:                                  ; preds = %.preheader25.us.preheader, %._crit_edge.us
  %indvars.iv36 = phi i64 [ 0, %.preheader25.us.preheader ], [ %indvars.iv.next37, %._crit_edge.us ]
  %9 = mul nuw nsw i64 %indvars.iv36, %5
  %10 = getelementptr inbounds i32, ptr %2, i64 %9
  br label %11

11:                                               ; preds = %.preheader25.us, %11
  %indvars.iv = phi i64 [ 0, %.preheader25.us ], [ %indvars.iv.next, %11 ]
  %12 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv
  %13 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef %12)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %5
  br i1 %exitcond.not, label %._crit_edge.us, label %11, !llvm.loop !5

._crit_edge.us:                                   ; preds = %11
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond40.not = icmp eq i64 %indvars.iv.next37, %wide.trip.count39
  br i1 %exitcond40.not, label %._crit_edge28, label %.preheader25.us, !llvm.loop !7

._crit_edge28:                                    ; preds = %._crit_edge.us
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br i1 %7, label %.preheader.us.preheader, label %._crit_edge31

.preheader.us.preheader:                          ; preds = %._crit_edge28
  %wide.trip.count49 = zext nneg i32 %0 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us32
  %indvars.iv46 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next47, %._crit_edge.us32 ]
  %15 = mul nuw nsw i64 %indvars.iv46, %5
  %16 = getelementptr inbounds i32, ptr %3, i64 %15
  br label %17

17:                                               ; preds = %.preheader.us, %17
  %indvars.iv41 = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next42, %17 ]
  %18 = getelementptr inbounds i32, ptr %16, i64 %indvars.iv41
  %19 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef %18)
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %exitcond45.not = icmp eq i64 %indvars.iv.next42, %5
  br i1 %exitcond45.not, label %._crit_edge.us32, label %17, !llvm.loop !8

._crit_edge.us32:                                 ; preds = %17
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %exitcond50.not = icmp eq i64 %indvars.iv.next47, %wide.trip.count49
  br i1 %exitcond50.not, label %._crit_edge31, label %.preheader.us, !llvm.loop !9

._crit_edge31.sink.split:                         ; preds = %4
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %._crit_edge31

._crit_edge31:                                    ; preds = %._crit_edge.us32, %._crit_edge31.sink.split, %._crit_edge28
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  ret void
}

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

attributes #0 = { 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 #1 = { 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" }

!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 = distinct !{!7, !6}
!8 = distinct !{!8, !6}
!9 = distinct !{!9, !6}


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