; LLVM IR from TheAlgorithms/C-Plus-Plus :: numerical_methods/qr_eigen_values.ll (Z13create_matrixPSt8valarrayIS_IdEE)

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

%"class.std::valarray" = type { i64, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z13create_matrixPSt8valarrayIS_IdEE(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 4, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call noundef i64 @_ZNKSt8valarrayIS_IdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %8)
  %10 = trunc i64 %9 to i32
  store i32 %10, ptr %7, align 4, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %64, %1
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %15, label %67

15:                                               ; preds = %11
  %16 = call i32 @rand() #4
  %17 = srem i32 %16, 9
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sub nsw i32 %17, %18
  %20 = sitofp i32 %19 to double
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %"class.std::valarray", ptr %21, i64 0
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt8valarrayIS_IdEEixEm(ptr noundef nonnull align 8 dereferenceable(16) %22, i64 noundef %24) #4
  %26 = load i32, ptr %3, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIdEixEm(ptr noundef nonnull align 8 dereferenceable(16) %25, i64 noundef %27) #4
  store double %20, ptr %28, align 8, !tbaa !11
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %4, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %60, %15
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %63

35:                                               ; preds = %31
  %36 = call i32 @rand() #4
  %37 = srem i32 %36, 9
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = sub nsw i32 %37, %38
  store i32 %39, ptr %5, align 4, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = sitofp i32 %40 to double
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %"class.std::valarray", ptr %42, i64 0
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt8valarrayIS_IdEEixEm(ptr noundef nonnull align 8 dereferenceable(16) %43, i64 noundef %45) #4
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIdEixEm(ptr noundef nonnull align 8 dereferenceable(16) %46, i64 noundef %48) #4
  store double %41, ptr %49, align 8, !tbaa !11
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = sitofp i32 %50 to double
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %"class.std::valarray", ptr %52, i64 0
  %54 = load i32, ptr %4, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt8valarrayIS_IdEEixEm(ptr noundef nonnull align 8 dereferenceable(16) %53, i64 noundef %55) #4
  %57 = load i32, ptr %3, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIdEixEm(ptr noundef nonnull align 8 dereferenceable(16) %56, i64 noundef %58) #4
  store double %51, ptr %59, align 8, !tbaa !11
  br label %60

60:                                               ; preds = %35
  %61 = load i32, ptr %4, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %4, align 4, !tbaa !9
  br label %31, !llvm.loop !13

63:                                               ; preds = %31
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %3, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %3, align 4, !tbaa !9
  br label %11, !llvm.loop !15

67:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt8valarrayIS_IdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

; Function Attrs: nounwind
declare i32 @rand() #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt8valarrayIS_IdEEixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIdEixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #2 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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: mustprogress nounwind uwtable
define dso_local void @_Z13create_matrixPSt8valarrayIS_IdEE(ptr noundef nonnull %0) local_unnamed_addr #0 {
  %2 = tail call noundef i64 @_ZNKSt8valarrayIS_IdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %3 = trunc i64 %2 to i32
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph24.preheader, label %._crit_edge

.lr.ph24.preheader:                               ; preds = %1
  %5 = and i64 %2, 2147483647
  %wide.trip.count31 = and i64 %2, 2147483647
  br label %.lr.ph24

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph24
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond32.not = icmp eq i64 %indvars.iv.next29, %wide.trip.count31
  br i1 %exitcond32.not, label %._crit_edge, label %.lr.ph24, !llvm.loop !5

.lr.ph24:                                         ; preds = %.lr.ph24.preheader, %.loopexit
  %indvars.iv28 = phi i64 [ 0, %.lr.ph24.preheader ], [ %indvars.iv.next29, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph24.preheader ], [ %indvars.iv.next, %.loopexit ]
  %6 = tail call i32 @rand() #3
  %7 = srem i32 %6, 9
  %8 = add nsw i32 %7, -4
  %9 = sitofp i32 %8 to double
  %10 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt8valarrayIS_IdEEixEm(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %indvars.iv28) #3
  %11 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIdEixEm(ptr noundef nonnull align 8 dereferenceable(16) %10, i64 noundef %indvars.iv28) #3
  store double %9, ptr %11, align 8, !tbaa !7
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %12 = icmp ult i64 %indvars.iv.next29, %5
  br i1 %12, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph24, %.lr.ph
  %indvars.iv25 = phi i64 [ %indvars.iv.next26, %.lr.ph ], [ %indvars.iv, %.lr.ph24 ]
  %13 = tail call i32 @rand() #3
  %14 = srem i32 %13, 9
  %15 = add nsw i32 %14, -4
  %16 = sitofp i32 %15 to double
  %17 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt8valarrayIS_IdEEixEm(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %indvars.iv28) #3
  %18 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIdEixEm(ptr noundef nonnull align 8 dereferenceable(16) %17, i64 noundef %indvars.iv25) #3
  store double %16, ptr %18, align 8, !tbaa !7
  %19 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt8valarrayIS_IdEEixEm(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %indvars.iv25) #3
  %20 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIdEixEm(ptr noundef nonnull align 8 dereferenceable(16) %19, i64 noundef %indvars.iv28) #3
  store double %16, ptr %20, align 8, !tbaa !7
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next26, %wide.trip.count31
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %1
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt8valarrayIS_IdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt8valarrayIS_IdEEixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt8valarrayIdEixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 = 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++ TBAA"}
!11 = distinct !{!11, !6}


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