; LLVM IR from AlgoGenesis/C :: Miscellaneous Algorithms/multilevel_queue_scheduling (program)

; 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.Process = type { i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local void @calculateTimes(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [10 x i32], align 16
  %6 = alloca [10 x i32], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 40, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %77, %2
  %13 = load i32, ptr %10, align 4, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %80

17:                                               ; preds = %12
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10 x i32], ptr %5, i64 0, i64 %20
  store i32 %18, ptr %21, align 4, !tbaa !9
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds %struct.Process, ptr %22, i64 %24
  %26 = getelementptr inbounds %struct.Process, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = add nsw i32 %28, %27
  store i32 %29, ptr %9, align 4, !tbaa !9
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [10 x i32], ptr %5, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.Process, ptr %34, i64 %36
  %38 = getelementptr inbounds %struct.Process, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = add nsw i32 %33, %39
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i64 %42
  store i32 %40, ptr %43, align 4, !tbaa !9
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [10 x i32], ptr %5, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = add nsw i32 %48, %47
  store i32 %49, ptr %7, align 4, !tbaa !9
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = add nsw i32 %54, %53
  store i32 %55, ptr %8, align 4, !tbaa !9
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds %struct.Process, ptr %56, i64 %58
  %60 = getelementptr inbounds %struct.Process, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 4, !tbaa !13
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds %struct.Process, ptr %62, i64 %64
  %66 = getelementptr inbounds %struct.Process, ptr %65, i32 0, i32 2
  %67 = load i32, ptr %66, align 4, !tbaa !14
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [10 x i32], ptr %5, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !9
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %61, i32 noundef %67, i32 noundef %71, i32 noundef %75)
  br label %77

77:                                               ; preds = %17
  %78 = load i32, ptr %10, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %10, align 4, !tbaa !9
  br label %12, !llvm.loop !15

80:                                               ; preds = %16
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = sitofp i32 %81 to float
  %83 = load i32, ptr %4, align 4, !tbaa !9
  %84 = sitofp i32 %83 to float
  %85 = fdiv float %82, %84
  %86 = fpext float %85 to double
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %86)
  %88 = load i32, ptr %8, align 4, !tbaa !9
  %89 = sitofp i32 %88 to float
  %90 = load i32, ptr %4, align 4, !tbaa !9
  %91 = sitofp i32 %90 to float
  %92 = fdiv float %89, %91
  %93 = fpext float %92 to double
  %94 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, double noundef %93)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr %5) #3
  ret void
}

declare i32 @printf(ptr noundef, ...) #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 = { "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, !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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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.Process = type { i32, i32, i32 }

@.str = external hidden unnamed_addr constant [27 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @calculateTimes(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %4 = icmp sgt i32 %1, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %5 = sitofp i32 %18 to float
  %6 = sitofp i32 %19 to float
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.027.lcssa = phi float [ 0.000000e+00, %2 ], [ %5, %._crit_edge.loopexit ]
  %.026.lcssa = phi float [ 0.000000e+00, %2 ], [ %6, %._crit_edge.loopexit ]
  %7 = sitofp i32 %1 to float
  %8 = fdiv float %.027.lcssa, %7
  %9 = fpext float %8 to double
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %9)
  %11 = fdiv float %.026.lcssa, %7
  %12 = fpext float %11 to double
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, double noundef %12)
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.02531 = phi i32 [ 0, %.lr.ph.preheader ], [ %17, %.lr.ph ]
  %.02630 = phi i32 [ 0, %.lr.ph.preheader ], [ %19, %.lr.ph ]
  %.02729 = phi i32 [ 0, %.lr.ph.preheader ], [ %18, %.lr.ph ]
  %14 = getelementptr inbounds %struct.Process, ptr %0, i64 %indvars.iv
  %15 = getelementptr inbounds i8, ptr %14, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add nsw i32 %16, %.02531
  %18 = add nsw i32 %.02531, %.02729
  %19 = add nsw i32 %17, %.02630
  %20 = load i32, ptr %14, align 4, !tbaa !10
  %21 = getelementptr inbounds i8, ptr %14, i64 8
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %20, i32 noundef %22, i32 noundef %.02531, i32 noundef %17)
  %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.loopexit, label %.lr.ph, !llvm.loop !12
}

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

attributes #0 = { nofree 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 = { 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" }

!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 4}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!6, !7, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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