; LLVM IR from Softmotions/iowow :: src/utils (iwstw)

; 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 = type { ptr, ptr, ptr }
%struct.iwstw = type { ptr, ptr, ptr, ptr, %union.pthread_mutex_t, %union.pthread_cond_t, %union.pthread_cond_t, i64, i32, i32, i8, i8, i8 }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(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: nounwind
declare i32 @pthread_cond_broadcast(ptr noundef) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

declare i64 @iwrc_set_errno(i64 noundef, i32 noundef) #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

; Function Attrs: nounwind uwtable
define dso_local i64 @iwstw_schedule_empty_only(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #6 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %struct._task, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %22

16:                                               ; preds = %4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %19, %16, %4
  store i64 70017, ptr %5, align 8
  br label %92

23:                                               ; preds = %19
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  store i8 0, ptr %24, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  store i64 0, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %25 = call noalias ptr @malloc(i64 noundef 24) #8
  store ptr %25, ptr %11, align 8, !tbaa !5
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %32, label %28

28:                                               ; preds = %23
  %29 = call ptr @__errno_location() #9
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %30)
  store i64 %31, ptr %10, align 8, !tbaa !11
  br label %85

32:                                               ; preds = %23
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._task, ptr %12, i32 0, i32 0
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %35, ptr %34, align 8, !tbaa !15
  %36 = getelementptr inbounds %struct._task, ptr %12, i32 0, i32 1
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %37, ptr %36, align 8, !tbaa !17
  %38 = getelementptr inbounds %struct._task, ptr %12, i32 0, i32 2
  store ptr null, ptr %38, align 8, !tbaa !18
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %33, ptr align 8 %12, i64 24, i1 false), !tbaa.struct !19
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.iwstw, ptr %39, i32 0, i32 4
  %41 = call i32 @pthread_mutex_lock(ptr noundef %40) #7
  store i32 %41, ptr %13, align 4, !tbaa !13
  %42 = load i32, ptr %13, align 4, !tbaa !13
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %32
  %45 = call ptr @__errno_location() #9
  %46 = load i32, ptr %45, align 4, !tbaa !13
  %47 = call i64 @iwrc_set_errno(i64 noundef 70008, i32 noundef %46)
  store i64 %47, ptr %10, align 8, !tbaa !11
  br label %85

48:                                               ; preds = %32
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.iwstw, ptr %49, i32 0, i32 12
  %51 = load volatile i8, ptr %50, align 2, !tbaa !20, !range !22, !noundef !23
  %52 = trunc i8 %51 to i1
  br i1 %52, label %53, label %57

53:                                               ; preds = %48
  store i64 70014, ptr %10, align 8, !tbaa !11
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.iwstw, ptr %54, i32 0, i32 4
  %56 = call i32 @pthread_mutex_unlock(ptr noundef %55) #7
  br label %85

57:                                               ; preds = %48
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.iwstw, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !24
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %67

62:                                               ; preds = %57
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.iwstw, ptr %63, i32 0, i32 4
  %65 = call i32 @pthread_mutex_unlock(ptr noundef %64) #7
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  call void @free(ptr noundef %66) #7
  br label %85

67:                                               ; preds = %57
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  store i8 1, ptr %68, align 1, !tbaa !9
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.iwstw, ptr %70, i32 0, i32 0
  store ptr %69, ptr %71, align 8, !tbaa !24
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.iwstw, ptr %73, i32 0, i32 1
  store ptr %72, ptr %74, align 8, !tbaa !25
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.iwstw, ptr %75, i32 0, i32 8
  %77 = load i32, ptr %76, align 8, !tbaa !26
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %76, align 8, !tbaa !26
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.iwstw, ptr %79, i32 0, i32 5
  %81 = call i32 @pthread_cond_broadcast(ptr noundef %80) #7
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.iwstw, ptr %82, i32 0, i32 4
  %84 = call i32 @pthread_mutex_unlock(ptr noundef %83) #7
  br label %85

85:                                               ; preds = %67, %62, %53, %44, %28
  %86 = load i64, ptr %10, align 8, !tbaa !11
  %87 = icmp ne i64 %86, 0
  br i1 %87, label %88, label %90

88:                                               ; preds = %85
  %89 = load ptr, ptr %11, align 8, !tbaa !5
  call void @free(ptr noundef %89) #7
  br label %90

90:                                               ; preds = %88, %85
  %91 = load i64, ptr %10, align 8, !tbaa !11
  store i64 %91, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  br label %92

92:                                               ; preds = %90, %22
  %93 = load i64, ptr %5, align 8
  ret i64 %93
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind 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 = { "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 willreturn memory(none) "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { nounwind willreturn memory(none) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"_task", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!16, !6, i64 8}
!18 = !{!16, !6, i64 16}
!19 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 8, !5}
!20 = !{!21, !10, i64 186}
!21 = !{!"iwstw", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !7, i64 72, !7, i64 120, !12, i64 168, !14, i64 176, !14, i64 180, !10, i64 184, !10, i64 185, !10, i64 186}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!21, !6, i64 0}
!25 = !{!21, !6, i64 8}
!26 = !{!21, !14, i64 176}


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

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @pthread_cond_broadcast(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

declare i64 @iwrc_set_errno(i64 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local i64 @iwstw_schedule_empty_only(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef writeonly %3) local_unnamed_addr #5 {
  %5 = icmp ne ptr %0, null
  %6 = icmp ne ptr %1, null
  %or.cond = and i1 %5, %6
  %7 = icmp ne ptr %3, null
  %or.cond3 = and i1 %or.cond, %7
  br i1 %or.cond3, label %8, label %.thread

8:                                                ; preds = %4
  store i8 0, ptr %3, align 1, !tbaa !5
  %9 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #6
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %30, label %10

10:                                               ; preds = %8
  store ptr %1, ptr %9, align 8, !tbaa !9
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %9, i64 8
  store ptr %2, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !9
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %9, i64 16
  store ptr null, ptr %.sroa.3.0..sroa_idx, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  %12 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull %11) #7
  %.not34 = icmp eq i32 %12, 0
  br i1 %.not34, label %13, label %30

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %0, i64 186
  %15 = load volatile i8, ptr %14, align 2, !tbaa !11, !range !15, !noundef !16
  %16 = trunc nuw i8 %15 to i1
  br i1 %16, label %.thread39, label %18

.thread39:                                        ; preds = %13
  %17 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull %11) #7
  br label %34

18:                                               ; preds = %13
  %19 = load ptr, ptr %0, align 8, !tbaa !17
  %.not35 = icmp eq ptr %19, null
  br i1 %.not35, label %22, label %20

20:                                               ; preds = %18
  %21 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull %11) #7
  tail call void @free(ptr noundef nonnull %9) #7
  br label %.thread

22:                                               ; preds = %18
  store i8 1, ptr %3, align 1, !tbaa !5
  store ptr %9, ptr %0, align 8, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %9, ptr %23, align 8, !tbaa !18
  %24 = getelementptr inbounds i8, ptr %0, i64 176
  %25 = load i32, ptr %24, align 8, !tbaa !19
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %24, align 8, !tbaa !19
  %27 = getelementptr inbounds i8, ptr %0, i64 72
  %28 = tail call i32 @pthread_cond_broadcast(ptr noundef nonnull %27) #7
  %29 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull %11) #7
  br label %.thread

30:                                               ; preds = %10, %8
  %.sink = phi i64 [ 70013, %8 ], [ 70008, %10 ]
  %31 = tail call ptr @__errno_location() #8
  %32 = load i32, ptr %31, align 4, !tbaa !20
  %33 = tail call i64 @iwrc_set_errno(i64 noundef %.sink, i32 noundef %32) #7
  %.not36 = icmp eq i64 %33, 0
  br i1 %.not36, label %.thread, label %34

34:                                               ; preds = %.thread39, %30
  %.02942 = phi i64 [ 70014, %.thread39 ], [ %33, %30 ]
  tail call void @free(ptr noundef %9) #7
  br label %.thread

.thread:                                          ; preds = %22, %20, %30, %34, %4
  %.0 = phi i64 [ 70017, %4 ], [ %.02942, %34 ], [ 0, %30 ], [ 0, %20 ], [ 0, %22 ]
  ret i64 %.0
}

attributes #0 = { 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 nofree nosync nounwind willreturn memory(none) "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 = { 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 allocsize(0) }
attributes #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 186}
!12 = !{!"iwstw", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !7, i64 72, !7, i64 120, !13, i64 168, !14, i64 176, !14, i64 180, !6, i64 184, !6, i64 185, !6, i64 186}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!12, !10, i64 0}
!18 = !{!12, !10, i64 8}
!19 = !{!12, !14, i64 176}
!20 = !{!14, !14, i64 0}


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