; LLVM IR from ytopt-team/ytopt :: ytopt-libe/xsbench/ytopt/xsbench (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"

%struct.Inputs = type { i32, i64, i64, i32, ptr, i32, i32, i32, i32, i32, i32 }
%struct.SimulationData = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, ptr, i32, ptr, i32 }

@.str.84 = external hidden unnamed_addr constant [37 x i8], align 1

; 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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @run_event_based_simulation(ptr noundef byval(%struct.Inputs) align 8 %0, ptr noundef byval(%struct.SimulationData) align 8 %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca [5 x double], align 16
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %2, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %3
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.84)
  br label %19

19:                                               ; preds = %17, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %86, %19
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 3
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = icmp slt i32 %21, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %89

26:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 1070, ptr %8, align 8, !tbaa !15
  %27 = load i64, ptr %8, align 8, !tbaa !15
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = mul nsw i32 2, %28
  %30 = sext i32 %29 to i64
  %31 = call i64 @fast_forward_LCG(i64 noundef %27, i64 noundef %30)
  store i64 %31, ptr %8, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %32 = call double @LCG_random_double(ptr noundef %8)
  store double %32, ptr %9, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %33 = call i32 @pick_mat(ptr noundef %8)
  store i32 %33, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %11) #4
  call void @llvm.memset.p0.i64(ptr align 16 %11, i8 0, i64 40, i1 false)
  %34 = load double, ptr %9, align 8, !tbaa !16
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !18
  %38 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 2
  %39 = load i64, ptr %38, align 8, !tbaa !19
  %40 = getelementptr inbounds %struct.SimulationData, ptr %1, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !20
  %42 = getelementptr inbounds %struct.SimulationData, ptr %1, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !22
  %44 = getelementptr inbounds %struct.SimulationData, ptr %1, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !23
  %46 = getelementptr inbounds %struct.SimulationData, ptr %1, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !24
  %48 = getelementptr inbounds %struct.SimulationData, ptr %1, i32 0, i32 5
  %49 = load ptr, ptr %48, align 8, !tbaa !25
  %50 = getelementptr inbounds %struct.SimulationData, ptr %1, i32 0, i32 2
  %51 = load ptr, ptr %50, align 8, !tbaa !26
  %52 = getelementptr inbounds [5 x double], ptr %11, i64 0, i64 0
  %53 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 5
  %54 = load i32, ptr %53, align 8, !tbaa !27
  %55 = getelementptr inbounds %struct.Inputs, ptr %0, i32 0, i32 6
  %56 = load i32, ptr %55, align 4, !tbaa !28
  %57 = getelementptr inbounds %struct.SimulationData, ptr %1, i32 0, i32 12
  %58 = load i32, ptr %57, align 8, !tbaa !29
  call void @calculate_macro_xs(double noundef %34, i32 noundef %35, i64 noundef %37, i64 noundef %39, ptr noundef %41, ptr noundef %43, ptr noundef %45, ptr noundef %47, ptr noundef %49, ptr noundef %51, ptr noundef %52, i32 noundef %54, i32 noundef %56, i32 noundef %58)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store double -1.000000e+00, ptr %12, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %77, %26
  %60 = load i32, ptr %14, align 4, !tbaa !5
  %61 = icmp slt i32 %60, 5
  br i1 %61, label %63, label %62

62:                                               ; preds = %59
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %80

63:                                               ; preds = %59
  %64 = load i32, ptr %14, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [5 x double], ptr %11, i64 0, i64 %65
  %67 = load double, ptr %66, align 8, !tbaa !16
  %68 = load double, ptr %12, align 8, !tbaa !16
  %69 = fcmp ogt double %67, %68
  br i1 %69, label %70, label %76

70:                                               ; preds = %63
  %71 = load i32, ptr %14, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [5 x double], ptr %11, i64 0, i64 %72
  %74 = load double, ptr %73, align 8, !tbaa !16
  store double %74, ptr %12, align 8, !tbaa !16
  %75 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %75, ptr %13, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %70, %63
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %14, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %14, align 4, !tbaa !5
  br label %59, !llvm.loop !30

80:                                               ; preds = %62
  %81 = load i32, ptr %13, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  %84 = load i64, ptr %5, align 8, !tbaa !9
  %85 = add i64 %84, %83
  store i64 %85, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %86

86:                                               ; preds = %80
  %87 = load i32, ptr %6, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %6, align 4, !tbaa !5
  br label %20, !llvm.loop !32

89:                                               ; preds = %25
  %90 = load i64, ptr %5, align 8, !tbaa !9
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i64 %90
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @fast_forward_LCG(i64 noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local double @LCG_random_double(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @pick_mat(ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare dso_local void @calculate_macro_xs(double noundef, i32 noundef, i64 noundef, i64 noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, i32 noundef, i32 noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"", !6, i64 0, !13, i64 8, !13, i64 16, !6, i64 24, !14, i64 32, !6, i64 40, !6, i64 44, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60}
!13 = !{!"long", !7, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = !{!12, !13, i64 8}
!19 = !{!12, !13, i64 16}
!20 = !{!21, !14, i64 0}
!21 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68, !6, i64 72, !14, i64 80, !6, i64 88, !14, i64 96, !6, i64 104}
!22 = !{!21, !14, i64 8}
!23 = !{!21, !14, i64 24}
!24 = !{!21, !14, i64 32}
!25 = !{!21, !14, i64 40}
!26 = !{!21, !14, i64 16}
!27 = !{!12, !6, i64 40}
!28 = !{!12, !6, i64 44}
!29 = !{!21, !6, i64 72}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}
!32 = distinct !{!32, !31}


; 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.Inputs = type { i32, i64, i64, i32, ptr, i32, i32, i32, i32, i32, i32 }
%struct.SimulationData = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, ptr, i32, ptr, i32 }

@.str.84 = external hidden unnamed_addr constant [37 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @run_event_based_simulation(ptr nocapture noundef readonly byval(%struct.Inputs) align 8 %0, ptr nocapture noundef readonly byval(%struct.SimulationData) align 8 %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = alloca i64, align 8
  %5 = alloca [5 x double], align 16
  %6 = icmp eq i32 %2, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %3
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.84)
  br label %9

9:                                                ; preds = %7, %3
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load i32, ptr %10, align 8, !tbaa !5
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i64, ptr %13, align 8
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load i64, ptr %15, align 8
  %17 = load ptr, ptr %1, align 8
  %18 = getelementptr inbounds i8, ptr %1, i64 8
  %19 = load ptr, ptr %18, align 8
  %20 = getelementptr inbounds i8, ptr %1, i64 24
  %21 = load ptr, ptr %20, align 8
  %22 = getelementptr inbounds i8, ptr %1, i64 32
  %23 = load ptr, ptr %22, align 8
  %24 = getelementptr inbounds i8, ptr %1, i64 40
  %25 = load ptr, ptr %24, align 8
  %26 = getelementptr inbounds i8, ptr %1, i64 16
  %27 = load ptr, ptr %26, align 8
  %28 = getelementptr inbounds i8, ptr %0, i64 40
  %29 = load i32, ptr %28, align 8
  %30 = getelementptr inbounds i8, ptr %0, i64 44
  %31 = load i32, ptr %30, align 4
  %32 = getelementptr inbounds i8, ptr %1, i64 72
  %33 = load i32, ptr %32, align 8
  %wide.trip.count = zext nneg i32 %11 to i64
  %34 = getelementptr inbounds i8, ptr %5, i64 8
  %35 = getelementptr inbounds i8, ptr %5, i64 16
  %36 = getelementptr inbounds i8, ptr %5, i64 24
  %37 = getelementptr inbounds i8, ptr %5, i64 32
  br label %38

._crit_edge:                                      ; preds = %38, %9
  %.017.lcssa = phi i64 [ 0, %9 ], [ %57, %38 ]
  ret i64 %.017.lcssa

38:                                               ; preds = %.lr.ph, %38
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %38 ]
  %.01724 = phi i64 [ 0, %.lr.ph ], [ %57, %38 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store i64 1070, ptr %4, align 8, !tbaa !12
  %39 = shl nuw nsw i64 %indvars.iv, 1
  %40 = call i64 @fast_forward_LCG(i64 noundef 1070, i64 noundef %39)
  store i64 %40, ptr %4, align 8, !tbaa !12
  %41 = call double @LCG_random_double(ptr noundef nonnull %4)
  %42 = call i32 @pick_mat(ptr noundef nonnull %4)
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %5) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %5, i8 0, i64 40, i1 false)
  call void @calculate_macro_xs(double noundef %41, i32 noundef %42, i64 noundef %14, i64 noundef %16, ptr noundef %17, ptr noundef %19, ptr noundef %21, ptr noundef %23, ptr noundef %25, ptr noundef %27, ptr noundef nonnull %5, i32 noundef %29, i32 noundef %31, i32 noundef %33)
  %43 = load double, ptr %5, align 16, !tbaa !13
  %44 = fcmp ogt double %43, -1.000000e+00
  %.116 = select i1 %44, double %43, double -1.000000e+00
  %45 = load double, ptr %34, align 8, !tbaa !13
  %46 = fcmp ogt double %45, %.116
  %.116.1 = select i1 %46, double %45, double %.116
  %47 = load double, ptr %35, align 16, !tbaa !13
  %48 = fcmp ogt double %47, %.116.1
  %.116.2 = select i1 %48, double %47, double %.116.1
  %49 = load double, ptr %36, align 8, !tbaa !13
  %50 = fcmp ogt double %49, %.116.2
  %.116.3 = select i1 %50, double %49, double %.116.2
  %51 = select i1 %46, i64 2, i64 1
  %52 = load double, ptr %37, align 16, !tbaa !13
  %53 = fcmp ogt double %52, %.116.3
  %54 = select i1 %48, i64 3, i64 %51
  %55 = select i1 %50, i64 4, i64 %54
  %56 = select i1 %53, i64 5, i64 %55
  %57 = add i64 %.01724, %56
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %38, !llvm.loop !15
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @fast_forward_LCG(i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local double @LCG_random_double(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @pick_mat(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare dso_local void @calculate_macro_xs(double noundef, i32 noundef, i64 noundef, i64 noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 24}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !11, i64 32, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass