; LLVM IR from Eslam-Rizk/Elite-DriveGuard :: Application/Middlewares/Third_Party/FreeRTOS/Source (tasks)

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

@xSchedulerRunning = external hidden global i64, align 8
@xTickCount = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@xIdleTaskHandle = external hidden global ptr, align 8
@xNextTaskUnblockTime = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local ptr @xTaskCreateStatic(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #0

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @vPortRaiseBASEPRI() #2

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

; Function Attrs: nounwind uwtable
define dso_local void @vTaskStartScheduler() #0 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @vApplicationGetIdleTaskMemory(ptr noundef %2, ptr noundef %3, ptr noundef %4)
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call ptr @xTaskCreateStatic(ptr noundef @prvIdleTask, ptr noundef @.str, i32 noundef %5, ptr noundef null, i64 noundef 0, ptr noundef %6, ptr noundef %7)
  store ptr %8, ptr @xIdleTaskHandle, align 8, !tbaa !5
  %9 = load ptr, ptr @xIdleTaskHandle, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %0
  store i64 1, ptr %1, align 8, !tbaa !11
  br label %13

12:                                               ; preds = %0
  store i64 0, ptr %1, align 8, !tbaa !11
  br label %13

13:                                               ; preds = %12, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %14 = load i64, ptr %1, align 8, !tbaa !11
  %15 = icmp eq i64 %14, 1
  br i1 %15, label %16, label %18

16:                                               ; preds = %13
  %17 = call i64 @xTimerCreateTimerTask()
  store i64 %17, ptr %1, align 8, !tbaa !11
  br label %19

18:                                               ; preds = %13
  br label %19

19:                                               ; preds = %18, %16
  %20 = load i64, ptr %1, align 8, !tbaa !11
  %21 = icmp eq i64 %20, 1
  br i1 %21, label %22, label %28

22:                                               ; preds = %19
  call void @vPortRaiseBASEPRI()
  store volatile i32 -1, ptr @xNextTaskUnblockTime, align 4, !tbaa !9
  store volatile i64 1, ptr @xSchedulerRunning, align 8, !tbaa !11
  store volatile i32 0, ptr @xTickCount, align 4, !tbaa !9
  %23 = call i64 @xPortStartScheduler()
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  br label %27

26:                                               ; preds = %22
  br label %27

27:                                               ; preds = %26, %25
  br label %36

28:                                               ; preds = %19
  %29 = load i64, ptr %1, align 8, !tbaa !11
  %30 = icmp ne i64 %29, -1
  %31 = zext i1 %30 to i32
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %28
  call void @vPortRaiseBASEPRI()
  br label %34

34:                                               ; preds = %34, %33
  br label %34

35:                                               ; preds = %28
  br label %36

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

declare void @vApplicationGetIdleTaskMemory(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @prvIdleTask(ptr noundef) #0

declare i64 @xTimerCreateTimerTask() #3

declare i64 @xPortStartScheduler() #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 = { alwaysinline 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 #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, !12, i64 0}
!12 = !{!"long", !7, 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"

@xSchedulerRunning = external hidden global i64, align 8
@xTickCount = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@xIdleTaskHandle = external hidden local_unnamed_addr global ptr, align 8
@xNextTaskUnblockTime = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local ptr @xTaskCreateStatic(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #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: alwaysinline nounwind uwtable
declare hidden void @vPortRaiseBASEPRI() 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

; Function Attrs: nounwind uwtable
define dso_local void @vTaskStartScheduler() local_unnamed_addr #0 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  store ptr null, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  call void @vApplicationGetIdleTaskMemory(ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3) #4
  %4 = load i32, ptr %3, align 4, !tbaa !9
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = call ptr @xTaskCreateStatic(ptr noundef nonnull @prvIdleTask, ptr noundef nonnull @.str, i32 noundef %4, ptr noundef null, i64 noundef 0, ptr noundef %5, ptr noundef %6)
  store ptr %7, ptr @xIdleTaskHandle, align 8, !tbaa !5
  %.not.not = icmp eq ptr %7, null
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  br i1 %.not.not, label %.thread, label %8

8:                                                ; preds = %0
  %9 = call i64 @xTimerCreateTimerTask() #4
  switch i64 %9, label %.thread [
    i64 1, label %10
    i64 -1, label %12
  ]

10:                                               ; preds = %8
  call void @vPortRaiseBASEPRI()
  store volatile i32 -1, ptr @xNextTaskUnblockTime, align 4, !tbaa !9
  store volatile i64 1, ptr @xSchedulerRunning, align 8, !tbaa !11
  store volatile i32 0, ptr @xTickCount, align 4, !tbaa !9
  %11 = call i64 @xPortStartScheduler() #4
  br label %.thread

12:                                               ; preds = %8
  call void @vPortRaiseBASEPRI()
  br label %13

13:                                               ; preds = %13, %12
  br label %13

.thread:                                          ; preds = %0, %8, %10
  ret void
}

declare void @vApplicationGetIdleTaskMemory(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @prvIdleTask(ptr noundef) #0

declare i64 @xTimerCreateTimerTask() local_unnamed_addr #3

declare i64 @xPortStartScheduler() 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 = { alwaysinline 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 #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, !12, i64 0}
!12 = !{!"long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass