; LLVM IR from erwincoumans/tiny-differentiable-simulator :: third_party/zeromq/src/fq.ll (ZN3zmq4fq_t6has_inEv)

; 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.zmq::fq_t" = type <{ %"class.zmq::array_t", i64, ptr, i64, i8, [7 x i8] }>
%"class.zmq::array_t" = type { %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<zmq::pipe_t *, std::allocator<zmq::pipe_t *>>::_Vector_impl" }
%"struct.std::_Vector_base<zmq::pipe_t *, std::allocator<zmq::pipe_t *>>::_Vector_impl" = type { %"struct.std::_Vector_base<zmq::pipe_t *, std::allocator<zmq::pipe_t *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<zmq::pipe_t *, std::allocator<zmq::pipe_t *>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3zmq7array_tINS_6pipe_tELi1EE4swapEmm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, i64 noundef) #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN3zmq7array_tINS_6pipe_tELi1EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3zmq4fq_t6has_inEv(ptr noundef nonnull align 8 dereferenceable(49) %0) #1 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8
  %5 = getelementptr inbounds %"class.zmq::fq_t", ptr %4, i32 0, i32 4
  %6 = load i8, ptr %5, align 8, !tbaa !9, !range !18, !noundef !19
  %7 = trunc i8 %6 to i1
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i1 true, ptr %2, align 1
  br label %40

9:                                                ; preds = %1
  br label %10

10:                                               ; preds = %38, %9
  %11 = getelementptr inbounds %"class.zmq::fq_t", ptr %4, i32 0, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !20
  %13 = icmp ugt i64 %12, 0
  br i1 %13, label %14, label %39

14:                                               ; preds = %10
  %15 = getelementptr inbounds %"class.zmq::fq_t", ptr %4, i32 0, i32 0
  %16 = getelementptr inbounds %"class.zmq::fq_t", ptr %4, i32 0, i32 3
  %17 = load i64, ptr %16, align 8, !tbaa !21
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN3zmq7array_tINS_6pipe_tELi1EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %15, i64 noundef %17)
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = call noundef zeroext i1 @_ZN3zmq6pipe_t10check_readEv(ptr noundef nonnull align 8 dereferenceable(264) %19)
  br i1 %20, label %21, label %22

21:                                               ; preds = %14
  store i1 true, ptr %2, align 1
  br label %40

22:                                               ; preds = %14
  %23 = getelementptr inbounds %"class.zmq::fq_t", ptr %4, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !20
  %25 = add i64 %24, -1
  store i64 %25, ptr %23, align 8, !tbaa !20
  %26 = getelementptr inbounds %"class.zmq::fq_t", ptr %4, i32 0, i32 0
  %27 = getelementptr inbounds %"class.zmq::fq_t", ptr %4, i32 0, i32 3
  %28 = load i64, ptr %27, align 8, !tbaa !21
  %29 = getelementptr inbounds %"class.zmq::fq_t", ptr %4, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !20
  call void @_ZN3zmq7array_tINS_6pipe_tELi1EE4swapEmm(ptr noundef nonnull align 8 dereferenceable(24) %26, i64 noundef %28, i64 noundef %30)
  %31 = getelementptr inbounds %"class.zmq::fq_t", ptr %4, i32 0, i32 3
  %32 = load i64, ptr %31, align 8, !tbaa !21
  %33 = getelementptr inbounds %"class.zmq::fq_t", ptr %4, i32 0, i32 1
  %34 = load i64, ptr %33, align 8, !tbaa !20
  %35 = icmp eq i64 %32, %34
  br i1 %35, label %36, label %38

36:                                               ; preds = %22
  %37 = getelementptr inbounds %"class.zmq::fq_t", ptr %4, i32 0, i32 3
  store i64 0, ptr %37, align 8, !tbaa !21
  br label %38

38:                                               ; preds = %36, %22
  br label %10, !llvm.loop !22

39:                                               ; preds = %10
  store i1 false, ptr %2, align 1
  br label %40

40:                                               ; preds = %39, %21, %8
  %41 = load i1, ptr %2, align 1
  ret i1 %41
}

declare noundef zeroext i1 @_ZN3zmq6pipe_t10check_readEv(ptr noundef nonnull align 8 dereferenceable(264)) #2

attributes #0 = { 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 #1 = { 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 #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" }

!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, !17, i64 48}
!10 = !{!"_ZTSN3zmq4fq_tE", !11, i64 0, !16, i64 24, !6, i64 32, !16, i64 40, !17, i64 48}
!11 = !{!"_ZTSN3zmq7array_tINS_6pipe_tELi1EEE", !12, i64 0}
!12 = !{!"_ZTSSt6vectorIPN3zmq6pipe_tESaIS2_EE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseIPN3zmq6pipe_tESaIS2_EE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIPN3zmq6pipe_tESaIS2_EE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIPN3zmq6pipe_tESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!"long", !7, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!10, !16, i64 24}
!21 = !{!10, !16, i64 40}
!22 = distinct !{!22, !23}
!23 = !{!"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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3zmq7array_tINS_6pipe_tELi1EE4swapEmm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN3zmq7array_tINS_6pipe_tELi1EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3zmq4fq_t6has_inEv(ptr noundef nonnull align 8 dereferenceable(49) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 48
  %3 = load i8, ptr %2, align 8, !tbaa !5, !range !17, !noundef !18
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i64, ptr %5, align 8, !tbaa !19
  %.not2 = icmp eq i64 %6, 0
  br i1 %.not2, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %.pre = load i64, ptr %7, align 8, !tbaa !20
  br label %8

8:                                                ; preds = %.lr.ph, %21
  %9 = phi i64 [ %.pre, %.lr.ph ], [ %22, %21 ]
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN3zmq7array_tINS_6pipe_tELi1EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %9)
  %11 = load ptr, ptr %10, align 8, !tbaa !21
  %12 = tail call noundef zeroext i1 @_ZN3zmq6pipe_t10check_readEv(ptr noundef nonnull align 8 dereferenceable(264) %11)
  br i1 %12, label %.loopexit, label %13

13:                                               ; preds = %8
  %14 = load i64, ptr %5, align 8, !tbaa !19
  %15 = add i64 %14, -1
  store i64 %15, ptr %5, align 8, !tbaa !19
  %16 = load i64, ptr %7, align 8, !tbaa !20
  tail call void @_ZN3zmq7array_tINS_6pipe_tELi1EE4swapEmm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %16, i64 noundef %15)
  %17 = load i64, ptr %7, align 8, !tbaa !20
  %18 = load i64, ptr %5, align 8, !tbaa !19
  %19 = icmp eq i64 %17, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %13
  store i64 0, ptr %7, align 8, !tbaa !20
  br label %21

21:                                               ; preds = %20, %13
  %22 = phi i64 [ 0, %20 ], [ %17, %13 ]
  %.not = icmp eq i64 %18, 0
  br i1 %.not, label %.loopexit, label %8, !llvm.loop !22

.loopexit:                                        ; preds = %8, %21, %.preheader, %1
  %.0 = phi i1 [ true, %1 ], [ false, %.preheader ], [ %12, %21 ], [ %12, %8 ]
  ret i1 %.0
}

declare noundef zeroext i1 @_ZN3zmq6pipe_t10check_readEv(ptr noundef nonnull align 8 dereferenceable(264)) local_unnamed_addr #2

attributes #0 = { 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 #1 = { 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 #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" }

!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, !16, i64 48}
!6 = !{!"_ZTSN3zmq4fq_tE", !7, i64 0, !15, i64 24, !12, i64 32, !15, i64 40, !16, i64 48}
!7 = !{!"_ZTSN3zmq7array_tINS_6pipe_tELi1EEE", !8, i64 0}
!8 = !{!"_ZTSSt6vectorIPN3zmq6pipe_tESaIS2_EE", !9, i64 0}
!9 = !{!"_ZTSSt12_Vector_baseIPN3zmq6pipe_tESaIS2_EE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseIPN3zmq6pipe_tESaIS2_EE12_Vector_implE", !11, i64 0}
!11 = !{!"_ZTSNSt12_Vector_baseIPN3zmq6pipe_tESaIS2_EE17_Vector_impl_dataE", !12, i64 0, !12, i64 8, !12, i64 16}
!12 = !{!"any pointer", !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C++ TBAA"}
!15 = !{!"long", !13, i64 0}
!16 = !{!"bool", !13, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!6, !15, i64 24}
!20 = !{!6, !15, i64 40}
!21 = !{!12, !12, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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