; LLVM IR from whoiswelliton/Computer_Engineering_UTFPR-PB :: Embedded_Systems/Project - RTOS on Coldfire/Base/Coldfare/Coldfare_v1t/Sources_ (scheduler)

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

@ct = external dso_local global i64, align 8
@it = external dso_local global i64, align 8
@tcb = external dso_local global [5 x %struct._tcb], align 16

; 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 ptr @scheduler() #1 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  store i64 0, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  store i64 0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 0, ptr %3, align 8, !tbaa !5
  store i64 0, ptr %1, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %29, %0
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = load volatile i64, ptr @it, align 8, !tbaa !5
  %7 = icmp ult i64 %5, %6
  br i1 %7, label %8, label %32

8:                                                ; preds = %4
  %9 = load i64, ptr %1, align 8, !tbaa !5
  %10 = getelementptr inbounds [5 x %struct._tcb], ptr @tcb, i64 0, i64 %9
  %11 = getelementptr inbounds %struct._tcb, ptr %10, i32 0, i32 1
  %12 = load volatile i64, ptr %11, align 8, !tbaa !9
  %13 = icmp eq i64 %12, 1
  br i1 %13, label %14, label %28

14:                                               ; preds = %8
  %15 = load i64, ptr %1, align 8, !tbaa !5
  %16 = getelementptr inbounds [5 x %struct._tcb], ptr @tcb, i64 0, i64 %15
  %17 = getelementptr inbounds %struct._tcb, ptr %16, i32 0, i32 2
  %18 = load volatile i64, ptr %17, align 16, !tbaa !13
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = icmp uge i64 %18, %19
  br i1 %20, label %21, label %27

21:                                               ; preds = %14
  %22 = load i64, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds [5 x %struct._tcb], ptr @tcb, i64 0, i64 %22
  %24 = getelementptr inbounds %struct._tcb, ptr %23, i32 0, i32 2
  %25 = load volatile i64, ptr %24, align 16, !tbaa !13
  store i64 %25, ptr %2, align 8, !tbaa !5
  %26 = load i64, ptr %1, align 8, !tbaa !5
  store i64 %26, ptr %3, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %21, %14
  br label %28

28:                                               ; preds = %27, %8
  br label %29

29:                                               ; preds = %28
  %30 = load i64, ptr %1, align 8, !tbaa !5
  %31 = add i64 %30, 1
  store i64 %31, ptr %1, align 8, !tbaa !5
  br label %4, !llvm.loop !14

32:                                               ; preds = %4
  %33 = load i64, ptr %3, align 8, !tbaa !5
  store volatile i64 %33, ptr @ct, align 8, !tbaa !5
  %34 = load volatile i64, ptr @ct, align 8, !tbaa !5
  %35 = getelementptr inbounds [5 x %struct._tcb], ptr @tcb, i64 0, i64 %34
  %36 = getelementptr inbounds %struct._tcb, ptr %35, i32 0, i32 0
  %37 = load volatile ptr, ptr %36, align 16, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret ptr %37
}

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 }

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


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

@ct = external dso_local global i64, align 8
@it = external dso_local global i64, align 8
@tcb = external dso_local global [5 x %struct._tcb], align 16

; Function Attrs: nofree norecurse nounwind memory(readwrite, argmem: none) uwtable
define dso_local ptr @scheduler() local_unnamed_addr #0 {
  %1 = load volatile i64, ptr @it, align 8, !tbaa !5
  %.not14 = icmp eq i64 %1, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %11
  %.013 = phi i64 [ %.1, %11 ], [ 0, %0 ]
  %.0812 = phi i64 [ %.19, %11 ], [ 0, %0 ]
  %.01011 = phi i64 [ %12, %11 ], [ 0, %0 ]
  %2 = getelementptr inbounds [5 x %struct._tcb], ptr @tcb, i64 0, i64 %.01011
  %3 = getelementptr inbounds i8, ptr %2, i64 8
  %4 = load volatile i64, ptr %3, align 8, !tbaa !9
  %5 = icmp eq i64 %4, 1
  br i1 %5, label %6, label %11

6:                                                ; preds = %.lr.ph
  %7 = getelementptr inbounds i8, ptr %2, i64 16
  %8 = load volatile i64, ptr %7, align 16, !tbaa !13
  %.not = icmp ult i64 %8, %.0812
  br i1 %.not, label %11, label %9

9:                                                ; preds = %6
  %10 = load volatile i64, ptr %7, align 16, !tbaa !13
  br label %11

11:                                               ; preds = %.lr.ph, %9, %6
  %.19 = phi i64 [ %10, %9 ], [ %.0812, %6 ], [ %.0812, %.lr.ph ]
  %.1 = phi i64 [ %.01011, %9 ], [ %.013, %6 ], [ %.013, %.lr.ph ]
  %12 = add nuw i64 %.01011, 1
  %13 = load volatile i64, ptr @it, align 8, !tbaa !5
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %11, %0
  %.0.lcssa = phi i64 [ 0, %0 ], [ %.1, %11 ]
  store volatile i64 %.0.lcssa, ptr @ct, align 8, !tbaa !5
  %15 = load volatile i64, ptr @ct, align 8, !tbaa !5
  %16 = getelementptr inbounds [5 x %struct._tcb], ptr @tcb, i64 0, i64 %15
  %17 = load volatile ptr, ptr %16, align 16, !tbaa !16
  ret ptr %17
}

attributes #0 = { nofree norecurse nounwind memory(readwrite, argmem: none) 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" }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass