; 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

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

18:                                               ; preds = %4
  %19 = load i32, ptr %12, align 4, !tbaa !10
  call void @OS_CPU_SR_Restore(i32 noundef %19)
  store i8 60, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %57

20:                                               ; preds = %4
  %21 = load i8, ptr %9, align 1, !tbaa !9
  %22 = zext i8 %21 to i64
  %23 = getelementptr inbounds [64 x ptr], ptr @OSTCBPrioTbl, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %55

26:                                               ; preds = %20
  %27 = load i8, ptr %9, align 1, !tbaa !9
  %28 = zext i8 %27 to i64
  %29 = getelementptr inbounds [64 x ptr], ptr @OSTCBPrioTbl, i64 0, i64 %28
  store ptr inttoptr (i64 1 to ptr), ptr %29, align 8, !tbaa !5
  %30 = load i32, ptr %12, align 4, !tbaa !10
  call void @OS_CPU_SR_Restore(i32 noundef %30)
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = call ptr @OSTaskStkInit(ptr noundef %31, ptr noundef %32, ptr noundef %33, i16 noundef zeroext 0)
  store ptr %34, ptr %10, align 8, !tbaa !5
  %35 = load i8, ptr %9, align 1, !tbaa !9
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = call zeroext i8 @OS_TCBInit(i8 noundef zeroext %35, ptr noundef %36, ptr noundef null, i16 noundef zeroext 0, i32 noundef 0, ptr noundef null, i16 noundef zeroext 0)
  store i8 %37, ptr %11, align 1, !tbaa !9
  %38 = load i8, ptr %11, align 1, !tbaa !9
  %39 = zext i8 %38 to i32
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %47

41:                                               ; preds = %26
  %42 = load i8, ptr @OSRunning, align 1, !tbaa !9
  %43 = zext i8 %42 to i32
  %44 = icmp eq i32 %43, 1
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  call void @OS_Sched()
  br label %46

46:                                               ; preds = %45, %41
  br label %53

47:                                               ; preds = %26
  %48 = call i32 @OS_CPU_SR_Save()
  store i32 %48, ptr %12, align 4, !tbaa !10
  %49 = load i8, ptr %9, align 1, !tbaa !9
  %50 = zext i8 %49 to i64
  %51 = getelementptr inbounds [64 x ptr], ptr @OSTCBPrioTbl, i64 0, i64 %50
  store ptr null, ptr %51, align 8, !tbaa !5
  %52 = load i32, ptr %12, align 4, !tbaa !10
  call void @OS_CPU_SR_Restore(i32 noundef %52)
  br label %53

53:                                               ; preds = %47, %46
  %54 = load i8, ptr %11, align 1, !tbaa !9
  store i8 %54, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %57

55:                                               ; preds = %20
  %56 = load i32, ptr %12, align 4, !tbaa !10
  call void @OS_CPU_SR_Restore(i32 noundef %56)
  store i8 40, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %57

57:                                               ; preds = %55, %53, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %58 = load i8, ptr %5, align 1
  ret i8 %58
}

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

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 = !{!"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

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

7:                                                ; preds = %4
  tail call void @OS_CPU_SR_Restore(i32 noundef %5) #2
  br label %24

8:                                                ; preds = %4
  %9 = zext i8 %3 to i64
  %10 = getelementptr inbounds [64 x ptr], ptr @OSTCBPrioTbl, i64 0, i64 %9
  %11 = load ptr, ptr %10, align 8, !tbaa !8
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %23

13:                                               ; preds = %8
  store ptr inttoptr (i64 1 to ptr), ptr %10, align 8, !tbaa !8
  tail call void @OS_CPU_SR_Restore(i32 noundef %5) #2
  %14 = tail call ptr @OSTaskStkInit(ptr noundef %0, ptr noundef %1, ptr noundef %2, i16 noundef zeroext 0) #2
  %15 = tail call zeroext i8 @OS_TCBInit(i8 noundef zeroext %3, ptr noundef %14, ptr noundef null, i16 noundef zeroext 0, i32 noundef 0, ptr noundef null, i16 noundef zeroext 0) #2
  %16 = icmp eq i8 %15, 0
  br i1 %16, label %17, label %21

17:                                               ; preds = %13
  %18 = load i8, ptr @OSRunning, align 1, !tbaa !5
  %19 = icmp eq i8 %18, 1
  br i1 %19, label %20, label %24

20:                                               ; preds = %17
  tail call void @OS_Sched() #2
  br label %24

21:                                               ; preds = %13
  %22 = tail call i32 @OS_CPU_SR_Save() #2
  store ptr null, ptr %10, align 8, !tbaa !8
  tail call void @OS_CPU_SR_Restore(i32 noundef %22) #2
  br label %24

23:                                               ; preds = %8
  tail call void @OS_CPU_SR_Restore(i32 noundef %5) #2
  br label %24

24:                                               ; preds = %21, %20, %17, %23, %7
  %.0 = phi i8 [ 60, %7 ], [ 40, %23 ], [ 0, %17 ], [ 0, %20 ], [ %15, %21 ]
  ret i8 %.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

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