; LLVM IR from BurntSushi/clibs :: libds (queue)

; 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.DSQueue = type { ptr, i32, i32, i32, i8, %union.pthread_mutex_t, %union.pthread_cond_t }
%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 }

@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__.ds_queue_put = external hidden unnamed_addr constant [44 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [32 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @ds_queue_put(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.DSQueue, ptr %5, i32 0, i32 5
  %7 = call i32 @pthread_mutex_lock(ptr noundef %6) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.DSQueue, ptr %8, i32 0, i32 4
  %10 = load i8, ptr %9, align 4, !tbaa !9, !range !13, !noundef !14
  %11 = trunc i8 %10 to i1
  br i1 %11, label %13, label %12

12:                                               ; preds = %2
  br label %14

13:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 116, ptr noundef @__PRETTY_FUNCTION__.ds_queue_put) #5
  unreachable

14:                                               ; preds = %12
  br label %15

15:                                               ; preds = %23, %14
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.DSQueue, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 4, !tbaa !15
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.DSQueue, ptr %19, i32 0, i32 3
  %21 = load i32, ptr %20, align 8, !tbaa !16
  %22 = icmp eq i32 %18, %21
  br i1 %22, label %23, label %29

23:                                               ; preds = %15
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.DSQueue, ptr %24, i32 0, i32 6
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.DSQueue, ptr %26, i32 0, i32 5
  %28 = call i32 @pthread_cond_wait(ptr noundef %25, ptr noundef %27)
  br label %15, !llvm.loop !17

29:                                               ; preds = %15
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.DSQueue, ptr %30, i32 0, i32 4
  %32 = load i8, ptr %31, align 4, !tbaa !9, !range !13, !noundef !14
  %33 = trunc i8 %32 to i1
  br i1 %33, label %35, label %34

34:                                               ; preds = %29
  br label %36

35:                                               ; preds = %29
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 121, ptr noundef @__PRETTY_FUNCTION__.ds_queue_put) #5
  unreachable

36:                                               ; preds = %34
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.DSQueue, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !15
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.DSQueue, ptr %40, i32 0, i32 3
  %42 = load i32, ptr %41, align 8, !tbaa !16
  %43 = icmp ult i32 %39, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %36
  br label %46

45:                                               ; preds = %36
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.1, i32 noundef 122, ptr noundef @__PRETTY_FUNCTION__.ds_queue_put) #5
  unreachable

46:                                               ; preds = %44
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.DSQueue, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !19
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.DSQueue, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 8, !tbaa !20
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.DSQueue, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 4, !tbaa !15
  %57 = add i32 %53, %56
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.DSQueue, ptr %58, i32 0, i32 3
  %60 = load i32, ptr %59, align 8, !tbaa !16
  %61 = urem i32 %57, %60
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds ptr, ptr %50, i64 %62
  store ptr %47, ptr %63, align 8, !tbaa !5
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.DSQueue, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 4, !tbaa !15
  %67 = add i32 %66, 1
  store i32 %67, ptr %65, align 4, !tbaa !15
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.DSQueue, ptr %68, i32 0, i32 6
  %70 = call i32 @pthread_cond_broadcast(ptr noundef %69) #4
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.DSQueue, ptr %71, i32 0, i32 5
  %73 = call i32 @pthread_mutex_unlock(ptr noundef %72) #4
  ret void
}

declare i32 @pthread_cond_wait(ptr noundef, ptr noundef) #3

attributes #0 = { noreturn 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 = { 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 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 = { "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 }
attributes #5 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !12, i64 20}
!10 = !{!"DSQueue", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !12, i64 20, !7, i64 24, !7, i64 64}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!10, !11, i64 12}
!16 = !{!10, !11, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!10, !6, i64 0}
!20 = !{!10, !11, i64 8}


; 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.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__.ds_queue_put = external hidden unnamed_addr constant [44 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ds_queue_put(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull %3) #4
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  %6 = load i8, ptr %5, align 4, !tbaa !5, !range !12, !noundef !13
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %14, label %.preheader

.preheader:                                       ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load i32, ptr %8, align 4, !tbaa !14
  %11 = load i32, ptr %9, align 8, !tbaa !15
  %12 = icmp eq i32 %10, %11
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %13 = getelementptr inbounds i8, ptr %0, i64 64
  br label %15

14:                                               ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 116, ptr noundef nonnull @__PRETTY_FUNCTION__.ds_queue_put) #5
  unreachable

15:                                               ; preds = %.lr.ph, %15
  %16 = tail call i32 @pthread_cond_wait(ptr noundef nonnull %13, ptr noundef nonnull %3) #4
  %17 = load i32, ptr %8, align 4, !tbaa !14
  %18 = load i32, ptr %9, align 8, !tbaa !15
  %19 = icmp eq i32 %17, %18
  br i1 %19, label %15, label %._crit_edge.loopexit, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %15
  %.pre = load i8, ptr %5, align 4, !tbaa !5, !range !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %20 = phi i8 [ %6, %.preheader ], [ %.pre, %._crit_edge.loopexit ]
  %.lcssa18 = phi i32 [ %10, %.preheader ], [ %17, %._crit_edge.loopexit ]
  %.lcssa = phi i32 [ %11, %.preheader ], [ %18, %._crit_edge.loopexit ]
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %22, label %23

22:                                               ; preds = %._crit_edge
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 121, ptr noundef nonnull @__PRETTY_FUNCTION__.ds_queue_put) #5
  unreachable

23:                                               ; preds = %._crit_edge
  %24 = icmp ult i32 %.lcssa18, %.lcssa
  br i1 %24, label %26, label %25

25:                                               ; preds = %23
  tail call void @__assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.1, i32 noundef 122, ptr noundef nonnull @__PRETTY_FUNCTION__.ds_queue_put) #5
  unreachable

26:                                               ; preds = %23
  %27 = load ptr, ptr %0, align 8, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  %29 = load i32, ptr %28, align 8, !tbaa !19
  %30 = add i32 %29, %.lcssa18
  %31 = urem i32 %30, %.lcssa
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds ptr, ptr %27, i64 %32
  store ptr %1, ptr %33, align 8, !tbaa !20
  %34 = add nuw i32 %.lcssa18, 1
  store i32 %34, ptr %8, align 4, !tbaa !14
  %35 = getelementptr inbounds i8, ptr %0, i64 64
  %36 = tail call i32 @pthread_cond_broadcast(ptr noundef nonnull %35) #4
  %37 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull %3) #4
  ret void
}

declare i32 @pthread_cond_wait(ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { noreturn 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 = { 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 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 = { "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 }
attributes #5 = { noreturn 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, !11, i64 20}
!6 = !{!"DSQueue", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !11, i64 20, !8, i64 24, !8, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!6, !10, i64 12}
!15 = !{!6, !10, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !7, i64 0}
!19 = !{!6, !10, i64 8}
!20 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass