; LLVM IR from af-jk/rtos :: src (stos)

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

; Function Attrs: nounwind uwtable
define dso_local void @STOS_CreateTask(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %17, label %14

14:                                               ; preds = %4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14, %4
  br label %92

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %19 = call ptr asm sideeffect " MRS   $0, psp    \0A", "=r,~{dirflag},~{fpsr},~{flags}"() #2, !srcloc !11
  store ptr %19, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = ptrtoint ptr %20 to i32
  %22 = zext i32 %21 to i64
  %23 = inttoptr i64 %22 to ptr
  store ptr %23, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds i32, ptr %24, i32 -1
  store ptr %25, ptr %10, align 8, !tbaa !5
  store i32 16777216, ptr %25, align 4, !tbaa !9
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = ptrtoint ptr %26 to i32
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = getelementptr inbounds i32, ptr %28, i32 -1
  store ptr %29, ptr %10, align 8, !tbaa !5
  store i32 %27, ptr %29, align 4, !tbaa !9
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds i32, ptr %30, i32 -1
  store ptr %31, ptr %10, align 8, !tbaa !5
  store i32 14, ptr %31, align 4, !tbaa !9
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds i32, ptr %32, i32 -1
  store ptr %33, ptr %10, align 8, !tbaa !5
  store i32 12, ptr %33, align 4, !tbaa !9
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds i32, ptr %34, i32 -1
  store ptr %35, ptr %10, align 8, !tbaa !5
  store i32 3, ptr %35, align 4, !tbaa !9
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds i32, ptr %36, i32 -1
  store ptr %37, ptr %10, align 8, !tbaa !5
  store i32 2, ptr %37, align 4, !tbaa !9
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = getelementptr inbounds i32, ptr %38, i32 -1
  store ptr %39, ptr %10, align 8, !tbaa !5
  store i32 1, ptr %39, align 4, !tbaa !9
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds i32, ptr %40, i32 -1
  store ptr %41, ptr %10, align 8, !tbaa !5
  store i32 0, ptr %41, align 4, !tbaa !9
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = getelementptr inbounds i32, ptr %42, i32 -1
  store ptr %43, ptr %10, align 8, !tbaa !5
  store i32 11, ptr %43, align 4, !tbaa !9
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds i32, ptr %44, i32 -1
  store ptr %45, ptr %10, align 8, !tbaa !5
  store i32 10, ptr %45, align 4, !tbaa !9
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds i32, ptr %46, i32 -1
  store ptr %47, ptr %10, align 8, !tbaa !5
  store i32 9, ptr %47, align 4, !tbaa !9
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds i32, ptr %48, i32 -1
  store ptr %49, ptr %10, align 8, !tbaa !5
  store i32 8, ptr %49, align 4, !tbaa !9
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = getelementptr inbounds i32, ptr %50, i32 -1
  store ptr %51, ptr %10, align 8, !tbaa !5
  store i32 7, ptr %51, align 4, !tbaa !9
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds i32, ptr %52, i32 -1
  store ptr %53, ptr %10, align 8, !tbaa !5
  store i32 6, ptr %53, align 4, !tbaa !9
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds i32, ptr %54, i32 -1
  store ptr %55, ptr %10, align 8, !tbaa !5
  store i32 5, ptr %55, align 4, !tbaa !9
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds i32, ptr %56, i32 -1
  store ptr %57, ptr %10, align 8, !tbaa !5
  store i32 4, ptr %57, align 4, !tbaa !9
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.stos_tcb, ptr %59, i32 0, i32 0
  store ptr %58, ptr %60, align 8, !tbaa !12
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.stos_tcb, ptr %62, i32 0, i32 1
  store ptr %61, ptr %63, align 8, !tbaa !14
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.stos_tcb, ptr %65, i32 0, i32 3
  store i32 %64, ptr %66, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = zext i32 %68 to i64
  %70 = sub i64 0, %69
  %71 = getelementptr inbounds i32, ptr %67, i64 %70
  %72 = getelementptr inbounds i32, ptr %71, i64 4
  store ptr %72, ptr %11, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %77, %18
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = icmp ugt ptr %74, %75
  br i1 %76, label %77, label %80

77:                                               ; preds = %73
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = getelementptr inbounds i32, ptr %78, i32 -1
  store ptr %79, ptr %10, align 8, !tbaa !5
  store i32 -559038737, ptr %79, align 4, !tbaa !9
  br label %73, !llvm.loop !16

80:                                               ; preds = %73
  br label %81

81:                                               ; preds = %86, %80
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = ptrtoint ptr %82 to i32
  %84 = and i32 %83, 7
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %89

86:                                               ; preds = %81
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = getelementptr inbounds i32, ptr %87, i32 -1
  store ptr %88, ptr %10, align 8, !tbaa !5
  store i32 -18096467, ptr %88, align 4, !tbaa !9
  br label %81, !llvm.loop !18

89:                                               ; preds = %81
  %90 = load ptr, ptr %10, align 8, !tbaa !5
  call void asm sideeffect "MSR psp, $0", "r,~{dirflag},~{fpsr},~{flags}"(ptr %90) #2, !srcloc !19
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  call void @STOS_AddTask(ptr noundef %91, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %92

92:                                               ; preds = %89, %17
  ret void
}

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

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

; 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 = !{!"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 = !{i64 532}
!12 = !{!13, !6, i64 0}
!13 = !{!"stos_tcb", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !6, i64 32, !6, i64 40}
!14 = !{!13, !6, i64 8}
!15 = !{!13, !10, i64 20}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = !{i64 2096}


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

; Function Attrs: nounwind uwtable
define dso_local void @STOS_CreateTask(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %1, null
  %or.cond = or i1 %5, %6
  br i1 %or.cond, label %33, label %7

7:                                                ; preds = %4
  %8 = tail call ptr asm sideeffect " MRS   $0, psp    \0A", "=r,~{dirflag},~{fpsr},~{flags}"() #1, !srcloc !5
  %9 = ptrtoint ptr %8 to i64
  %10 = and i64 %9, 4294967295
  %11 = inttoptr i64 %10 to ptr
  %12 = getelementptr inbounds i8, ptr %11, i64 -4
  store i32 16777216, ptr %12, align 4, !tbaa !6
  %13 = ptrtoint ptr %1 to i64
  %14 = trunc i64 %13 to i32
  %15 = getelementptr inbounds i8, ptr %11, i64 -8
  store i32 %14, ptr %15, align 4, !tbaa !6
  %16 = getelementptr inbounds i8, ptr %11, i64 -12
  store i32 14, ptr %16, align 4, !tbaa !6
  %17 = getelementptr inbounds i8, ptr %11, i64 -16
  store i32 12, ptr %17, align 4, !tbaa !6
  %18 = getelementptr inbounds i8, ptr %11, i64 -32
  store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, ptr %18, align 4, !tbaa !6
  %19 = getelementptr inbounds i8, ptr %11, i64 -48
  store <4 x i32> <i32 8, i32 9, i32 10, i32 11>, ptr %19, align 4, !tbaa !6
  %.ptr = getelementptr inbounds i8, ptr %11, i64 -64
  store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, ptr %.ptr, align 4, !tbaa !6
  store ptr %.ptr, ptr %0, align 8, !tbaa !10
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %1, ptr %20, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %2, ptr %21, align 4, !tbaa !14
  %22 = zext i32 %3 to i64
  %.neg = mul nsw i64 %22, -4
  %23 = getelementptr i8, ptr %11, i64 %.neg
  %.ptr44 = getelementptr i8, ptr %23, i64 -48
  %24 = icmp ugt i32 %3, 4
  br i1 %24, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %7
  %.0.lcssa = phi ptr [ %.ptr, %7 ], [ %27, %.lr.ph ]
  %25 = ptrtoint ptr %.0.lcssa to i64
  %26 = and i64 %25, 7
  %.not38 = icmp eq i64 %26, 0
  br i1 %.not38, label %._crit_edge, label %.lr.ph40

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.037 = phi ptr [ %27, %.lr.ph ], [ %.ptr, %7 ]
  %27 = getelementptr inbounds i8, ptr %.037, i64 -4
  store i32 -559038737, ptr %27, align 4, !tbaa !6
  %28 = icmp ugt ptr %27, %.ptr44
  br i1 %28, label %.lr.ph, label %.preheader, !llvm.loop !15

.lr.ph40:                                         ; preds = %.preheader
  %29 = getelementptr inbounds i8, ptr %.0.lcssa, i64 -4
  store i32 -18096467, ptr %29, align 4, !tbaa !6
  %30 = ptrtoint ptr %29 to i64
  %31 = and i64 %30, 7
  %.not = icmp eq i64 %31, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph40.1, !llvm.loop !17

.lr.ph40.1:                                       ; preds = %.lr.ph40
  %32 = getelementptr inbounds i8, ptr %.0.lcssa, i64 -8
  store i32 -18096467, ptr %32, align 4, !tbaa !6
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph40, %.lr.ph40.1, %.preheader
  %.1.lcssa = phi ptr [ %.0.lcssa, %.preheader ], [ %29, %.lr.ph40 ], [ %32, %.lr.ph40.1 ]
  tail call void asm sideeffect "MSR psp, $0", "r,~{dirflag},~{fpsr},~{flags}"(ptr nonnull %.1.lcssa) #1, !srcloc !18
  tail call void @STOS_AddTask(ptr noundef nonnull %0, i32 noundef 0)
  br label %33

33:                                               ; preds = %4, %._crit_edge
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @STOS_AddTask(ptr noundef, i32 noundef) local_unnamed_addr #0

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 = { 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 = !{i64 532}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"stos_tcb", !12, i64 0, !12, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !12, i64 32, !12, i64 40}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!11, !12, i64 8}
!14 = !{!11, !7, i64 20}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{i64 2096}


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