; LLVM IR from nobuyuki83/delfem2 :: examples_cuda/003_VecDot (main)

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [1025 x float], align 16
  %4 = alloca [1025 x float], align 16
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca float, align 4
  %8 = alloca i64, align 8
  %9 = alloca float, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1025, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4100, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4100, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %32, %0
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = icmp ult i32 %12, 1025
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %35

15:                                               ; preds = %11
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sitofp i32 %16 to float
  %18 = fpext float %17 to double
  %19 = fdiv double %18, 1.000000e+02
  %20 = fptrunc double %19 to float
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1025 x float], ptr %3, i64 0, i64 %22
  store float %20, ptr %23, align 4, !tbaa !9
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sitofp i32 %24 to float
  %26 = fpext float %25 to double
  %27 = fdiv double %26, 1.000000e+02
  %28 = fptrunc double %27 to float
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1025 x float], ptr %4, i64 0, i64 %30
  store float %28, ptr %31, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %15
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %5, align 4, !tbaa !5
  br label %11, !llvm.loop !11

35:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %36 = call i64 @clock() #5
  store i64 %36, ptr %6, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %37 = getelementptr inbounds [1025 x float], ptr %3, i64 0, i64 0
  %38 = getelementptr inbounds [1025 x float], ptr %4, i64 0, i64 0
  %39 = call noundef float @_ZN7delfem24cuda8cuda_DotEPKfS2_j(ptr noundef %37, ptr noundef %38, i32 noundef 1025)
  store float %39, ptr %7, align 4, !tbaa !9
  %40 = load float, ptr %7, align 4, !tbaa !9
  %41 = fpext float %40 to double
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %41)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %43 = call i64 @clock() #5
  store i64 %43, ptr %8, align 8, !tbaa !13
  %44 = load i64, ptr %8, align 8, !tbaa !13
  %45 = load i64, ptr %6, align 8, !tbaa !13
  %46 = sub nsw i64 %44, %45
  %47 = sitofp i64 %46 to double
  %48 = fdiv double %47, 1.000000e+06
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %48)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store float 0.000000e+00, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %65, %35
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = icmp ult i32 %51, 1025
  br i1 %52, label %54, label %53

53:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %68

54:                                               ; preds = %50
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1025 x float], ptr %3, i64 0, i64 %56
  %58 = load float, ptr %57, align 4, !tbaa !9
  %59 = load i32, ptr %10, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1025 x float], ptr %4, i64 0, i64 %60
  %62 = load float, ptr %61, align 4, !tbaa !9
  %63 = load float, ptr %9, align 4, !tbaa !9
  %64 = call float @llvm.fmuladd.f32(float %58, float %62, float %63)
  store float %64, ptr %9, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %54
  %66 = load i32, ptr %10, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %10, align 4, !tbaa !5
  br label %50, !llvm.loop !15

68:                                               ; preds = %53
  %69 = load float, ptr %7, align 4, !tbaa !9
  %70 = fpext float %69 to double
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %70)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4100, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4100, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %72 = load i32, ptr %1, align 4
  ret i32 %72
}

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

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

; Function Attrs: nounwind
declare i64 @clock() #2

declare noundef float @_ZN7delfem24cuda8cuda_DotEPKfS2_j(ptr noundef, ptr noundef, i32 noundef) #3

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #4

attributes #0 = { mustprogress norecurse 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 "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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !12}


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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
vector.ph:
  %0 = alloca [1025 x float], align 16
  %1 = alloca [1025 x float], align 16
  call void @llvm.lifetime.start.p0(i64 4100, ptr nonnull %0) #5
  call void @llvm.lifetime.start.p0(i64 4100, ptr nonnull %1) #5
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.1, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ], [ %vec.ind.next.1, %vector.body ]
  %2 = uitofp <4 x i32> %vec.ind to <4 x double>
  %3 = fdiv <4 x double> %2, <double 1.000000e+02, double 1.000000e+02, double 1.000000e+02, double 1.000000e+02>
  %4 = fptrunc <4 x double> %3 to <4 x float>
  %5 = getelementptr inbounds [1025 x float], ptr %0, i64 0, i64 %index
  store <4 x float> %4, ptr %5, align 16, !tbaa !5
  %6 = getelementptr inbounds [1025 x float], ptr %1, i64 0, i64 %index
  store <4 x float> %4, ptr %6, align 16, !tbaa !5
  %index.next = or disjoint i64 %index, 4
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %7 = uitofp <4 x i32> %vec.ind.next to <4 x double>
  %8 = fdiv <4 x double> %7, <double 1.000000e+02, double 1.000000e+02, double 1.000000e+02, double 1.000000e+02>
  %9 = fptrunc <4 x double> %8 to <4 x float>
  %10 = getelementptr inbounds [1025 x float], ptr %0, i64 0, i64 %index.next
  store <4 x float> %9, ptr %10, align 16, !tbaa !5
  %11 = getelementptr inbounds [1025 x float], ptr %1, i64 0, i64 %index.next
  store <4 x float> %9, ptr %11, align 16, !tbaa !5
  %index.next.1 = add nuw nsw i64 %index, 8
  %vec.ind.next.1 = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %12 = icmp eq i64 %index.next.1, 1024
  br i1 %12, label %scalar.ph, label %vector.body, !llvm.loop !9

scalar.ph:                                        ; preds = %vector.body
  %13 = getelementptr inbounds i8, ptr %0, i64 4096
  store float 0x40247AE140000000, ptr %13, align 16, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %1, i64 4096
  store float 0x40247AE140000000, ptr %14, align 16, !tbaa !5
  %15 = tail call i64 @clock() #5
  %16 = call noundef float @_ZN7delfem24cuda8cuda_DotEPKfS2_j(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef 1025)
  %17 = fpext float %16 to double
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %17)
  %19 = call i64 @clock() #5
  %20 = sub nsw i64 %19, %15
  %21 = sitofp i64 %20 to double
  %22 = fdiv double %21, 1.000000e+06
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %22)
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %17)
  call void @llvm.lifetime.end.p0(i64 4100, ptr nonnull %1) #5
  call void @llvm.lifetime.end.p0(i64 4100, ptr nonnull %0) #5
  ret i32 0
}

; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #2

declare noundef float @_ZN7delfem24cuda8cuda_DotEPKfS2_j(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress norecurse 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 = { 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 = { "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 = { 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 #5 = { 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass