; LLVM IR from kaynewbie/algorithm :: algorithm/LeetCode/libs (queue_internal)

; 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.queue_s = type { ptr, ptr, i16, i16, i8, i8, i8, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @queue_lock_internal(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @queue_unlock_internal(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local signext i8 @queue_destroy_internal(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !10
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call signext i8 @queue_set_new_data(ptr noundef %8, i8 noundef zeroext 0)
  %10 = sext i8 %9 to i32
  store i32 %10, ptr %7, align 4, !tbaa !10
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call signext i8 @queue_lock_internal(ptr noundef %11)
  %13 = sext i8 %12 to i32
  store i32 %13, ptr %7, align 4, !tbaa !10
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i8, ptr %5, align 1, !tbaa !9
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = call signext i8 @queue_flush_internal(ptr noundef %14, i8 noundef zeroext %15, ptr noundef %16)
  %18 = sext i8 %17 to i32
  store i32 %18, ptr %7, align 4, !tbaa !10
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.queue_s, ptr %19, i32 0, i32 9
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = call i32 @pthread_cond_destroy(ptr noundef %21) #4
  store i32 %22, ptr %7, align 4, !tbaa !10
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.queue_s, ptr %23, i32 0, i32 9
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  call void @free(ptr noundef %25) #4
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.queue_s, ptr %26, i32 0, i32 10
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = call i32 @pthread_cond_destroy(ptr noundef %28) #4
  store i32 %29, ptr %7, align 4, !tbaa !10
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.queue_s, ptr %30, i32 0, i32 10
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  call void @free(ptr noundef %32) #4
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = call signext i8 @queue_unlock_internal(ptr noundef %33)
  %35 = sext i8 %34 to i32
  store i32 %35, ptr %7, align 4, !tbaa !10
  br label %36

36:                                               ; preds = %42, %3
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.queue_s, ptr %37, i32 0, i32 8
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  %40 = call i32 @pthread_mutex_destroy(ptr noundef %39) #4
  store i32 %40, ptr %7, align 4, !tbaa !10
  %41 = icmp eq i32 16, %40
  br i1 %41, label %42, label %44

42:                                               ; preds = %36
  %43 = call i32 @usleep(i32 noundef 100000)
  br label %36, !llvm.loop !17

44:                                               ; preds = %36
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.queue_s, ptr %45, i32 0, i32 8
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  call void @free(ptr noundef %47) #4
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %48) #4
  %49 = load i32, ptr %7, align 4, !tbaa !10
  %50 = trunc i32 %49 to i8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i8 %50
}

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

declare signext i8 @queue_set_new_data(ptr noundef, i8 noundef zeroext) #2

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @queue_flush_internal(ptr noundef, i8 noundef zeroext, ptr noundef) #0

; Function Attrs: nounwind
declare i32 @pthread_cond_destroy(ptr noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind
declare i32 @pthread_mutex_destroy(ptr noundef) #3

declare i32 @usleep(i32 noundef) #2

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

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

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 40}
!13 = !{!"queue_s", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 18, !7, i64 20, !7, i64 21, !7, i64 22, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !6, i64 48}
!16 = !{!13, !6, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @queue_lock_internal(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @queue_unlock_internal(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local signext i8 @queue_destroy_internal(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call signext i8 @queue_set_new_data(ptr noundef %0, i8 noundef zeroext 0) #4
  %5 = tail call signext i8 @queue_lock_internal(ptr noundef %0)
  %6 = tail call signext i8 @queue_flush_internal(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2)
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = tail call i32 @pthread_cond_destroy(ptr noundef %8) #4
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  tail call void @free(ptr noundef %10) #4
  %11 = getelementptr inbounds i8, ptr %0, i64 48
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = tail call i32 @pthread_cond_destroy(ptr noundef %12) #4
  %14 = load ptr, ptr %11, align 8, !tbaa !11
  tail call void @free(ptr noundef %14) #4
  %15 = tail call signext i8 @queue_unlock_internal(ptr noundef %0)
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = tail call i32 @pthread_mutex_destroy(ptr noundef %17) #4
  %19 = icmp eq i32 %18, 16
  br i1 %19, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %20 = tail call i32 @usleep(i32 noundef 100000) #4
  %21 = load ptr, ptr %16, align 8, !tbaa !12
  %22 = tail call i32 @pthread_mutex_destroy(ptr noundef %21) #4
  %23 = icmp eq i32 %22, 16
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.lcssa = phi i32 [ %18, %3 ], [ %22, %.lr.ph ]
  %24 = load ptr, ptr %16, align 8, !tbaa !12
  tail call void @free(ptr noundef %24) #4
  tail call void @free(ptr noundef nonnull %0) #4
  %25 = trunc i32 %.lcssa to i8
  ret i8 %25
}

declare signext i8 @queue_set_new_data(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @queue_flush_internal(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare i32 @pthread_cond_destroy(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_destroy(ptr noundef) local_unnamed_addr #2

declare i32 @usleep(i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { 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 #3 = { 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 #4 = { 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, !7, i64 40}
!6 = !{!"queue_s", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 18, !8, i64 20, !8, i64 21, !8, i64 22, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !7, i64 48}
!12 = !{!6, !7, i64 32}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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