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

; 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::msg_t" = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { ptr, [34 x i8], i8, i8, [16 x i8], i32 }
%"class.zmq::pipe_t" = type { %"class.zmq::object_t.base", [4 x i8], %"class.zmq::array_item_t.base", [4 x i8], %"class.zmq::array_item_t.base.9", [4 x i8], %"class.zmq::array_item_t.base.11", ptr, ptr, i8, i8, i32, i32, i32, i32, i64, i64, i64, ptr, ptr, i32, i8, [3 x i8], %"struct.zmq::blob_t", i32, i8, [3 x i8], %"struct.zmq::endpoint_uri_pair_t" }
%"class.zmq::object_t.base" = type <{ ptr, ptr, i32 }>
%"class.zmq::array_item_t.base" = type <{ ptr, i32 }>
%"class.zmq::array_item_t.base.9" = type <{ ptr, i32 }>
%"class.zmq::array_item_t.base.11" = type <{ ptr, i32 }>
%"struct.zmq::blob_t" = type <{ ptr, i64, i8, [7 x i8] }>
%"struct.zmq::endpoint_uri_pair_t" = type <{ %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", i32, [4 x i8] }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon.12 }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon.12 = type { i64, [8 x i8] }

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [108 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

declare i32 @fflush(ptr noundef) #3

declare void @_ZN3zmq9zmq_abortEPKc(ptr noundef) #3

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3zmq6pipe_t10check_readEv(ptr noundef nonnull align 8 dereferenceable(264) %0) #4 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca %"class.zmq::msg_t", align 8
  %5 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.zmq::pipe_t", ptr %6, i32 0, i32 9
  %8 = load i8, ptr %7, align 8, !tbaa !9, !range !24, !noundef !25
  %9 = trunc i8 %8 to i1
  %10 = xor i1 %9, true
  %11 = zext i1 %10 to i64
  %12 = call i64 @llvm.expect.i64(i64 %11, i64 0)
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %69

15:                                               ; preds = %1
  %16 = getelementptr inbounds %"class.zmq::pipe_t", ptr %6, i32 0, i32 20
  %17 = load i32, ptr %16, align 8, !tbaa !26
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %23

19:                                               ; preds = %15
  %20 = getelementptr inbounds %"class.zmq::pipe_t", ptr %6, i32 0, i32 20
  %21 = load i32, ptr %20, align 8, !tbaa !26
  %22 = icmp ne i32 %21, 2
  br label %23

23:                                               ; preds = %19, %15
  %24 = phi i1 [ false, %15 ], [ %22, %19 ]
  %25 = zext i1 %24 to i64
  %26 = call i64 @llvm.expect.i64(i64 %25, i64 0)
  %27 = icmp ne i64 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i1 false, ptr %2, align 1
  br label %69

29:                                               ; preds = %23
  %30 = getelementptr inbounds %"class.zmq::pipe_t", ptr %6, i32 0, i32 7
  %31 = load ptr, ptr %30, align 8, !tbaa !27
  %32 = load ptr, ptr %31, align 8, !tbaa !28
  %33 = getelementptr inbounds ptr, ptr %32, i64 5
  %34 = load ptr, ptr %33, align 8
  %35 = call noundef zeroext i1 %34(ptr noundef nonnull align 8 dereferenceable(8) %31)
  br i1 %35, label %38, label %36

36:                                               ; preds = %29
  %37 = getelementptr inbounds %"class.zmq::pipe_t", ptr %6, i32 0, i32 9
  store i8 0, ptr %37, align 8, !tbaa !9
  store i1 false, ptr %2, align 1
  br label %69

38:                                               ; preds = %29
  %39 = getelementptr inbounds %"class.zmq::pipe_t", ptr %6, i32 0, i32 7
  %40 = load ptr, ptr %39, align 8, !tbaa !27
  %41 = load ptr, ptr %40, align 8, !tbaa !28
  %42 = getelementptr inbounds ptr, ptr %41, i64 7
  %43 = load ptr, ptr %42, align 8
  %44 = call noundef zeroext i1 %43(ptr noundef nonnull align 8 dereferenceable(8) %40, ptr noundef @_ZN3zmq6pipe_t12is_delimiterERKNS_5msg_tE)
  br i1 %44, label %45, label %68

45:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 64, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #5
  %46 = getelementptr inbounds %"class.zmq::pipe_t", ptr %6, i32 0, i32 7
  %47 = load ptr, ptr %46, align 8, !tbaa !27
  %48 = load ptr, ptr %47, align 8, !tbaa !28
  %49 = getelementptr inbounds ptr, ptr %48, i64 6
  %50 = load ptr, ptr %49, align 8
  %51 = call noundef zeroext i1 %50(ptr noundef nonnull align 8 dereferenceable(8) %47, ptr noundef %4)
  %52 = zext i1 %51 to i8
  store i8 %52, ptr %5, align 1, !tbaa !30
  br label %53

53:                                               ; preds = %45
  %54 = load i8, ptr %5, align 1, !tbaa !30, !range !24, !noundef !25
  %55 = trunc i8 %54 to i1
  %56 = xor i1 %55, true
  %57 = zext i1 %56 to i64
  %58 = call i64 @llvm.expect.i64(i64 %57, i64 0)
  %59 = icmp ne i64 %58, 0
  br i1 %59, label %60, label %65

60:                                               ; preds = %53
  %61 = load ptr, ptr @stderr, align 8, !tbaa !5
  %62 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef @.str.4, ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 176) #5
  %63 = load ptr, ptr @stderr, align 8, !tbaa !5
  %64 = call i32 @fflush(ptr noundef %63)
  call void @_ZN3zmq9zmq_abortEPKc(ptr noundef @.str.8)
  br label %65

65:                                               ; preds = %60, %53
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  call void @_ZN3zmq6pipe_t17process_delimiterEv(ptr noundef nonnull align 8 dereferenceable(264) %6)
  store i1 false, ptr %2, align 1
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %4) #5
  br label %69

68:                                               ; preds = %38
  store i1 true, ptr %2, align 1
  br label %69

69:                                               ; preds = %68, %67, %36, %28, %14
  %70 = load i1, ptr %2, align 1
  ret i1 %70
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3zmq6pipe_t12is_delimiterERKNS_5msg_tE(ptr noundef nonnull align 8 dereferenceable(64)) #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3zmq6pipe_t17process_delimiterEv(ptr noundef nonnull align 8 dereferenceable(264)) #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { "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 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 = { 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, !16, i64 88}
!10 = !{!"_ZTSN3zmq6pipe_tE", !11, i64 0, !13, i64 24, !14, i64 40, !15, i64 56, !6, i64 72, !6, i64 80, !16, i64 88, !16, i64 89, !12, i64 92, !12, i64 96, !12, i64 100, !12, i64 104, !17, i64 112, !17, i64 120, !17, i64 128, !6, i64 136, !6, i64 144, !18, i64 152, !16, i64 156, !19, i64 160, !12, i64 184, !16, i64 188, !20, i64 192}
!11 = !{!"_ZTSN3zmq8object_tE", !6, i64 8, !12, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTSN3zmq12array_item_tILi1EEE", !12, i64 8}
!14 = !{!"_ZTSN3zmq12array_item_tILi2EEE", !12, i64 8}
!15 = !{!"_ZTSN3zmq12array_item_tILi3EEE", !12, i64 8}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSN3zmq6pipe_tUt_E", !7, i64 0}
!19 = !{!"_ZTSN3zmq6blob_tE", !6, i64 0, !17, i64 8, !16, i64 16}
!20 = !{!"_ZTSN3zmq19endpoint_uri_pair_tE", !21, i64 0, !21, i64 32, !23, i64 64}
!21 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !22, i64 0, !17, i64 8, !7, i64 16}
!22 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!23 = !{!"_ZTSN3zmq15endpoint_type_tE", !7, i64 0}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = !{!10, !18, i64 152}
!27 = !{!10, !6, i64 72}
!28 = !{!29, !29, i64 0}
!29 = !{!"vtable pointer", !8, i64 0}
!30 = !{!16, !16, i64 0}


; 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.zmq::msg_t" = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { ptr, [34 x i8], i8, i8, [16 x i8], i32 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [108 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #1

declare void @_ZN3zmq9zmq_abortEPKc(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3zmq6pipe_t10check_readEv(ptr noundef nonnull align 8 dereferenceable(264) %0) local_unnamed_addr #3 align 2 {
  %2 = alloca %"class.zmq::msg_t", align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 88
  %4 = load i8, ptr %3, align 8, !tbaa !5, !range !23, !noundef !24
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %6, label %36, !prof !25

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 152
  %8 = load i32, ptr %7, align 8, !tbaa !26
  %9 = and i32 %8, -3
  %spec.select.not = icmp eq i32 %9, 0
  br i1 %spec.select.not, label %10, label %36, !prof !25

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 72
  %12 = load ptr, ptr %11, align 8, !tbaa !27
  %13 = load ptr, ptr %12, align 8, !tbaa !28
  %14 = getelementptr inbounds i8, ptr %13, i64 40
  %15 = load ptr, ptr %14, align 8
  %16 = tail call noundef zeroext i1 %15(ptr noundef nonnull align 8 dereferenceable(8) %12)
  br i1 %16, label %18, label %17

17:                                               ; preds = %10
  store i8 0, ptr %3, align 8, !tbaa !5
  br label %36

18:                                               ; preds = %10
  %19 = load ptr, ptr %11, align 8, !tbaa !27
  %20 = load ptr, ptr %19, align 8, !tbaa !28
  %21 = getelementptr inbounds i8, ptr %20, i64 56
  %22 = load ptr, ptr %21, align 8
  %23 = tail call noundef zeroext i1 %22(ptr noundef nonnull align 8 dereferenceable(8) %19, ptr noundef nonnull @_ZN3zmq6pipe_t12is_delimiterERKNS_5msg_tE)
  br i1 %23, label %24, label %36

24:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #4
  %25 = load ptr, ptr %11, align 8, !tbaa !27
  %26 = load ptr, ptr %25, align 8, !tbaa !28
  %27 = getelementptr inbounds i8, ptr %26, i64 48
  %28 = load ptr, ptr %27, align 8
  %29 = call noundef zeroext i1 %28(ptr noundef nonnull align 8 dereferenceable(8) %25, ptr noundef nonnull %2)
  br i1 %29, label %35, label %30, !prof !25

30:                                               ; preds = %24
  %31 = load ptr, ptr @stderr, align 8, !tbaa !30
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 176) #5
  %33 = load ptr, ptr @stderr, align 8, !tbaa !30
  %34 = call i32 @fflush(ptr noundef %33)
  call void @_ZN3zmq9zmq_abortEPKc(ptr noundef nonnull @.str.8)
  br label %35

35:                                               ; preds = %30, %24
  call void @_ZN3zmq6pipe_t17process_delimiterEv(ptr noundef nonnull align 8 dereferenceable(264) %0)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #4
  br label %36

36:                                               ; preds = %18, %6, %1, %35, %17
  %.0 = phi i1 [ false, %35 ], [ false, %17 ], [ false, %1 ], [ false, %6 ], [ true, %18 ]
  ret i1 %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3zmq6pipe_t12is_delimiterERKNS_5msg_tE(ptr noundef nonnull align 8 dereferenceable(64)) #3 align 2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 = { "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 = { nounwind }
attributes #5 = { cold 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, !15, i64 88}
!6 = !{!"_ZTSN3zmq6pipe_tE", !7, i64 0, !12, i64 24, !13, i64 40, !14, i64 56, !8, i64 72, !8, i64 80, !15, i64 88, !15, i64 89, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !16, i64 112, !16, i64 120, !16, i64 128, !8, i64 136, !8, i64 144, !17, i64 152, !15, i64 156, !18, i64 160, !11, i64 184, !15, i64 188, !19, i64 192}
!7 = !{!"_ZTSN3zmq8object_tE", !8, i64 8, !11, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"_ZTSN3zmq12array_item_tILi1EEE", !11, i64 8}
!13 = !{!"_ZTSN3zmq12array_item_tILi2EEE", !11, i64 8}
!14 = !{!"_ZTSN3zmq12array_item_tILi3EEE", !11, i64 8}
!15 = !{!"bool", !9, i64 0}
!16 = !{!"long", !9, i64 0}
!17 = !{!"_ZTSN3zmq6pipe_tUt_E", !9, i64 0}
!18 = !{!"_ZTSN3zmq6blob_tE", !8, i64 0, !16, i64 8, !15, i64 16}
!19 = !{!"_ZTSN3zmq19endpoint_uri_pair_tE", !20, i64 0, !20, i64 32, !22, i64 64}
!20 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !21, i64 0, !16, i64 8, !9, i64 16}
!21 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !8, i64 0}
!22 = !{!"_ZTSN3zmq15endpoint_type_tE", !9, i64 0}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!26 = !{!6, !17, i64 152}
!27 = !{!6, !8, i64 72}
!28 = !{!29, !29, i64 0}
!29 = !{!"vtable pointer", !10, i64 0}
!30 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass