; LLVM IR from vczh/herodb :: Kernel/Source/Vlpp.ll (ZN2vl9Semaphore4OpenEbRKNS_12ObjectStringIwEE)

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

%"class.vl::ObjectString.1123" = type { %"class.vl::Object", ptr, ptr, i64, i64, i64 }
%"class.vl::Object" = type { ptr }
%"class.vl::Semaphore" = type { %"class.vl::WaitableObject", ptr }
%"class.vl::WaitableObject" = type { %"class.vl::Object" }
%"struct.vl::threading_internal::SemaphoreData" = type { %union.sem_t, ptr }
%union.sem_t = type { i64, [24 x i8] }

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 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 i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl4wtoaERKNS_12ObjectStringIwEE(ptr dead_on_unwind noalias writable sret(%"class.vl::ObjectString.1123") align 8, ptr noundef nonnull align 8 dereferenceable(48)) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK2vl12ObjectStringIcE6BufferEv(ptr noundef nonnull align 8 dereferenceable(48)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2vl12ObjectStringIcED2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2vl9Semaphore4OpenEbRKNS_12ObjectStringIwEE(ptr noundef nonnull align 8 dereferenceable(16) %0, i1 noundef zeroext %1, ptr noundef nonnull align 8 dereferenceable(48) %2) #3 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca %"class.vl::ObjectString.1123", align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  %11 = zext i1 %1 to i8
  store i8 %11, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  %13 = getelementptr inbounds %"class.vl::Semaphore", ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  br label %45

17:                                               ; preds = %3
  %18 = load i8, ptr %6, align 1, !tbaa !9, !range !15, !noundef !16
  %19 = trunc i8 %18 to i1
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  store i1 false, ptr %4, align 1
  br label %45

21:                                               ; preds = %17
  %22 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 40) #7
  call void @_ZN2vl18threading_internal13SemaphoreDataC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %22) #8
  %23 = getelementptr inbounds %"class.vl::Semaphore", ptr %12, i32 0, i32 1
  store ptr %22, ptr %23, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 48, ptr %8) #8
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN2vl4wtoaERKNS_12ObjectStringIwEE(ptr dead_on_unwind writable sret(%"class.vl::ObjectString.1123") align 8 %8, ptr noundef nonnull align 8 dereferenceable(48) %24)
  %25 = invoke noundef ptr @_ZNK2vl12ObjectStringIcE6BufferEv(ptr noundef nonnull align 8 dereferenceable(48) %8)
          to label %26 unwind label %40

26:                                               ; preds = %21
  %27 = call ptr (ptr, i32, ...) @sem_open(ptr noundef %25, i32 noundef 0) #8
  %28 = getelementptr inbounds %"class.vl::Semaphore", ptr %12, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = getelementptr inbounds %"struct.vl::threading_internal::SemaphoreData", ptr %29, i32 0, i32 1
  store ptr %27, ptr %30, align 8, !tbaa !17
  %31 = icmp ne ptr %27, null
  %32 = xor i1 %31, true
  call void @_ZN2vl12ObjectStringIcED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %8) #8
  call void @llvm.lifetime.end.p0(i64 48, ptr %8) #8
  br i1 %32, label %33, label %44

33:                                               ; preds = %26
  %34 = getelementptr inbounds %"class.vl::Semaphore", ptr %12, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = icmp eq ptr %35, null
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  call void @_ZdlPvm(ptr noundef %35, i64 noundef 40) #9
  br label %38

38:                                               ; preds = %37, %33
  %39 = getelementptr inbounds %"class.vl::Semaphore", ptr %12, i32 0, i32 1
  store ptr null, ptr %39, align 8, !tbaa !11
  store i1 false, ptr %4, align 1
  br label %45

40:                                               ; preds = %21
  %41 = landingpad { ptr, i32 }
          cleanup
  %42 = extractvalue { ptr, i32 } %41, 0
  store ptr %42, ptr %9, align 8
  %43 = extractvalue { ptr, i32 } %41, 1
  store i32 %43, ptr %10, align 4
  call void @_ZN2vl12ObjectStringIcED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %8) #8
  call void @llvm.lifetime.end.p0(i64 48, ptr %8) #8
  br label %47

44:                                               ; preds = %26
  store i1 true, ptr %4, align 1
  br label %45

45:                                               ; preds = %44, %38, %20, %16
  %46 = load i1, ptr %4, align 1
  ret i1 %46

47:                                               ; preds = %40
  %48 = load ptr, ptr %9, align 8
  %49 = load i32, ptr %10, align 4
  %50 = insertvalue { ptr, i32 } poison, ptr %48, 0
  %51 = insertvalue { ptr, i32 } %50, i32 %49, 1
  resume { ptr, i32 } %51
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN2vl18threading_internal13SemaphoreDataC2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #5 align 2

; Function Attrs: nounwind
declare ptr @sem_open(ptr noundef, i32 noundef, ...) #6

attributes #0 = { nobuiltin nounwind "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 = { nobuiltin allocsize(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 = { 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 = { 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 #5 = { inlinehint 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 #6 = { nounwind "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 #7 = { builtin allocsize(0) }
attributes #8 = { nounwind }
attributes #9 = { builtin 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 = !{!"bool", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTSN2vl9SemaphoreE", !13, i64 0, !6, i64 8}
!13 = !{!"_ZTSN2vl14WaitableObjectE", !14, i64 0}
!14 = !{!"_ZTSN2vl6ObjectE"}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !6, i64 32}
!18 = !{!"_ZTSN2vl18threading_internal13SemaphoreDataE", !7, i64 0, !6, i64 32}


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

%"class.vl::ObjectString.1123" = type { %"class.vl::Object", ptr, ptr, i64, i64, i64 }
%"class.vl::Object" = type { ptr }

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 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 i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2vl4wtoaERKNS_12ObjectStringIwEE(ptr dead_on_unwind noalias writable sret(%"class.vl::ObjectString.1123") align 8, ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK2vl12ObjectStringIcE6BufferEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2vl12ObjectStringIcED2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2vl9Semaphore4OpenEbRKNS_12ObjectStringIwEE(ptr nocapture noundef nonnull align 8 dereferenceable(16) %0, i1 noundef zeroext %1, ptr noundef nonnull align 8 dereferenceable(48) %2) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca %"class.vl::ObjectString.1123", align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp ne ptr %6, null
  %brmerge = or i1 %.not, %1
  br i1 %brmerge, label %21, label %7

7:                                                ; preds = %3
  %8 = tail call noalias noundef nonnull dereferenceable(40) ptr @_Znwm(i64 noundef 40) #7
  tail call void @_ZN2vl18threading_internal13SemaphoreDataC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %8) #8
  store ptr %8, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %4) #8
  call void @_ZN2vl4wtoaERKNS_12ObjectStringIwEE(ptr dead_on_unwind nonnull writable sret(%"class.vl::ObjectString.1123") align 8 %4, ptr noundef nonnull align 8 dereferenceable(48) %2)
  %9 = invoke noundef ptr @_ZNK2vl12ObjectStringIcE6BufferEv(ptr noundef nonnull align 8 dereferenceable(48) %4)
          to label %10 unwind label %19

10:                                               ; preds = %7
  %11 = call ptr (ptr, i32, ...) @sem_open(ptr noundef %9, i32 noundef 0) #8
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 32
  store ptr %11, ptr %13, align 8, !tbaa !12
  %.not6 = icmp eq ptr %11, null
  call void @_ZN2vl12ObjectStringIcED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %4) #8
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #8
  br i1 %.not6, label %14, label %21

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

17:                                               ; preds = %14
  call void @_ZdlPvm(ptr noundef nonnull %15, i64 noundef 40) #9
  br label %18

18:                                               ; preds = %17, %14
  store ptr null, ptr %5, align 8, !tbaa !5
  br label %21

19:                                               ; preds = %7
  %20 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN2vl12ObjectStringIcED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %4) #8
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #8
  resume { ptr, i32 } %20

21:                                               ; preds = %3, %10, %18
  %.0 = phi i1 [ false, %18 ], [ false, %3 ], [ true, %10 ]
  ret i1 %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN2vl18threading_internal13SemaphoreDataC2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #5 align 2

; Function Attrs: nounwind
declare ptr @sem_open(ptr noundef, i32 noundef, ...) local_unnamed_addr #6

attributes #0 = { nobuiltin nounwind "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 = { nobuiltin allocsize(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 = { 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 = { 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 #5 = { inlinehint 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 #6 = { nounwind "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 #7 = { builtin allocsize(0) }
attributes #8 = { nounwind }
attributes #9 = { builtin 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, !9, i64 8}
!6 = !{!"_ZTSN2vl9SemaphoreE", !7, i64 0, !9, i64 8}
!7 = !{!"_ZTSN2vl14WaitableObjectE", !8, i64 0}
!8 = !{!"_ZTSN2vl6ObjectE"}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!13, !9, i64 32}
!13 = !{!"_ZTSN2vl18threading_internal13SemaphoreDataE", !10, i64 0, !9, i64 32}


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