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

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

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1

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

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

5:                                                ; preds = %14, %1
  br label %6

6:                                                ; preds = %5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load i32, ptr %7, align 4, !tbaa !9
  call void @_ZN6kernel4task5sleepEj(i32 noundef %8)
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = load i32, ptr %9, align 4, !tbaa !9
  switch i32 %10, label %14 [
    i32 100, label %11
    i32 500, label %12
    i32 1000, label %13
  ]

11:                                               ; preds = %6
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.1)
  br label %14

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

13:                                               ; preds = %6
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.3)
  br label %14

14:                                               ; preds = %13, %12, %11, %6
  br label %5, !llvm.loop !11
}

declare void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef) #2

declare void @_ZN6kernel4task5sleepEj(i32 noundef) #2

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

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: mustprogress noreturn uwtable
define dso_local void @_Z12task_routinePv(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  br label %.sink.split3

.sink.split3:                                     ; preds = %1, %.sink.split
  %.str.3.sink.sink = phi ptr [ %.str.3.sink, %.sink.split ], [ @.str, %1 ]
  tail call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull %.str.3.sink.sink)
  br label %2

2:                                                ; preds = %.sink.split3, %2
  %3 = load i32, ptr %0, align 4, !tbaa !5
  tail call void @_ZN6kernel4task5sleepEj(i32 noundef %3)
  %4 = load i32, ptr %0, align 4, !tbaa !5
  switch i32 %4, label %2 [
    i32 100, label %.sink.split.loopexit
    i32 500, label %.sink.split
    i32 1000, label %5
  ], !llvm.loop !9

5:                                                ; preds = %2
  br label %.sink.split

.sink.split.loopexit:                             ; preds = %2
  br label %.sink.split

.sink.split:                                      ; preds = %2, %.sink.split.loopexit, %5
  %.str.3.sink = phi ptr [ @.str.3, %5 ], [ @.str.1, %.sink.split.loopexit ], [ @.str.2, %2 ]
  br label %.sink.split3, !llvm.loop !9
}

declare void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef) local_unnamed_addr #1

declare void @_ZN6kernel4task5sleepEj(i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress noreturn 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 = { "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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass