; LLVM IR from EntityFX/anybench :: src/benchmarks/generic/scimark2 (Random)

; 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.Random_struct = type { [17 x i32], i32, i32, i32, i32, double, double, double }

@dm1 = external hidden global double, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local double @Random_nextDouble(ptr noundef %0) #1 {
  %2 = alloca double, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.Random_struct, ptr %9, i32 0, i32 2
  %11 = load i32, ptr %10, align 8, !tbaa !9
  store i32 %11, ptr %5, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Random_struct, ptr %12, i32 0, i32 3
  %14 = load i32, ptr %13, align 4, !tbaa !14
  store i32 %14, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Random_struct, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds [17 x i32], ptr %16, i64 0, i64 0
  store ptr %17, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !13
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i32, ptr %18, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !13
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr %23, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = sub nsw i32 %22, %27
  store i32 %28, ptr %4, align 4, !tbaa !13
  %29 = load i32, ptr %4, align 4, !tbaa !13
  %30 = icmp slt i32 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %1
  %32 = load i32, ptr %4, align 4, !tbaa !13
  %33 = add nsw i32 %32, 2147483647
  store i32 %33, ptr %4, align 4, !tbaa !13
  br label %34

34:                                               ; preds = %31, %1
  %35 = load i32, ptr %4, align 4, !tbaa !13
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Random_struct, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %6, align 4, !tbaa !13
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [17 x i32], ptr %37, i64 0, i64 %39
  store i32 %35, ptr %40, align 4, !tbaa !13
  %41 = load i32, ptr %5, align 4, !tbaa !13
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %34
  store i32 16, ptr %5, align 4, !tbaa !13
  br label %47

44:                                               ; preds = %34
  %45 = load i32, ptr %5, align 4, !tbaa !13
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr %5, align 4, !tbaa !13
  br label %47

47:                                               ; preds = %44, %43
  %48 = load i32, ptr %5, align 4, !tbaa !13
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Random_struct, ptr %49, i32 0, i32 2
  store i32 %48, ptr %50, align 8, !tbaa !9
  %51 = load i32, ptr %6, align 4, !tbaa !13
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %47
  store i32 16, ptr %6, align 4, !tbaa !13
  br label %57

54:                                               ; preds = %47
  %55 = load i32, ptr %6, align 4, !tbaa !13
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr %6, align 4, !tbaa !13
  br label %57

57:                                               ; preds = %54, %53
  %58 = load i32, ptr %6, align 4, !tbaa !13
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Random_struct, ptr %59, i32 0, i32 3
  store i32 %58, ptr %60, align 4, !tbaa !14
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Random_struct, ptr %61, i32 0, i32 4
  %63 = load i32, ptr %62, align 8, !tbaa !15
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %77

65:                                               ; preds = %57
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.Random_struct, ptr %66, i32 0, i32 5
  %68 = load double, ptr %67, align 8, !tbaa !16
  %69 = load double, ptr @dm1, align 8, !tbaa !17
  %70 = load i32, ptr %4, align 4, !tbaa !13
  %71 = sitofp i32 %70 to double
  %72 = fmul double %69, %71
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.Random_struct, ptr %73, i32 0, i32 7
  %75 = load double, ptr %74, align 8, !tbaa !18
  %76 = call double @llvm.fmuladd.f64(double %72, double %75, double %68)
  store double %76, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %82

77:                                               ; preds = %57
  %78 = load double, ptr @dm1, align 8, !tbaa !17
  %79 = load i32, ptr %4, align 4, !tbaa !13
  %80 = sitofp i32 %79 to double
  %81 = fmul double %78, %80
  store double %81, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %82

82:                                               ; preds = %77, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %83 = load double, ptr %2, align 8
  ret double %83
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 72}
!10 = !{!"", !7, i64 0, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !12, i64 88, !12, i64 96, !12, i64 104}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 76}
!15 = !{!10, !11, i64 80}
!16 = !{!10, !12, i64 88}
!17 = !{!12, !12, i64 0}
!18 = !{!10, !12, i64 104}


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

@dm1 = external hidden local_unnamed_addr global double, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local double @Random_nextDouble(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 72
  %3 = load <2 x i32>, ptr %2, align 8, !tbaa !5
  %4 = extractelement <2 x i32> %3, i64 0
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds i32, ptr %0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = extractelement <2 x i32> %3, i64 1
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds i32, ptr %0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sub nsw i32 %7, %11
  %13 = icmp slt i32 %12, 0
  %14 = add nsw i32 %12, 2147483647
  %spec.select = select i1 %13, i32 %14, i32 %12
  store i32 %spec.select, ptr %10, align 4, !tbaa !5
  %15 = icmp eq <2 x i32> %3, zeroinitializer
  %16 = add nsw <2 x i32> %3, <i32 -1, i32 -1>
  %17 = select <2 x i1> %15, <2 x i32> <i32 16, i32 16>, <2 x i32> %16
  store <2 x i32> %17, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 80
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %29, label %20

20:                                               ; preds = %1
  %21 = getelementptr inbounds i8, ptr %0, i64 88
  %22 = load double, ptr %21, align 8, !tbaa !12
  %23 = load double, ptr @dm1, align 8, !tbaa !13
  %24 = sitofp i32 %spec.select to double
  %25 = fmul double %23, %24
  %26 = getelementptr inbounds i8, ptr %0, i64 104
  %27 = load double, ptr %26, align 8, !tbaa !14
  %28 = tail call double @llvm.fmuladd.f64(double %25, double %27, double %22)
  br label %33

29:                                               ; preds = %1
  %30 = load double, ptr @dm1, align 8, !tbaa !13
  %31 = sitofp i32 %spec.select to double
  %32 = fmul double %30, %31
  br label %33

33:                                               ; preds = %29, %20
  %.0 = phi double [ %28, %20 ], [ %32, %29 ]
  ret double %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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 speculatable willreturn memory(none) }

!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, !6, i64 80}
!10 = !{!"", !7, i64 0, !6, i64 68, !6, i64 72, !6, i64 76, !6, i64 80, !11, i64 88, !11, i64 96, !11, i64 104}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !11, i64 88}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 104}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass