; LLVM IR from microsoft/LightAIMD :: src (velocity_init)

; 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.molecule = type { i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr }
%struct.vec3d = type { double, double, double }

; Function Attrs: nounwind uwtable
define dso_local void @maxwell_boltzmann_velocity_init(ptr noundef %0, double noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = load double, ptr %4, align 8, !tbaa !9
  %11 = fmul double 0x3B30B0E6D55E647C, %10
  %12 = fmul double %11, 0x4389771F54E89CA3
  store double %12, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.molecule, ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = mul i64 %15, 3
  %17 = mul i64 %16, 8
  %18 = call ptr @x_malloc(i64 noundef %17)
  store ptr %18, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.molecule, ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = mul i64 %22, 3
  call void @rand_standard_normal(ptr noundef %19, i64 noundef %23)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %24, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !14
  br label %25

25:                                               ; preds = %77, %2
  %26 = load i64, ptr %8, align 8, !tbaa !14
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.molecule, ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = icmp ult i64 %26, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %80

32:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %33 = load double, ptr %5, align 8, !tbaa !9
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.molecule, ptr %34, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = load i64, ptr %8, align 8, !tbaa !14
  %38 = getelementptr inbounds double, ptr %36, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = fdiv double %33, %39
  %41 = call double @sqrt(double noundef %40) #4
  store double %41, ptr %9, align 8, !tbaa !9
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds double, ptr %42, i64 0
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = load double, ptr %9, align 8, !tbaa !9
  %46 = fmul double %44, %45
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.molecule, ptr %47, i32 0, i32 5
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = load i64, ptr %8, align 8, !tbaa !14
  %51 = getelementptr inbounds %struct.vec3d, ptr %49, i64 %50
  %52 = getelementptr inbounds %struct.vec3d, ptr %51, i32 0, i32 0
  store double %46, ptr %52, align 8, !tbaa !17
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds double, ptr %53, i64 1
  %55 = load double, ptr %54, align 8, !tbaa !9
  %56 = load double, ptr %9, align 8, !tbaa !9
  %57 = fmul double %55, %56
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.molecule, ptr %58, i32 0, i32 5
  %60 = load ptr, ptr %59, align 8, !tbaa !16
  %61 = load i64, ptr %8, align 8, !tbaa !14
  %62 = getelementptr inbounds %struct.vec3d, ptr %60, i64 %61
  %63 = getelementptr inbounds %struct.vec3d, ptr %62, i32 0, i32 1
  store double %57, ptr %63, align 8, !tbaa !19
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds double, ptr %64, i64 2
  %66 = load double, ptr %65, align 8, !tbaa !9
  %67 = load double, ptr %9, align 8, !tbaa !9
  %68 = fmul double %66, %67
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.molecule, ptr %69, i32 0, i32 5
  %71 = load ptr, ptr %70, align 8, !tbaa !16
  %72 = load i64, ptr %8, align 8, !tbaa !14
  %73 = getelementptr inbounds %struct.vec3d, ptr %71, i64 %72
  %74 = getelementptr inbounds %struct.vec3d, ptr %73, i32 0, i32 2
  store double %68, ptr %74, align 8, !tbaa !20
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds double, ptr %75, i64 3
  store ptr %76, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %77

77:                                               ; preds = %32
  %78 = load i64, ptr %8, align 8, !tbaa !14
  %79 = add i64 %78, 1
  store i64 %79, ptr %8, align 8, !tbaa !14
  br label %25, !llvm.loop !21

80:                                               ; preds = %31
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  call void @x_free(ptr noundef %81)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

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

declare ptr @x_malloc(i64 noundef) #2

declare void @rand_standard_normal(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

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

declare void @x_free(ptr noundef) #2

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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"molecule", !13, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !13, i64 64, !6, i64 72}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 24}
!16 = !{!12, !6, i64 40}
!17 = !{!18, !10, i64 0}
!18 = !{!"vec3d", !10, i64 0, !10, i64 8, !10, i64 16}
!19 = !{!18, !10, i64 8}
!20 = !{!18, !10, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%struct.vec3d = type { double, double, double }

; Function Attrs: nounwind uwtable
define dso_local void @maxwell_boltzmann_velocity_init(ptr nocapture noundef readonly %0, double noundef %1) local_unnamed_addr #0 {
  %3 = fmul double %1, 0x3B30B0E6D55E647C
  %4 = fmul double %3, 0x4389771F54E89CA3
  %5 = load i64, ptr %0, align 8, !tbaa !5
  %6 = mul i64 %5, 24
  %7 = tail call ptr @x_malloc(i64 noundef %6) #3
  %8 = load i64, ptr %0, align 8, !tbaa !5
  %9 = mul i64 %8, 3
  tail call void @rand_standard_normal(ptr noundef %7, i64 noundef %9) #3
  %10 = load i64, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  br label %13

._crit_edge:                                      ; preds = %13, %2
  tail call void @x_free(ptr noundef %7) #3
  ret void

13:                                               ; preds = %.lr.ph, %13
  %.026 = phi ptr [ %7, %.lr.ph ], [ %31, %13 ]
  %.02425 = phi i64 [ 0, %.lr.ph ], [ %32, %13 ]
  %14 = load ptr, ptr %11, align 8, !tbaa !11
  %15 = getelementptr inbounds double, ptr %14, i64 %.02425
  %16 = load double, ptr %15, align 8, !tbaa !12
  %17 = fdiv double %4, %16
  %18 = tail call double @sqrt(double noundef %17) #3
  %19 = load double, ptr %.026, align 8, !tbaa !12
  %20 = fmul double %18, %19
  %21 = load ptr, ptr %12, align 8, !tbaa !14
  %22 = getelementptr inbounds %struct.vec3d, ptr %21, i64 %.02425
  store double %20, ptr %22, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %.026, i64 8
  %24 = load double, ptr %23, align 8, !tbaa !12
  %25 = fmul double %18, %24
  %26 = getelementptr inbounds %struct.vec3d, ptr %21, i64 %.02425, i32 1
  store double %25, ptr %26, align 8, !tbaa !17
  %27 = getelementptr inbounds i8, ptr %.026, i64 16
  %28 = load double, ptr %27, align 8, !tbaa !12
  %29 = fmul double %18, %28
  %30 = getelementptr inbounds %struct.vec3d, ptr %21, i64 %.02425, i32 2
  store double %29, ptr %30, align 8, !tbaa !18
  %31 = getelementptr inbounds i8, ptr %.026, i64 24
  %32 = add nuw i64 %.02425, 1
  %33 = load i64, ptr %0, align 8, !tbaa !5
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %13, label %._crit_edge, !llvm.loop !19
}

declare ptr @x_malloc(i64 noundef) local_unnamed_addr #1

declare void @rand_standard_normal(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

declare void @x_free(ptr noundef) local_unnamed_addr #1

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 = { "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 = { mustprogress nofree nounwind willreturn memory(write) "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 = !{!6, !7, i64 0}
!6 = !{!"molecule", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !7, i64 64, !10, i64 72}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !8, i64 0}
!14 = !{!6, !10, i64 40}
!15 = !{!16, !13, i64 0}
!16 = !{!"vec3d", !13, i64 0, !13, i64 8, !13, i64 16}
!17 = !{!16, !13, i64 8}
!18 = !{!16, !13, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass