; LLVM IR from YanzhenHuang/c-nn :: xlinalg (xmat_vstack)

; 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 = type { i64, i64, ptr }

@stderr = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [76 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 void @mat_write(ptr noundef, i64 noundef, i64 noundef, double noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @xmat_diag(i64 noundef, i64 noundef, double noundef) #2

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

declare double @mat_read(ptr noundef, i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @xmat_vstack(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca double, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Matrix, ptr %13, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Matrix, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = icmp ne i64 %15, %18
  br i1 %19, label %20, label %35

20:                                               ; preds = %2
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Matrix, ptr %22, i32 0, i32 0
  %24 = load i64, ptr %23, align 8, !tbaa !12
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Matrix, ptr %25, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Matrix, ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !12
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Matrix, ptr %31, i32 0, i32 1
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str.4, i64 noundef %24, i64 noundef %27, i64 noundef %30, i64 noundef %33) #5
  call void @exit(i32 noundef 1) #6
  unreachable

35:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Matrix, ptr %36, i32 0, i32 0
  %38 = load i64, ptr %37, align 8, !tbaa !12
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Matrix, ptr %39, i32 0, i32 0
  %41 = load i64, ptr %40, align 8, !tbaa !12
  %42 = add nsw i64 %38, %41
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.Matrix, ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = call ptr @xmat_diag(i64 noundef %42, i64 noundef %45, double noundef 0.000000e+00)
  store ptr %46, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !13
  br label %47

47:                                               ; preds = %75, %35
  %48 = load i64, ptr %6, align 8, !tbaa !13
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Matrix, ptr %49, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !12
  %52 = icmp slt i64 %48, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %47
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %78

54:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 0, ptr %8, align 8, !tbaa !13
  br label %55

55:                                               ; preds = %71, %54
  %56 = load i64, ptr %8, align 8, !tbaa !13
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Matrix, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !9
  %60 = icmp slt i64 %56, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %55
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %74

62:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load i64, ptr %6, align 8, !tbaa !13
  %65 = load i64, ptr %8, align 8, !tbaa !13
  %66 = call double @mat_read(ptr noundef %63, i64 noundef %64, i64 noundef %65)
  store double %66, ptr %9, align 8, !tbaa !14
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load i64, ptr %6, align 8, !tbaa !13
  %69 = load i64, ptr %8, align 8, !tbaa !13
  %70 = load double, ptr %9, align 8, !tbaa !14
  call void @mat_write(ptr noundef %67, i64 noundef %68, i64 noundef %69, double noundef %70)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %71

71:                                               ; preds = %62
  %72 = load i64, ptr %8, align 8, !tbaa !13
  %73 = add nsw i64 %72, 1
  store i64 %73, ptr %8, align 8, !tbaa !13
  br label %55, !llvm.loop !16

74:                                               ; preds = %61
  br label %75

75:                                               ; preds = %74
  %76 = load i64, ptr %6, align 8, !tbaa !13
  %77 = add nsw i64 %76, 1
  store i64 %77, ptr %6, align 8, !tbaa !13
  br label %47, !llvm.loop !18

78:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 0, ptr %10, align 8, !tbaa !13
  br label %79

79:                                               ; preds = %111, %78
  %80 = load i64, ptr %10, align 8, !tbaa !13
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.Matrix, ptr %81, i32 0, i32 0
  %83 = load i64, ptr %82, align 8, !tbaa !12
  %84 = icmp slt i64 %80, %83
  br i1 %84, label %86, label %85

85:                                               ; preds = %79
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %114

86:                                               ; preds = %79
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 0, ptr %11, align 8, !tbaa !13
  br label %87

87:                                               ; preds = %107, %86
  %88 = load i64, ptr %11, align 8, !tbaa !13
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.Matrix, ptr %89, i32 0, i32 1
  %91 = load i64, ptr %90, align 8, !tbaa !9
  %92 = icmp slt i64 %88, %91
  br i1 %92, label %94, label %93

93:                                               ; preds = %87
  store i32 11, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %110

94:                                               ; preds = %87
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = load i64, ptr %10, align 8, !tbaa !13
  %97 = load i64, ptr %11, align 8, !tbaa !13
  %98 = call double @mat_read(ptr noundef %95, i64 noundef %96, i64 noundef %97)
  store double %98, ptr %12, align 8, !tbaa !14
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = load i64, ptr %10, align 8, !tbaa !13
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.Matrix, ptr %101, i32 0, i32 0
  %103 = load i64, ptr %102, align 8, !tbaa !12
  %104 = add nsw i64 %100, %103
  %105 = load i64, ptr %11, align 8, !tbaa !13
  %106 = load double, ptr %12, align 8, !tbaa !14
  call void @mat_write(ptr noundef %99, i64 noundef %104, i64 noundef %105, double noundef %106)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %107

107:                                              ; preds = %94
  %108 = load i64, ptr %11, align 8, !tbaa !13
  %109 = add nsw i64 %108, 1
  store i64 %109, ptr %11, align 8, !tbaa !13
  br label %87, !llvm.loop !19

110:                                              ; preds = %93
  br label %111

111:                                              ; preds = %110
  %112 = load i64, ptr %10, align 8, !tbaa !13
  %113 = add nsw i64 %112, 1
  store i64 %113, ptr %10, align 8, !tbaa !13
  br label %79, !llvm.loop !20

114:                                              ; preds = %85
  %115 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %115
}

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 "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 #4 = { noreturn 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 #5 = { nounwind }
attributes #6 = { noreturn 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 8}
!10 = !{!"", !11, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}
!20 = distinct !{!20, !17}


; 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.4 = external hidden unnamed_addr constant [76 x i8], align 1

declare void @mat_write(ptr noundef, i64 noundef, i64 noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @xmat_diag(i64 noundef, i64 noundef, double noundef) local_unnamed_addr #1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

declare double @mat_read(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @xmat_vstack(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i64 %4, %6
  br i1 %.not, label %12, label %7

7:                                                ; preds = %2
  %8 = load ptr, ptr @stderr, align 8, !tbaa !11
  %9 = load i64, ptr %0, align 8, !tbaa !12
  %10 = load i64, ptr %1, align 8, !tbaa !12
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.4, i64 noundef %9, i64 noundef %4, i64 noundef %10, i64 noundef %6) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

12:                                               ; preds = %2
  %13 = load i64, ptr %0, align 8, !tbaa !12
  %14 = shl nsw i64 %13, 1
  %15 = tail call ptr @xmat_diag(i64 noundef %14, i64 noundef %4, double noundef 0.000000e+00)
  %16 = load i64, ptr %0, align 8, !tbaa !12
  %17 = icmp sgt i64 %16, 0
  br i1 %17, label %.preheader42.lr.ph, label %.preheader41

.preheader42.lr.ph:                               ; preds = %12
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = icmp sgt i64 %18, 0
  br i1 %19, label %.preheader42, label %.preheader41

.preheader42:                                     ; preds = %.preheader42.lr.ph, %._crit_edge
  %20 = phi i64 [ %27, %._crit_edge ], [ %16, %.preheader42.lr.ph ]
  %21 = phi i64 [ %28, %._crit_edge ], [ %18, %.preheader42.lr.ph ]
  %.044 = phi i64 [ %29, %._crit_edge ], [ 0, %.preheader42.lr.ph ]
  %22 = icmp sgt i64 %21, 0
  br i1 %22, label %.lr.ph, label %._crit_edge

.preheader41:                                     ; preds = %._crit_edge, %.preheader42.lr.ph, %12
  %23 = load i64, ptr %1, align 8, !tbaa !12
  %24 = icmp sgt i64 %23, 0
  br i1 %24, label %.preheader.lr.ph, label %._crit_edge49

.preheader.lr.ph:                                 ; preds = %.preheader41
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = icmp sgt i64 %25, 0
  br i1 %26, label %.preheader, label %._crit_edge49

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i64, ptr %0, align 8, !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader42
  %27 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %20, %.preheader42 ]
  %28 = phi i64 [ %33, %._crit_edge.loopexit ], [ %21, %.preheader42 ]
  %29 = add nuw nsw i64 %.044, 1
  %30 = icmp slt i64 %29, %27
  br i1 %30, label %.preheader42, label %.preheader41, !llvm.loop !13

.lr.ph:                                           ; preds = %.preheader42, %.lr.ph
  %.03843 = phi i64 [ %32, %.lr.ph ], [ 0, %.preheader42 ]
  %31 = tail call double @mat_read(ptr noundef nonnull %0, i64 noundef %.044, i64 noundef %.03843) #6
  tail call void @mat_write(ptr noundef %15, i64 noundef %.044, i64 noundef %.03843, double noundef %31) #6
  %32 = add nuw nsw i64 %.03843, 1
  %33 = load i64, ptr %3, align 8, !tbaa !5
  %34 = icmp slt i64 %32, %33
  br i1 %34, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !16

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge47
  %35 = phi i64 [ %38, %._crit_edge47 ], [ %23, %.preheader.lr.ph ]
  %36 = phi i64 [ %39, %._crit_edge47 ], [ %25, %.preheader.lr.ph ]
  %.03748 = phi i64 [ %40, %._crit_edge47 ], [ 0, %.preheader.lr.ph ]
  %37 = icmp sgt i64 %36, 0
  br i1 %37, label %.lr.ph46, label %._crit_edge47

._crit_edge49:                                    ; preds = %._crit_edge47, %.preheader.lr.ph, %.preheader41
  ret ptr %15

._crit_edge47.loopexit:                           ; preds = %.lr.ph46
  %.pre52 = load i64, ptr %1, align 8, !tbaa !12
  br label %._crit_edge47

._crit_edge47:                                    ; preds = %._crit_edge47.loopexit, %.preheader
  %38 = phi i64 [ %.pre52, %._crit_edge47.loopexit ], [ %35, %.preheader ]
  %39 = phi i64 [ %46, %._crit_edge47.loopexit ], [ %36, %.preheader ]
  %40 = add nuw nsw i64 %.03748, 1
  %41 = icmp slt i64 %40, %38
  br i1 %41, label %.preheader, label %._crit_edge49, !llvm.loop !17

.lr.ph46:                                         ; preds = %.preheader, %.lr.ph46
  %.03645 = phi i64 [ %45, %.lr.ph46 ], [ 0, %.preheader ]
  %42 = tail call double @mat_read(ptr noundef nonnull %1, i64 noundef %.03748, i64 noundef %.03645) #6
  %43 = load i64, ptr %0, align 8, !tbaa !12
  %44 = add nsw i64 %43, %.03748
  tail call void @mat_write(ptr noundef %15, i64 noundef %44, i64 noundef %.03645, double noundef %42) #6
  %45 = add nuw nsw i64 %.03645, 1
  %46 = load i64, ptr %5, align 8, !tbaa !5
  %47 = icmp slt i64 %45, %46
  br i1 %47, label %.lr.ph46, label %._crit_edge47.loopexit, !llvm.loop !18
}

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 = { 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 #3 = { noreturn 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 #4 = { cold nounwind }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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 8}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !7, i64 0}
!13 = distinct !{!13, !14, !15}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.unswitch.partial.disable"}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14, !15}
!18 = distinct !{!18, !14}


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