; LLVM IR from HANDS-FREE/OpenRE :: 3_OS/STM32F1/RTOS/uCOS-II/CORE (os_task)

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

@OSTCBPrioTbl = external global [64 x ptr], align 16
@OSRunning = external global i8, align 1
@OSIntNesting = external global i8, align 1

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

declare i32 @OS_CPU_SR_Save() #1

declare void @OS_CPU_SR_Restore(i32 noundef) #1

declare void @OS_Sched() #1

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

declare ptr @OSTaskStkInit(ptr noundef, ptr noundef, ptr noundef, i16 noundef zeroext) #1

declare zeroext i8 @OS_TCBInit(i8 noundef zeroext, ptr noundef, ptr noundef, i16 noundef zeroext, i32 noundef, ptr noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @OSTaskCreateExt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i8 noundef zeroext %3, i16 noundef zeroext %4, ptr noundef %5, i32 noundef %6, ptr noundef %7, i16 noundef zeroext %8) #2 {
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i8, align 1
  %15 = alloca i16, align 2
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca i16, align 2
  %20 = alloca ptr, align 8
  %21 = alloca i8, align 1
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  store ptr %0, ptr %11, align 8, !tbaa !5
  store ptr %1, ptr %12, align 8, !tbaa !5
  store ptr %2, ptr %13, align 8, !tbaa !5
  store i8 %3, ptr %14, align 1, !tbaa !9
  store i16 %4, ptr %15, align 2, !tbaa !10
  store ptr %5, ptr %16, align 8, !tbaa !5
  store i32 %6, ptr %17, align 4, !tbaa !12
  store ptr %7, ptr %18, align 8, !tbaa !5
  store i16 %8, ptr %19, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %21) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #3
  store i32 0, ptr %22, align 4, !tbaa !12
  %24 = call i32 @OS_CPU_SR_Save()
  store i32 %24, ptr %22, align 4, !tbaa !12
  %25 = load i8, ptr @OSIntNesting, align 1, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = icmp ugt i32 %26, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %9
  %29 = load i32, ptr %22, align 4, !tbaa !12
  call void @OS_CPU_SR_Restore(i32 noundef %29)
  store i8 60, ptr %10, align 1
  store i32 1, ptr %23, align 4
  br label %76

30:                                               ; preds = %9
  %31 = load i8, ptr %14, align 1, !tbaa !9
  %32 = zext i8 %31 to i64
  %33 = getelementptr inbounds [64 x ptr], ptr @OSTCBPrioTbl, i64 0, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %74

36:                                               ; preds = %30
  %37 = load i8, ptr %14, align 1, !tbaa !9
  %38 = zext i8 %37 to i64
  %39 = getelementptr inbounds [64 x ptr], ptr @OSTCBPrioTbl, i64 0, i64 %38
  store ptr inttoptr (i64 1 to ptr), ptr %39, align 8, !tbaa !5
  %40 = load i32, ptr %22, align 4, !tbaa !12
  call void @OS_CPU_SR_Restore(i32 noundef %40)
  %41 = load ptr, ptr %16, align 8, !tbaa !5
  %42 = load i32, ptr %17, align 4, !tbaa !12
  %43 = load i16, ptr %19, align 2, !tbaa !10
  call void @OS_TaskStkClr(ptr noundef %41, i32 noundef %42, i16 noundef zeroext %43)
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = load i16, ptr %19, align 2, !tbaa !10
  %48 = call ptr @OSTaskStkInit(ptr noundef %44, ptr noundef %45, ptr noundef %46, i16 noundef zeroext %47)
  store ptr %48, ptr %20, align 8, !tbaa !5
  %49 = load i8, ptr %14, align 1, !tbaa !9
  %50 = load ptr, ptr %20, align 8, !tbaa !5
  %51 = load ptr, ptr %16, align 8, !tbaa !5
  %52 = load i16, ptr %15, align 2, !tbaa !10
  %53 = load i32, ptr %17, align 4, !tbaa !12
  %54 = load ptr, ptr %18, align 8, !tbaa !5
  %55 = load i16, ptr %19, align 2, !tbaa !10
  %56 = call zeroext i8 @OS_TCBInit(i8 noundef zeroext %49, ptr noundef %50, ptr noundef %51, i16 noundef zeroext %52, i32 noundef %53, ptr noundef %54, i16 noundef zeroext %55)
  store i8 %56, ptr %21, align 1, !tbaa !9
  %57 = load i8, ptr %21, align 1, !tbaa !9
  %58 = zext i8 %57 to i32
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %60, label %66

60:                                               ; preds = %36
  %61 = load i8, ptr @OSRunning, align 1, !tbaa !9
  %62 = zext i8 %61 to i32
  %63 = icmp eq i32 %62, 1
  br i1 %63, label %64, label %65

64:                                               ; preds = %60
  call void @OS_Sched()
  br label %65

65:                                               ; preds = %64, %60
  br label %72

66:                                               ; preds = %36
  %67 = call i32 @OS_CPU_SR_Save()
  store i32 %67, ptr %22, align 4, !tbaa !12
  %68 = load i8, ptr %14, align 1, !tbaa !9
  %69 = zext i8 %68 to i64
  %70 = getelementptr inbounds [64 x ptr], ptr @OSTCBPrioTbl, i64 0, i64 %69
  store ptr null, ptr %70, align 8, !tbaa !5
  %71 = load i32, ptr %22, align 4, !tbaa !12
  call void @OS_CPU_SR_Restore(i32 noundef %71)
  br label %72

72:                                               ; preds = %66, %65
  %73 = load i8, ptr %21, align 1, !tbaa !9
  store i8 %73, ptr %10, align 1
  store i32 1, ptr %23, align 4
  br label %76

74:                                               ; preds = %30
  %75 = load i32, ptr %22, align 4, !tbaa !12
  call void @OS_CPU_SR_Restore(i32 noundef %75)
  store i8 40, ptr %10, align 1
  store i32 1, ptr %23, align 4
  br label %76

76:                                               ; preds = %74, %72, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  %77 = load i8, ptr %10, align 1
  ret i8 %77
}

; Function Attrs: nounwind uwtable
declare dso_local void @OS_TaskStkClr(ptr noundef, i32 noundef, i16 noundef zeroext) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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"

@OSTCBPrioTbl = external local_unnamed_addr global [64 x ptr], align 16
@OSRunning = external local_unnamed_addr global i8, align 1
@OSIntNesting = external local_unnamed_addr global i8, align 1

declare i32 @OS_CPU_SR_Save() local_unnamed_addr #0

declare void @OS_CPU_SR_Restore(i32 noundef) local_unnamed_addr #0

declare void @OS_Sched() local_unnamed_addr #0

declare ptr @OSTaskStkInit(ptr noundef, ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

declare zeroext i8 @OS_TCBInit(i8 noundef zeroext, ptr noundef, ptr noundef, i16 noundef zeroext, i32 noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @OSTaskCreateExt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i8 noundef zeroext %3, i16 noundef zeroext %4, ptr noundef %5, i32 noundef %6, ptr noundef %7, i16 noundef zeroext %8) local_unnamed_addr #1 {
  %10 = tail call i32 @OS_CPU_SR_Save() #2
  %11 = load i8, ptr @OSIntNesting, align 1, !tbaa !5
  %.not = icmp eq i8 %11, 0
  br i1 %.not, label %13, label %12

12:                                               ; preds = %9
  tail call void @OS_CPU_SR_Restore(i32 noundef %10) #2
  br label %29

13:                                               ; preds = %9
  %14 = zext i8 %3 to i64
  %15 = getelementptr inbounds [64 x ptr], ptr @OSTCBPrioTbl, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !8
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %28

18:                                               ; preds = %13
  store ptr inttoptr (i64 1 to ptr), ptr %15, align 8, !tbaa !8
  tail call void @OS_CPU_SR_Restore(i32 noundef %10) #2
  tail call void @OS_TaskStkClr(ptr noundef %5, i32 noundef %6, i16 noundef zeroext %8)
  %19 = tail call ptr @OSTaskStkInit(ptr noundef %0, ptr noundef %1, ptr noundef %2, i16 noundef zeroext %8) #2
  %20 = tail call zeroext i8 @OS_TCBInit(i8 noundef zeroext %3, ptr noundef %19, ptr noundef %5, i16 noundef zeroext %4, i32 noundef %6, ptr noundef %7, i16 noundef zeroext %8) #2
  %21 = icmp eq i8 %20, 0
  br i1 %21, label %22, label %26

22:                                               ; preds = %18
  %23 = load i8, ptr @OSRunning, align 1, !tbaa !5
  %24 = icmp eq i8 %23, 1
  br i1 %24, label %25, label %29

25:                                               ; preds = %22
  tail call void @OS_Sched() #2
  br label %29

26:                                               ; preds = %18
  %27 = tail call i32 @OS_CPU_SR_Save() #2
  store ptr null, ptr %15, align 8, !tbaa !8
  tail call void @OS_CPU_SR_Restore(i32 noundef %27) #2
  br label %29

28:                                               ; preds = %13
  tail call void @OS_CPU_SR_Restore(i32 noundef %10) #2
  br label %29

29:                                               ; preds = %26, %25, %22, %28, %12
  %.0 = phi i8 [ 60, %12 ], [ 40, %28 ], [ 0, %22 ], [ 0, %25 ], [ %20, %26 ]
  ret i8 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local void @OS_TaskStkClr(ptr noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #1

attributes #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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass