; LLVM IR from AlgoGenesis/C :: Miscellaneous Algorithms/proportional 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 [35 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @fairShareScheduling(ptr noundef %0, i32 noundef %1) #0 {
  %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 i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = 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 4, ptr %5) #4
  store i32 2, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = zext i32 %14 to i64
  %16 = call ptr @llvm.stacksave.p0()
  store ptr %16, ptr %7, align 8
  %17 = alloca i32, i64 %15, align 16
  store i64 %15, ptr %8, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %33, %2
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %36

23:                                               ; preds = %18
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %struct.Process, ptr %24, i64 %26
  %28 = getelementptr inbounds %struct.Process, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr %17, i64 %31
  store i32 %29, ptr %32, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %23
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %9, align 4, !tbaa !9
  br label %18, !llvm.loop !13

36:                                               ; preds = %22
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %38

38:                                               ; preds = %116, %36
  br label %39

39:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 1, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %106, %39
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %109

45:                                               ; preds = %40
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr %17, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = icmp sgt i32 %49, 0
  br i1 %50, label %51, label %105

51:                                               ; preds = %45
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %17, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = icmp sgt i32 %55, %56
  br i1 %57, label %58, label %60

58:                                               ; preds = %51
  %59 = load i32, ptr %5, align 4, !tbaa !9
  br label %65

60:                                               ; preds = %51
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i32, ptr %17, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %60, %58
  %66 = phi i32 [ %59, %58 ], [ %64, %60 ]
  store i32 %66, ptr %12, align 4, !tbaa !9
  %67 = load i32, ptr %12, align 4, !tbaa !9
  %68 = load i32, ptr %11, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i32, ptr %17, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = sub nsw i32 %71, %67
  store i32 %72, ptr %70, align 4, !tbaa !9
  %73 = load i32, ptr %12, align 4, !tbaa !9
  %74 = load i32, ptr %6, align 4, !tbaa !9
  %75 = add nsw i32 %74, %73
  store i32 %75, ptr %6, align 4, !tbaa !9
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds %struct.Process, ptr %76, i64 %78
  %80 = getelementptr inbounds %struct.Process, ptr %79, i32 0, i32 0
  %81 = load i32, ptr %80, align 4, !tbaa !15
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = load i32, ptr %11, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds %struct.Process, ptr %82, i64 %84
  %86 = getelementptr inbounds %struct.Process, ptr %85, i32 0, i32 2
  %87 = load i32, ptr %86, align 4, !tbaa !16
  %88 = load i32, ptr %12, align 4, !tbaa !9
  %89 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %81, i32 noundef %87, i32 noundef %88)
  %90 = load i32, ptr %11, align 4, !tbaa !9
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds i32, ptr %17, i64 %91
  %93 = load i32, ptr %92, align 4, !tbaa !9
  %94 = icmp eq i32 %93, 0
  br i1 %94, label %95, label %104

95:                                               ; preds = %65
  %96 = load ptr, ptr %3, align 8, !tbaa !5
  %97 = load i32, ptr %11, align 4, !tbaa !9
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds %struct.Process, ptr %96, i64 %98
  %100 = getelementptr inbounds %struct.Process, ptr %99, i32 0, i32 0
  %101 = load i32, ptr %100, align 4, !tbaa !15
  %102 = load i32, ptr %6, align 4, !tbaa !9
  %103 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %101, i32 noundef %102)
  br label %104

104:                                              ; preds = %95, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %105

105:                                              ; preds = %104, %45
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %11, align 4, !tbaa !9
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %11, align 4, !tbaa !9
  br label %40, !llvm.loop !17

109:                                              ; preds = %44
  %110 = load i32, ptr %10, align 4, !tbaa !9
  %111 = icmp ne i32 %110, 0
  br i1 %111, label %112, label %113

112:                                              ; preds = %109
  store i32 6, ptr %13, align 4
  br label %114

113:                                              ; preds = %109
  store i32 0, ptr %13, align 4
  br label %114

114:                                              ; preds = %113, %112
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %115 = load i32, ptr %13, align 4
  switch i32 %115, label %119 [
    i32 0, label %116
    i32 6, label %117
  ]

116:                                              ; preds = %114
  br label %38

117:                                              ; preds = %114
  %118 = load ptr, ptr %7, align 8
  call void @llvm.stackrestore.p0(ptr %118)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void

119:                                              ; preds = %114
  unreachable
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { "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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"Process", !10, i64 0, !10, i64 4, !10, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !10, i64 0}
!16 = !{!12, !10, i64 8}
!17 = distinct !{!17, !14}


; 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 [35 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @fairShareScheduling(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = zext i32 %1 to i64
  %4 = alloca i32, i64 %3, align 16
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge.thread

.lr.ph.preheader:                                 ; preds = %2
  %min.iters.check = icmp ult i32 %1, 9
  br i1 %min.iters.check, label %.lr.ph.preheader54, label %vector.ph

.lr.ph.preheader54:                               ; preds = %vector.body, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %vector.body ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.mod.vf = and i64 %3, 7
  %6 = icmp eq i64 %n.mod.vf, 0
  %7 = select i1 %6, i64 8, i64 %n.mod.vf
  %n.vec = sub nsw i64 %3, %7
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %8 = or disjoint i64 %index, 1
  %9 = or disjoint i64 %index, 2
  %10 = or disjoint i64 %index, 3
  %11 = or disjoint i64 %index, 4
  %12 = or disjoint i64 %index, 5
  %13 = or disjoint i64 %index, 6
  %14 = or disjoint i64 %index, 7
  %15 = getelementptr inbounds %struct.Process, ptr %0, i64 %index, i32 1
  %16 = getelementptr inbounds %struct.Process, ptr %0, i64 %8, i32 1
  %17 = getelementptr inbounds %struct.Process, ptr %0, i64 %9, i32 1
  %18 = getelementptr inbounds %struct.Process, ptr %0, i64 %10, i32 1
  %19 = getelementptr inbounds %struct.Process, ptr %0, i64 %11, i32 1
  %20 = getelementptr inbounds %struct.Process, ptr %0, i64 %12, i32 1
  %21 = getelementptr inbounds %struct.Process, ptr %0, i64 %13, i32 1
  %22 = getelementptr inbounds %struct.Process, ptr %0, i64 %14, i32 1
  %23 = load i32, ptr %15, align 4, !tbaa !5
  %24 = load i32, ptr %16, align 4, !tbaa !5
  %25 = load i32, ptr %17, align 4, !tbaa !5
  %26 = load i32, ptr %18, align 4, !tbaa !5
  %27 = insertelement <4 x i32> poison, i32 %23, i64 0
  %28 = insertelement <4 x i32> %27, i32 %24, i64 1
  %29 = insertelement <4 x i32> %28, i32 %25, i64 2
  %30 = insertelement <4 x i32> %29, i32 %26, i64 3
  %31 = load i32, ptr %19, align 4, !tbaa !5
  %32 = load i32, ptr %20, align 4, !tbaa !5
  %33 = load i32, ptr %21, align 4, !tbaa !5
  %34 = load i32, ptr %22, align 4, !tbaa !5
  %35 = insertelement <4 x i32> poison, i32 %31, i64 0
  %36 = insertelement <4 x i32> %35, i32 %32, i64 1
  %37 = insertelement <4 x i32> %36, i32 %33, i64 2
  %38 = insertelement <4 x i32> %37, i32 %34, i64 3
  %39 = getelementptr inbounds i32, ptr %4, i64 %index
  %40 = getelementptr inbounds i8, ptr %39, i64 16
  store <4 x i32> %30, ptr %39, align 16, !tbaa !10
  store <4 x i32> %38, ptr %40, align 16, !tbaa !10
  %index.next = add nuw i64 %index, 8
  %41 = icmp eq i64 %index.next, %n.vec
  br i1 %41, label %.lr.ph.preheader54, label %vector.body, !llvm.loop !11

._crit_edge.thread:                               ; preds = %2
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %.split47.us

._crit_edge:                                      ; preds = %.lr.ph
  %43 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br i1 %5, label %.lr.ph43.us, label %.split47.us

.lr.ph43.us:                                      ; preds = %._crit_edge, %.lr.ph43.us.backedge
  %indvars.iv49 = phi i64 [ %indvars.iv49.be, %.lr.ph43.us.backedge ], [ 0, %._crit_edge ]
  %.141.us = phi i32 [ %.2.us, %.lr.ph43.us.backedge ], [ 0, %._crit_edge ]
  %.03239.us = phi i32 [ %.03239.us.be, %.lr.ph43.us.backedge ], [ 1, %._crit_edge ]
  %44 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv49
  %45 = load i32, ptr %44, align 4, !tbaa !10
  %46 = icmp sgt i32 %45, 0
  br i1 %46, label %47, label %59

47:                                               ; preds = %.lr.ph43.us
  %.37.us = tail call i32 @llvm.umin.i32(i32 %45, i32 2)
  %48 = sub nsw i32 %45, %.37.us
  store i32 %48, ptr %44, align 4, !tbaa !10
  %49 = add nsw i32 %.37.us, %.141.us
  %50 = getelementptr inbounds %struct.Process, ptr %0, i64 %indvars.iv49
  %51 = load i32, ptr %50, align 4, !tbaa !15
  %52 = getelementptr inbounds i8, ptr %50, i64 8
  %53 = load i32, ptr %52, align 4, !tbaa !16
  %54 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %51, i32 noundef %53, i32 noundef %.37.us)
  %55 = icmp ult i32 %45, 3
  br i1 %55, label %56, label %59

56:                                               ; preds = %47
  %57 = load i32, ptr %50, align 4, !tbaa !15
  %58 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %57, i32 noundef %49)
  br label %59

59:                                               ; preds = %56, %47, %.lr.ph43.us
  %.133.us = phi i32 [ %.03239.us, %.lr.ph43.us ], [ 0, %56 ], [ 0, %47 ]
  %.2.us = phi i32 [ %.141.us, %.lr.ph43.us ], [ %49, %56 ], [ %49, %47 ]
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %exitcond53.not = icmp eq i64 %indvars.iv.next50, %3
  br i1 %exitcond53.not, label %._crit_edge44.us, label %.lr.ph43.us.backedge

.lr.ph43.us.backedge:                             ; preds = %59, %._crit_edge44.us
  %indvars.iv49.be = phi i64 [ %indvars.iv.next50, %59 ], [ 0, %._crit_edge44.us ]
  %.03239.us.be = phi i32 [ %.133.us, %59 ], [ 1, %._crit_edge44.us ]
  br label %.lr.ph43.us, !llvm.loop !17

._crit_edge44.us:                                 ; preds = %59
  %.not.us = icmp eq i32 %.133.us, 0
  br i1 %.not.us, label %.lr.ph43.us.backedge, label %.split47.us

.lr.ph:                                           ; preds = %.lr.ph.preheader54, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader54 ]
  %60 = getelementptr inbounds %struct.Process, ptr %0, i64 %indvars.iv, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv
  store i32 %61, ptr %62, align 4, !tbaa !10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %3
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

.split47.us:                                      ; preds = %._crit_edge44.us, %._crit_edge.thread, %._crit_edge
  ret void
}

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

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

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" }
attributes #2 = { 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, !7, i64 4}
!6 = !{!"Process", !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 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !7, i64 8}
!17 = distinct !{!17, !12}
!18 = distinct !{!18, !12, !14, !13}


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