; LLVM IR from AlgoGenesis/C :: Miscellaneous Algorithms/gang cpu 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"

%union.pthread_barrier_t = type { i64, [24 x i8] }

@barrier = external dso_local global %union.pthread_barrier_t, align 8
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @execute_task(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [8 x i64], align 16
  %3 = alloca i32, align 4
  %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 i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 64, ptr %2) #5
  %9 = call i32 @pthread_barrier_init(ptr noundef @barrier, ptr noundef null, i32 noundef 4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %65, %0
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 2
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  store i32 2, ptr %5, align 4
  br label %68

14:                                               ; preds = %10
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %16)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %39, %14
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = icmp slt i32 %19, 4
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  store i32 5, ptr %5, align 4
  br label %42

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %23 = call noalias ptr @malloc(i64 noundef 4) #6
  store ptr %23, ptr %7, align 8, !tbaa !9
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %24, ptr %25, align 4, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [8 x i64], ptr %2, i64 0, i64 %27
  %29 = load ptr, ptr %7, align 8, !tbaa !9
  %30 = call i32 @pthread_create(ptr noundef %28, ptr noundef null, ptr noundef @execute_task, ptr noundef %29) #5
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %22
  call void @perror(ptr noundef @.str.2)
  store i32 1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %36

33:                                               ; preds = %22
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %3, align 4, !tbaa !5
  store i32 0, ptr %5, align 4
  br label %36

36:                                               ; preds = %33, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  %37 = load i32, ptr %5, align 4
  switch i32 %37, label %42 [
    i32 0, label %38
  ]

38:                                               ; preds = %36
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %6, align 4, !tbaa !5
  br label %18, !llvm.loop !11

42:                                               ; preds = %36, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %43 = load i32, ptr %5, align 4
  switch i32 %43, label %68 [
    i32 5, label %44
  ]

44:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %58, %44
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = icmp slt i32 %46, 4
  br i1 %47, label %49, label %48

48:                                               ; preds = %45
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %61

49:                                               ; preds = %45
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = mul nsw i32 %50, 4
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = add nsw i32 %51, %52
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [8 x i64], ptr %2, i64 0, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !13
  %57 = call i32 @pthread_join(i64 noundef %56, ptr noundef null)
  br label %58

58:                                               ; preds = %49
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %8, align 4, !tbaa !5
  br label %45, !llvm.loop !15

61:                                               ; preds = %48
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %63)
  br label %65

65:                                               ; preds = %61
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %4, align 4, !tbaa !5
  br label %10, !llvm.loop !16

68:                                               ; preds = %42, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %69 = load i32, ptr %5, align 4
  switch i32 %69, label %73 [
    i32 2, label %70
  ]

70:                                               ; preds = %68
  %71 = call i32 @pthread_barrier_destroy(ptr noundef @barrier) #5
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %73

73:                                               ; preds = %70, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %2) #5
  %74 = load i32, ptr %1, align 4
  ret i32 %74
}

; Function Attrs: nounwind
declare i32 @pthread_barrier_init(ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

; Function Attrs: nounwind
declare i32 @pthread_create(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

declare void @perror(ptr noundef) #2

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

declare i32 @pthread_join(i64 noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @pthread_barrier_destroy(ptr noundef) #3

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 = { "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 "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 allocsize(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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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

%union.pthread_barrier_t = type { i64, [24 x i8] }

@barrier = external dso_local global %union.pthread_barrier_t, align 8
@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @execute_task(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main() local_unnamed_addr #0 {
  %1 = alloca [8 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %1) #6
  %2 = tail call i32 @pthread_barrier_init(ptr noundef nonnull @barrier, ptr noundef null, i32 noundef 4) #6
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef 1)
  %4 = tail call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #7
  store i32 0, ptr %4, align 4, !tbaa !5
  %5 = call i32 @pthread_create(ptr noundef nonnull %1, ptr noundef null, ptr noundef nonnull @execute_task, ptr noundef nonnull %4) #6
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %54

6:                                                ; preds = %0
  %7 = call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #7
  store i32 1, ptr %7, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = call i32 @pthread_create(ptr noundef nonnull %8, ptr noundef null, ptr noundef nonnull @execute_task, ptr noundef nonnull %7) #6
  %.not.1 = icmp eq i32 %9, 0
  br i1 %.not.1, label %10, label %54

10:                                               ; preds = %6
  %11 = call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #7
  store i32 2, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  %13 = call i32 @pthread_create(ptr noundef nonnull %12, ptr noundef null, ptr noundef nonnull @execute_task, ptr noundef nonnull %11) #6
  %.not.2 = icmp eq i32 %13, 0
  br i1 %.not.2, label %14, label %54

14:                                               ; preds = %10
  %15 = call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #7
  store i32 3, ptr %15, align 4, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %1, i64 24
  %17 = call i32 @pthread_create(ptr noundef nonnull %16, ptr noundef null, ptr noundef nonnull @execute_task, ptr noundef nonnull %15) #6
  %.not.3 = icmp eq i32 %17, 0
  br i1 %.not.3, label %.preheader, label %54

.preheader:                                       ; preds = %14
  %18 = load i64, ptr %1, align 16, !tbaa !9
  %19 = call i32 @pthread_join(i64 noundef %18, ptr noundef null) #6
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = call i32 @pthread_join(i64 noundef %20, ptr noundef null) #6
  %22 = load i64, ptr %12, align 16, !tbaa !9
  %23 = call i32 @pthread_join(i64 noundef %22, ptr noundef null) #6
  %24 = load i64, ptr %16, align 8, !tbaa !9
  %25 = call i32 @pthread_join(i64 noundef %24, ptr noundef null) #6
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef 1)
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef 2)
  %28 = call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #7
  store i32 4, ptr %28, align 4, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %1, i64 32
  %30 = call i32 @pthread_create(ptr noundef nonnull %29, ptr noundef null, ptr noundef nonnull @execute_task, ptr noundef nonnull %28) #6
  %.not.155 = icmp eq i32 %30, 0
  br i1 %.not.155, label %31, label %54

31:                                               ; preds = %.preheader
  %32 = call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #7
  store i32 5, ptr %32, align 4, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %1, i64 40
  %34 = call i32 @pthread_create(ptr noundef nonnull %33, ptr noundef null, ptr noundef nonnull @execute_task, ptr noundef nonnull %32) #6
  %.not.1.1 = icmp eq i32 %34, 0
  br i1 %.not.1.1, label %35, label %54

35:                                               ; preds = %31
  %36 = call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #7
  store i32 6, ptr %36, align 4, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %1, i64 48
  %38 = call i32 @pthread_create(ptr noundef nonnull %37, ptr noundef null, ptr noundef nonnull @execute_task, ptr noundef nonnull %36) #6
  %.not.2.1 = icmp eq i32 %38, 0
  br i1 %.not.2.1, label %39, label %54

39:                                               ; preds = %35
  %40 = call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #7
  store i32 7, ptr %40, align 4, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %1, i64 56
  %42 = call i32 @pthread_create(ptr noundef nonnull %41, ptr noundef null, ptr noundef nonnull @execute_task, ptr noundef nonnull %40) #6
  %.not.3.1 = icmp eq i32 %42, 0
  br i1 %.not.3.1, label %.preheader.1, label %54

.preheader.1:                                     ; preds = %39
  %43 = load i64, ptr %29, align 16, !tbaa !9
  %44 = call i32 @pthread_join(i64 noundef %43, ptr noundef null) #6
  %45 = load i64, ptr %33, align 8, !tbaa !9
  %46 = call i32 @pthread_join(i64 noundef %45, ptr noundef null) #6
  %47 = load i64, ptr %37, align 16, !tbaa !9
  %48 = call i32 @pthread_join(i64 noundef %47, ptr noundef null) #6
  %49 = load i64, ptr %41, align 8, !tbaa !9
  %50 = call i32 @pthread_join(i64 noundef %49, ptr noundef null) #6
  %51 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef 2)
  %52 = call i32 @pthread_barrier_destroy(ptr noundef nonnull @barrier) #6
  %53 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %55

54:                                               ; preds = %39, %35, %31, %.preheader, %14, %10, %6, %0
  call void @perror(ptr noundef nonnull @.str.2) #8
  br label %55

55:                                               ; preds = %54, %.preheader.1
  %.5 = phi i32 [ 0, %.preheader.1 ], [ 1, %54 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %1) #6
  ret i32 %.5
}

; Function Attrs: nounwind
declare i32 @pthread_barrier_init(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare i32 @pthread_create(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #2

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

declare i32 @pthread_join(i64 noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind
declare i32 @pthread_barrier_destroy(ptr noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { cold }

!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", !7, i64 0}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass