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

; 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.2 = 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_hstack(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 0
  %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 0
  %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 !9
  %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 !12
  %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 !9
  %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 !12
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str.2, 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 !9
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Matrix, ptr %39, i32 0, i32 1
  %41 = load i64, ptr %40, align 8, !tbaa !12
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Matrix, ptr %42, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !12
  %45 = add nsw i64 %41, %44
  %46 = call ptr @xmat_diag(i64 noundef %38, 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 !9
  %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 !12
  %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 !9
  %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 !12
  %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 i64, ptr %11, align 8, !tbaa !13
  %102 = load ptr, ptr %3, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.Matrix, ptr %102, i32 0, i32 1
  %104 = load i64, ptr %103, align 8, !tbaa !12
  %105 = add nsw i64 %101, %104
  %106 = load double, ptr %12, align 8, !tbaa !14
  call void @mat_write(ptr noundef %99, i64 noundef %100, 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 0}
!10 = !{!"", !11, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!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.2 = 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_hstack(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = load i64, ptr %0, align 8, !tbaa !5
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %3, %4
  br i1 %.not, label %12, label %5

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

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

.preheader42.lr.ph:                               ; preds = %12
  %21 = load i64, ptr %13, align 8, !tbaa !12
  %22 = icmp sgt i64 %21, 0
  br i1 %22, label %.preheader42, label %.preheader41

.preheader42:                                     ; preds = %.preheader42.lr.ph, %._crit_edge
  %23 = phi i64 [ %30, %._crit_edge ], [ %19, %.preheader42.lr.ph ]
  %24 = phi i64 [ %31, %._crit_edge ], [ %21, %.preheader42.lr.ph ]
  %.044 = phi i64 [ %32, %._crit_edge ], [ 0, %.preheader42.lr.ph ]
  %25 = icmp sgt i64 %24, 0
  br i1 %25, label %.lr.ph, label %._crit_edge

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

.preheader.lr.ph:                                 ; preds = %.preheader41
  %28 = load i64, ptr %15, align 8, !tbaa !12
  %29 = icmp sgt i64 %28, 0
  br i1 %29, label %.preheader, label %._crit_edge49

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

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader42
  %30 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %23, %.preheader42 ]
  %31 = phi i64 [ %36, %._crit_edge.loopexit ], [ %24, %.preheader42 ]
  %32 = add nuw nsw i64 %.044, 1
  %33 = icmp slt i64 %32, %30
  br i1 %33, label %.preheader42, label %.preheader41, !llvm.loop !13

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

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge47
  %38 = phi i64 [ %41, %._crit_edge47 ], [ %26, %.preheader.lr.ph ]
  %39 = phi i64 [ %42, %._crit_edge47 ], [ %28, %.preheader.lr.ph ]
  %.03748 = phi i64 [ %43, %._crit_edge47 ], [ 0, %.preheader.lr.ph ]
  %40 = icmp sgt i64 %39, 0
  br i1 %40, label %.lr.ph46, label %._crit_edge47

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

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

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

.lr.ph46:                                         ; preds = %.preheader, %.lr.ph46
  %.03645 = phi i64 [ %48, %.lr.ph46 ], [ 0, %.preheader ]
  %45 = tail call double @mat_read(ptr noundef nonnull %1, i64 noundef %.03748, i64 noundef %.03645) #6
  %46 = load i64, ptr %13, align 8, !tbaa !12
  %47 = add nsw i64 %46, %.03645
  tail call void @mat_write(ptr noundef %18, i64 noundef %.03748, i64 noundef %47, double noundef %45) #6
  %48 = add nuw nsw i64 %.03645, 1
  %49 = load i64, ptr %15, align 8, !tbaa !12
  %50 = icmp slt i64 %48, %49
  br i1 %50, 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 0}
!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 8}
!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