; LLVM IR from t4th/cortex-m3-rtos :: examples/create_task/main.ll (Z5task1Pv)

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

@_ZZ5task1PvE4once = external hidden global i8, align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5delayj(i32 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare noundef zeroext i1 @_ZN6kernel4task6createEPFvPvENS0_8PriorityEPNS_6HandleES1_b(ptr noundef, i32 noundef, ptr noundef, ptr noundef, i1 noundef zeroext) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5task1Pv(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.4)
  br label %8

8:                                                ; preds = %31, %1
  br label %9

9:                                                ; preds = %8
  %10 = load i8, ptr @_ZZ5task1PvE4once, align 1, !tbaa !11, !range !13, !noundef !14
  %11 = trunc i8 %10 to i1
  br i1 %11, label %12, label %25

12:                                               ; preds = %9
  store i8 0, ptr @_ZZ5task1PvE4once, align 1, !tbaa !11
  call void @_Z5delayj(i32 noundef 1000000)
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.5)
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Task_ids, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = call noundef zeroext i1 @_ZN6kernel4task6createEPFvPvENS0_8PriorityEPNS_6HandleES1_b(ptr noundef @_Z5task2Pv, i32 noundef 1, ptr noundef %14, ptr noundef %15, i1 noundef zeroext false)
  %17 = zext i1 %16 to i8
  store i8 %17, ptr %5, align 1, !tbaa !11
  %18 = load i8, ptr %5, align 1, !tbaa !11, !range !13, !noundef !14
  %19 = trunc i8 %18 to i1
  %20 = zext i1 %19 to i32
  %21 = icmp eq i32 0, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %12
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.6)
  br label %23

23:                                               ; preds = %22, %12
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.7)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %24 = call noundef i32 @_ZN6kernel4task10getCurrentEv()
  store i32 %24, ptr %6, align 4, !tbaa !15
  call void @_ZN6kernel4task9terminateERNS_6HandleE(ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  br label %31

25:                                               ; preds = %9
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %4, align 4, !tbaa !9
  %28 = icmp sge i32 %27, 20
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.7)
  br label %32

30:                                               ; preds = %25
  call void @_Z5delayj(i32 noundef 100000)
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.8)
  br label %31

31:                                               ; preds = %30, %23
  br label %8, !llvm.loop !17

32:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

declare void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef) #2

declare void @_ZN6kernel4task9terminateERNS_6HandleE(ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5task2Pv(ptr noundef) #3

declare noundef i32 @_ZN6kernel4task10getCurrentEv() #2

attributes #0 = { mustprogress 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 = { "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 = { mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !16, i64 0}
!16 = !{!"_ZTSN6kernel6HandleE", !7, i64 0}
!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"

@_ZZ5task1PvE4once = external hidden local_unnamed_addr global i8, align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5delayj(i32 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare noundef zeroext i1 @_ZN6kernel4task6createEPFvPvENS0_8PriorityEPNS_6HandleES1_b(ptr noundef, i32 noundef, ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5task1Pv(ptr noundef %0) local_unnamed_addr #3 {
  %2 = alloca i32, align 4
  tail call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.4)
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  br label %.outer

.outer:                                           ; preds = %15, %1
  %.0.ph = phi i32 [ %16, %15 ], [ 0, %1 ]
  br label %4

4:                                                ; preds = %.outer, %10
  %5 = load i8, ptr @_ZZ5task1PvE4once, align 1, !tbaa !5, !range !9, !noundef !10
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %7, label %12

7:                                                ; preds = %4
  store i8 0, ptr @_ZZ5task1PvE4once, align 1, !tbaa !5
  call void @_Z5delayj(i32 noundef 1000000)
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.5)
  %8 = call noundef zeroext i1 @_ZN6kernel4task6createEPFvPvENS0_8PriorityEPNS_6HandleES1_b(ptr noundef nonnull @_Z5task2Pv, i32 noundef 1, ptr noundef nonnull %3, ptr noundef %0, i1 noundef zeroext false)
  br i1 %8, label %10, label %9

9:                                                ; preds = %7
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.6)
  br label %10

10:                                               ; preds = %9, %7
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.7)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %11 = call noundef i32 @_ZN6kernel4task10getCurrentEv()
  store i32 %11, ptr %2, align 4, !tbaa !11
  call void @_ZN6kernel4task9terminateERNS_6HandleE(ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  br label %4, !llvm.loop !13

12:                                               ; preds = %4
  %13 = icmp ugt i32 %.0.ph, 18
  br i1 %13, label %14, label %15

14:                                               ; preds = %12
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.7)
  ret void

15:                                               ; preds = %12
  %16 = add nuw nsw i32 %.0.ph, 1
  call void @_Z5delayj(i32 noundef 100000)
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.8)
  br label %.outer, !llvm.loop !13
}

declare void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef) local_unnamed_addr #2

declare void @_ZN6kernel4task9terminateERNS_6HandleE(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5task2Pv(ptr noundef) #3

declare noundef i32 @_ZN6kernel4task10getCurrentEv() local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { "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 = { mustprogress 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 #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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTSN6kernel6HandleE", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass