; LLVM IR from t4th/cortex-m3-rtos :: examples/waitForSingleObject/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.Events = type { i32 }

@.str.6 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [26 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

declare void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef) #1

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

6:                                                ; preds = %15, %1
  br label %7

7:                                                ; preds = %6
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.7)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.Events, ptr %8, i32 0, i32 0
  %10 = call noundef i32 @_ZN6kernel4sync19waitForSingleObjectERNS_6HandleEbj(ptr noundef nonnull align 4 dereferenceable(4) %9, i1 noundef zeroext true, i32 noundef 0)
  store i32 %10, ptr %4, align 4, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = icmp eq i32 0, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %7
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.8)
  br label %15

14:                                               ; preds = %7
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.9)
  br label %15

15:                                               ; preds = %14, %13
  call void @_ZN6kernel4task5sleepEj(i32 noundef 100)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %6, !llvm.loop !11
}

declare void @_ZN6kernel4task5sleepEj(i32 noundef) #1

declare noundef i32 @_ZN6kernel4sync19waitForSingleObjectERNS_6HandleEbj(ptr noundef nonnull align 4 dereferenceable(4), i1 noundef zeroext, i32 noundef) #1

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

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 = { 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 #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 = !{!"_ZTSN6kernel4sync10WaitResultE", !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.6 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [26 x i8], align 1

declare void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress noreturn uwtable
define dso_local void @_Z5task1Pv(ptr noundef %0) local_unnamed_addr #1 {
  tail call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.6)
  br label %2

2:                                                ; preds = %2, %1
  tail call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.7)
  %3 = tail call noundef i32 @_ZN6kernel4sync19waitForSingleObjectERNS_6HandleEbj(ptr noundef nonnull align 4 dereferenceable(4) %0, i1 noundef zeroext true, i32 noundef 0)
  %4 = icmp eq i32 %3, 0
  %.str.8..str.9 = select i1 %4, ptr @.str.8, ptr @.str.9
  tail call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull %.str.8..str.9)
  tail call void @_ZN6kernel4task5sleepEj(i32 noundef 100)
  br label %2, !llvm.loop !5
}

declare void @_ZN6kernel4task5sleepEj(i32 noundef) local_unnamed_addr #0

declare noundef i32 @_ZN6kernel4sync19waitForSingleObjectERNS_6HandleEbj(ptr noundef nonnull align 4 dereferenceable(4), i1 noundef zeroext, i32 noundef) 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 = { 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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