; LLVM IR from MaxGoryunov/LinearSystemsToolkit :: LinearSystemsToolkit (VectorTest)

; 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.Vector = type { ptr, i32 }

@.str.1 = external hidden unnamed_addr constant [100 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [48 x i8], align 1
@__PRETTY_FUNCTION__.calculatesDiffOfTwoVectors = external hidden unnamed_addr constant [34 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

declare ptr @vectorCreate(i32 noundef) #1

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

declare signext i8 @vectorEqual(ptr noundef, ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare void @vectorDestroy(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @calculatesDiffOfTwoVectors() #3 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 3, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = call ptr @vectorCreate(i32 noundef %6)
  store ptr %7, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = call ptr @vectorCreate(i32 noundef %8)
  store ptr %9, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = call ptr @vectorCreate(i32 noundef %10)
  store ptr %11, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %42, %0
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %45

17:                                               ; preds = %12
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = add nsw i32 %18, 4
  %20 = sitofp i32 %19 to double
  %21 = load ptr, ptr %2, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.Vector, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr %23, i64 %25
  store double %20, ptr %26, align 8, !tbaa !13
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  %29 = sitofp i32 %28 to double
  %30 = load ptr, ptr %3, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.Vector, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds double, ptr %32, i64 %34
  store double %29, ptr %35, align 8, !tbaa !13
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.Vector, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %38, i64 %40
  store double 3.000000e+00, ptr %41, align 8, !tbaa !13
  br label %42

42:                                               ; preds = %17
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %5, align 4, !tbaa !5
  br label %12, !llvm.loop !15

45:                                               ; preds = %16
  %46 = load ptr, ptr %2, align 8, !tbaa !9
  %47 = load ptr, ptr %3, align 8, !tbaa !9
  %48 = call ptr @vectorDiff(ptr noundef %46, ptr noundef %47)
  %49 = load ptr, ptr %4, align 8, !tbaa !9
  %50 = call signext i8 @vectorEqual(ptr noundef %48, ptr noundef %49)
  %51 = sext i8 %50 to i32
  %52 = icmp eq i32 1, %51
  br i1 %52, label %53, label %54

53:                                               ; preds = %45
  br label %55

54:                                               ; preds = %45
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 44, ptr noundef @__PRETTY_FUNCTION__.calculatesDiffOfTwoVectors) #5
  unreachable

55:                                               ; preds = %53
  %56 = load ptr, ptr %2, align 8, !tbaa !9
  call void @vectorDestroy(ptr noundef %56)
  %57 = load ptr, ptr %3, align 8, !tbaa !9
  call void @vectorDestroy(ptr noundef %57)
  %58 = load ptr, ptr %4, align 8, !tbaa !9
  call void @vectorDestroy(ptr noundef %58)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret void
}

declare ptr @vectorDiff(ptr noundef, 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 = { 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { 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 = !{!"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 = !{!12, !10, i64 0}
!12 = !{!"Vector", !10, i64 0, !6, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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.1 = external hidden unnamed_addr constant [100 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [48 x i8], align 1
@__PRETTY_FUNCTION__.calculatesDiffOfTwoVectors = external hidden unnamed_addr constant [34 x i8], align 1

declare ptr @vectorCreate(i32 noundef) local_unnamed_addr #0

declare signext i8 @vectorEqual(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare void @vectorDestroy(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @calculatesDiffOfTwoVectors() local_unnamed_addr #2 {
  %1 = tail call ptr @vectorCreate(i32 noundef 3) #3
  %2 = tail call ptr @vectorCreate(i32 noundef 3) #3
  %3 = tail call ptr @vectorCreate(i32 noundef 3) #3
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  store double 4.000000e+00, ptr %4, align 8, !tbaa !11
  store double 1.000000e+00, ptr %5, align 8, !tbaa !11
  store double 3.000000e+00, ptr %6, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  store double 5.000000e+00, ptr %7, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %5, i64 8
  store double 2.000000e+00, ptr %8, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %6, i64 8
  store double 3.000000e+00, ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %4, i64 16
  store double 6.000000e+00, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %5, i64 16
  store double 3.000000e+00, ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %6, i64 16
  store double 3.000000e+00, ptr %12, align 8, !tbaa !11
  %13 = tail call ptr @vectorDiff(ptr noundef nonnull %1, ptr noundef nonnull %2) #3
  %14 = tail call signext i8 @vectorEqual(ptr noundef %13, ptr noundef nonnull %3) #3
  %15 = icmp eq i8 %14, 1
  br i1 %15, label %17, label %16

16:                                               ; preds = %0
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 44, ptr noundef nonnull @__PRETTY_FUNCTION__.calculatesDiffOfTwoVectors) #4
  unreachable

17:                                               ; preds = %0
  tail call void @vectorDestroy(ptr noundef nonnull %1) #3
  tail call void @vectorDestroy(ptr noundef nonnull %2) #3
  tail call void @vectorDestroy(ptr noundef nonnull %3) #3
  ret void
}

declare ptr @vectorDiff(ptr noundef, ptr noundef) local_unnamed_addr #0

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 = { 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 #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 }
attributes #4 = { 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, !7, i64 0}
!6 = !{!"Vector", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass