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

; 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.Data = type { [6 x i32] }

@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [34 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

7:                                                ; preds = %17, %1
  br label %8

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

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

16:                                               ; preds = %8
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.12)
  call void @_ZN6kernel8hardware5debug13setBreakpointEv()
  br label %17

17:                                               ; preds = %16, %15
  call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef @.str.13)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 5, ptr %5, align 4, !tbaa !11
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Data, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [6 x i32], ptr %19, i64 0, i64 5
  call void @_ZN6kernel5event5resetERNS_6HandleE(ptr noundef nonnull align 4 dereferenceable(4) %20)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %7, !llvm.loop !13
}

declare noundef i32 @_ZN6kernel4sync22waitForMultipleObjectsEPNS_6HandleEjbbjPj(ptr noundef, i32 noundef, i1 noundef zeroext, i1 noundef zeroext, i32 noundef, ptr noundef) #1

declare void @_ZN6kernel8hardware5debug13setBreakpointEv() #1

declare void @_ZN6kernel5event5resetERNS_6HandleE(ptr noundef nonnull align 4 dereferenceable(4)) #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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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.9 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [34 x i8], align 1

declare void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress noreturn uwtable
define dso_local void @_Z11worker_taskPv(ptr noundef %0) local_unnamed_addr #1 {
  tail call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.9)
  %2 = getelementptr inbounds i8, ptr %0, i64 20
  br label %3

3:                                                ; preds = %8, %1
  tail call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.10)
  %4 = tail call noundef i32 @_ZN6kernel4sync22waitForMultipleObjectsEPNS_6HandleEjbbjPj(ptr noundef %0, i32 noundef 6, i1 noundef zeroext true, i1 noundef zeroext true, i32 noundef 0, ptr noundef null)
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %6, label %7

6:                                                ; preds = %3
  tail call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.11)
  br label %8

7:                                                ; preds = %3
  tail call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.12)
  tail call void @_ZN6kernel8hardware5debug13setBreakpointEv()
  br label %8

8:                                                ; preds = %7, %6
  tail call void @_ZN6kernel8hardware5debug5printEPKc(ptr noundef nonnull @.str.13)
  tail call void @_ZN6kernel5event5resetERNS_6HandleE(ptr noundef nonnull align 4 dereferenceable(4) %2)
  br label %3, !llvm.loop !5
}

declare noundef i32 @_ZN6kernel4sync22waitForMultipleObjectsEPNS_6HandleEjbbjPj(ptr noundef, i32 noundef, i1 noundef zeroext, i1 noundef zeroext, i32 noundef, ptr noundef) local_unnamed_addr #0

declare void @_ZN6kernel8hardware5debug13setBreakpointEv() local_unnamed_addr #0

declare void @_ZN6kernel5event5resetERNS_6HandleE(ptr noundef nonnull align 4 dereferenceable(4)) 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,LICMPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass