; LLVM IR from ERGO-Code/HiGHS :: src/pdlp/cupdlp/cuda (test_cublas)

; 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 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1

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

20:                                               ; preds = %36, %1
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %39

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds double, ptr %26, i64 %28
  store double 1.000000e+00, ptr %29, align 8, !tbaa !11
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = sitofp i32 %30 to double
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds double, ptr %32, i64 %34
  store double %31, ptr %35, align 8, !tbaa !11
  br label %36

36:                                               ; preds = %25
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %7, align 4, !tbaa !9
  br label %20, !llvm.loop !13

39:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = mul i64 %41, 8
  %43 = call i32 @cudaMalloc(ptr noundef %8, i64 noundef %42)
  %44 = call i32 @check_cuda_call(i32 noundef %43, ptr noundef @.str, i32 noundef 23)
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %39
  store i32 1, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %91

47:                                               ; preds = %39
  %48 = load i32, ptr %4, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = mul i64 %49, 8
  %51 = call i32 @cudaMalloc(ptr noundef %9, i64 noundef %50)
  %52 = call i32 @check_cuda_call(i32 noundef %51, ptr noundef @.str, i32 noundef 27)
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %47
  store i32 1, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %91

55:                                               ; preds = %47
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load i32, ptr %4, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = mul i64 %59, 8
  %61 = call i32 @cudaMemcpy(ptr noundef %56, ptr noundef %57, i64 noundef %60, i32 noundef 1)
  %62 = call i32 @check_cuda_call(i32 noundef %61, ptr noundef @.str, i32 noundef 29)
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %55
  store i32 1, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %91

65:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = load i32, ptr %4, align 4, !tbaa !9
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = call i32 @cublasDnrm2_v2(ptr noundef %66, i32 noundef %67, ptr noundef %68, i32 noundef 1, ptr noundef %11)
  %70 = call i32 @check_cublas_call(i32 noundef %69, ptr noundef @.str, i32 noundef 37)
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %73

72:                                               ; preds = %65
  store i32 1, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %90

73:                                               ; preds = %65
  %74 = load double, ptr %11, align 8, !tbaa !11
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %74)
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %76) #6
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %77) #6
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = call i32 @cudaFree(ptr noundef %78)
  %80 = call i32 @check_cuda_call(i32 noundef %79, ptr noundef @.str, i32 noundef 66)
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %82, label %83

82:                                               ; preds = %73
  store i32 1, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %90

83:                                               ; preds = %73
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = call i32 @cudaFree(ptr noundef %84)
  %86 = call i32 @check_cuda_call(i32 noundef %85, ptr noundef @.str, i32 noundef 67)
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %89

88:                                               ; preds = %83
  store i32 1, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %90

89:                                               ; preds = %83
  store i32 0, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %90

90:                                               ; preds = %89, %88, %82, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  br label %91

91:                                               ; preds = %90, %64, %54, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  %92 = load i32, ptr %2, align 4
  ret i32 %92
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_cuda_call(i32 noundef, ptr noundef, i32 noundef) #3

declare i32 @cudaMalloc(ptr noundef, i64 noundef) #4

declare i32 @cudaMemcpy(ptr noundef, ptr noundef, i64 noundef, i32 noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_cublas_call(i32 noundef, ptr noundef, i32 noundef) #3

declare i32 @cublasDnrm2_v2(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) #4

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #5

declare i32 @cudaFree(ptr noundef) #4

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 = { inlinehint 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 = { "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 "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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, !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"}


; 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 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @use_cublas(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = tail call noalias dereferenceable_or_null(80) ptr @malloc(i64 noundef 80) #7
  store <2 x double> <double 0.000000e+00, double 1.000000e+00>, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  store <2 x double> <double 2.000000e+00, double 3.000000e+00>, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %5, i64 32
  store <2 x double> <double 4.000000e+00, double 5.000000e+00>, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %5, i64 48
  store <2 x double> <double 6.000000e+00, double 7.000000e+00>, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %5, i64 64
  store <2 x double> <double 8.000000e+00, double 9.000000e+00>, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #8
  %10 = call i32 @cudaMalloc(ptr noundef nonnull %2, i64 noundef 80) #8
  %11 = call i32 @check_cuda_call(i32 noundef %10, ptr noundef nonnull @.str, i32 noundef 23)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %34

12:                                               ; preds = %1
  %13 = call i32 @cudaMalloc(ptr noundef nonnull %3, i64 noundef 80) #8
  %14 = call i32 @check_cuda_call(i32 noundef %13, ptr noundef nonnull @.str, i32 noundef 27)
  %.not19 = icmp eq i32 %14, 0
  br i1 %.not19, label %15, label %34

15:                                               ; preds = %12
  %16 = load ptr, ptr %3, align 8, !tbaa !9
  %17 = call i32 @cudaMemcpy(ptr noundef %16, ptr noundef nonnull %5, i64 noundef 80, i32 noundef 1) #8
  %18 = call i32 @check_cuda_call(i32 noundef %17, ptr noundef nonnull @.str, i32 noundef 29)
  %.not20 = icmp eq i32 %18, 0
  br i1 %.not20, label %19, label %34

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #8
  %20 = load ptr, ptr %2, align 8, !tbaa !9
  %21 = call i32 @cublasDnrm2_v2(ptr noundef %0, i32 noundef 10, ptr noundef %20, i32 noundef 1, ptr noundef nonnull %4) #8
  %22 = call i32 @check_cublas_call(i32 noundef %21, ptr noundef nonnull @.str, i32 noundef 37)
  %.not21 = icmp eq i32 %22, 0
  br i1 %.not21, label %23, label %33

23:                                               ; preds = %19
  %24 = load double, ptr %4, align 8, !tbaa !5
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %24)
  call void @free(ptr noundef nonnull %5) #8
  %26 = load ptr, ptr %2, align 8, !tbaa !9
  %27 = call i32 @cudaFree(ptr noundef %26) #8
  %28 = call i32 @check_cuda_call(i32 noundef %27, ptr noundef nonnull @.str, i32 noundef 66)
  %.not22 = icmp eq i32 %28, 0
  br i1 %.not22, label %29, label %33

29:                                               ; preds = %23
  %30 = load ptr, ptr %3, align 8, !tbaa !9
  %31 = call i32 @cudaFree(ptr noundef %30) #8
  %32 = call i32 @check_cuda_call(i32 noundef %31, ptr noundef nonnull @.str, i32 noundef 67)
  %.not23 = icmp ne i32 %32, 0
  %. = zext i1 %.not23 to i32
  br label %33

33:                                               ; preds = %29, %23, %19
  %.018 = phi i32 [ 1, %19 ], [ 1, %23 ], [ %., %29 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #8
  br label %34

34:                                               ; preds = %15, %12, %1, %33
  %.1 = phi i32 [ %.018, %33 ], [ 1, %1 ], [ 1, %12 ], [ 1, %15 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #8
  ret i32 %.1
}

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_cuda_call(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @cudaMalloc(ptr noundef, i64 noundef) local_unnamed_addr #4

declare i32 @cudaMemcpy(ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_cublas_call(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @cublasDnrm2_v2(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #4

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #6

declare i32 @cudaFree(ptr noundef) local_unnamed_addr #4

attributes #0 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { inlinehint 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 = { "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 = { 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 #6 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #7 = { nounwind allocsize(0) }
attributes #8 = { 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 = !{!"double", !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}


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