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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @os_inc_and_compare() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  store i64 0, ptr %2, align 8, !tbaa !9
  %3 = load volatile i64, ptr @os_time, align 8, !tbaa !11
  %4 = add nsw i64 %3, 1
  store volatile i64 %4, ptr @os_time, align 8, !tbaa !11
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %24, %0
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = load volatile i64, ptr @it, align 8, !tbaa !9
  %9 = icmp ult i64 %7, %8
  br i1 %9, label %10, label %27

10:                                               ; preds = %5
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [5 x %struct._tcb], ptr @tcb, i64 0, i64 %12
  %14 = getelementptr inbounds %struct._tcb, ptr %13, i32 0, i32 3
  %15 = load volatile i64, ptr %14, align 8, !tbaa !13
  %16 = load volatile i64, ptr @os_time, align 8, !tbaa !11
  %17 = icmp eq i64 %15, %16
  br i1 %17, label %18, label %23

18:                                               ; preds = %10
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [5 x %struct._tcb], ptr @tcb, i64 0, i64 %20
  %22 = getelementptr inbounds %struct._tcb, ptr %21, i32 0, i32 1
  store volatile i64 1, ptr %22, align 8, !tbaa !16
  store i64 1, ptr %2, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %18, %10
  br label %24

24:                                               ; preds = %23
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !17

27:                                               ; preds = %5
  %28 = load i64, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret i64 %28
}

; 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 memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = { 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", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !12, i64 24}
!14 = !{!"_tcb", !15, i64 0, !10, i64 8, !10, i64 16, !12, i64 24}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!14, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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._tcb = type { ptr, i64, i64, i64 }

@it = external dso_local global i64, align 8
@os_time = 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 range(i64 0, 2) i64 @os_inc_and_compare() local_unnamed_addr #0 {
  %1 = load volatile i64, ptr @os_time, align 8, !tbaa !5
  %2 = add nsw i64 %1, 1
  store volatile i64 %2, ptr @os_time, align 8, !tbaa !5
  %3 = load volatile i64, ptr @it, align 8, !tbaa !9
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %11
  %indvars.iv = phi i64 [ %indvars.iv.next, %11 ], [ 0, %0 ]
  %.08 = phi i64 [ %.1, %11 ], [ 0, %0 ]
  %4 = getelementptr inbounds [5 x %struct._tcb], ptr @tcb, i64 0, i64 %indvars.iv
  %5 = getelementptr inbounds i8, ptr %4, i64 24
  %6 = load volatile i64, ptr %5, align 8, !tbaa !11
  %7 = load volatile i64, ptr @os_time, align 8, !tbaa !5
  %8 = icmp eq i64 %6, %7
  br i1 %8, label %9, label %11

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds i8, ptr %4, i64 8
  store volatile i64 1, ptr %10, align 8, !tbaa !14
  br label %11

11:                                               ; preds = %.lr.ph, %9
  %.1 = phi i64 [ 1, %9 ], [ %.08, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load volatile i64, ptr @it, align 8, !tbaa !9
  %13 = icmp ugt i64 %12, %indvars.iv.next
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %11, %0
  %.0.lcssa = phi i64 [ 0, %0 ], [ %.1, %11 ]
  ret i64 %.0.lcssa
}

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


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