; LLVM IR from simbody/simbody :: SimTKmath/Optimizers/src/c-cmaes (cmaes)

; 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.cmaes_random_t = type { i64, i64, i64, ptr, i16, double }

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

; Function Attrs: nounwind uwtable
define dso_local i64 @cmaes_random_init(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %6 = call i64 @clock() #4
  store i64 %6, ptr %5, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.cmaes_random_t, ptr %7, i32 0, i32 4
  store i16 0, ptr %8, align 8, !tbaa !11
  %9 = call ptr @new_void(i32 noundef 32, i64 noundef 8)
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.cmaes_random_t, ptr %10, i32 0, i32 3
  store ptr %9, ptr %11, align 8, !tbaa !15
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = icmp ult i64 %12, 1
  br i1 %13, label %14, label %27

14:                                               ; preds = %2
  br label %15

15:                                               ; preds = %20, %14
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = call i64 @clock() #4
  %18 = sub nsw i64 %16, %17
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  br label %15, !llvm.loop !16

21:                                               ; preds = %15
  %22 = call i64 @time(ptr noundef null) #4
  %23 = mul nsw i64 100, %22
  %24 = call i64 @clock() #4
  %25 = add nsw i64 %23, %24
  %26 = call i64 @llvm.abs.i64(i64 %25, i1 true)
  store i64 %26, ptr %4, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %21, %2
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load i64, ptr %4, align 8, !tbaa !9
  %30 = call i64 @cmaes_random_Start(ptr noundef %28, i64 noundef %29)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i64 %30
}

; Function Attrs: nounwind uwtable
declare hidden ptr @new_void(i32 noundef, i64 noundef) #1

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

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.abs.i64(i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare dso_local i64 @cmaes_random_Start(ptr noundef, i64 noundef) #1

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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 32}
!12 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !14, i64 40}
!13 = !{!"short", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!12, !6, i64 24}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local i64 @cmaes_random_init(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i64 @clock() #3
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  store i16 0, ptr %4, align 8, !tbaa !5
  %5 = tail call ptr @new_void(i32 noundef 32, i64 noundef 8)
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %5, ptr %6, align 8, !tbaa !13
  %7 = icmp eq i64 %1, 0
  br i1 %7, label %.preheader, label %16

.preheader:                                       ; preds = %2, %.preheader
  %8 = tail call i64 @clock() #3
  %9 = icmp eq i64 %3, %8
  br i1 %9, label %.preheader, label %10, !llvm.loop !14

10:                                               ; preds = %.preheader
  %11 = tail call i64 @time(ptr noundef null) #3
  %12 = mul nsw i64 %11, 100
  %13 = tail call i64 @clock() #3
  %14 = add nsw i64 %12, %13
  %15 = tail call i64 @llvm.abs.i64(i64 %14, i1 true)
  br label %16

16:                                               ; preds = %10, %2
  %.0 = phi i64 [ %15, %10 ], [ %1, %2 ]
  %17 = tail call i64 @cmaes_random_Start(ptr noundef %0, i64 noundef %.0)
  ret i64 %17
}

; Function Attrs: nounwind uwtable
declare hidden ptr @new_void(i32 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.abs.i64(i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @cmaes_random_Start(ptr noundef, i64 noundef) local_unnamed_addr #0

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 = { 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 = { mustprogress 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, !11, i64 32}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !11, i64 32, !12, i64 40}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = !{!6, !10, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass