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

; 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::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.13 = external hidden unnamed_addr constant [77 x i8], align 1

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

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

declare i32 @fflush(ptr noundef) #2

declare void @_ZN3zmq9zmq_abortEPKc(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3zmq6pipe_t17process_pipe_termEv(ptr noundef nonnull align 8 dereferenceable(264) %0) unnamed_addr #3 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  br label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 20
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %16, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 20
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %16, label %12

12:                                               ; preds = %8
  %13 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 20
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = icmp eq i32 %14, 4
  br label %16

16:                                               ; preds = %12, %8, %4
  %17 = phi i1 [ true, %8 ], [ true, %4 ], [ %15, %12 ]
  %18 = xor i1 %17, true
  %19 = zext i1 %18 to i64
  %20 = call i64 @llvm.expect.i64(i64 %19, i64 0)
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %27

22:                                               ; preds = %16
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str.4, ptr noundef @.str.13, ptr noundef @.str.1, i32 noundef 319) #4
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = call i32 @fflush(ptr noundef %25)
  call void @_ZN3zmq9zmq_abortEPKc(ptr noundef @.str.13)
  br label %27

27:                                               ; preds = %22, %16
  br label %28

28:                                               ; preds = %27
  %29 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 20
  %30 = load i32, ptr %29, align 8, !tbaa !9
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %44

32:                                               ; preds = %28
  %33 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 21
  %34 = load i8, ptr %33, align 4, !tbaa !24, !range !25, !noundef !26
  %35 = trunc i8 %34 to i1
  br i1 %35, label %36, label %38

36:                                               ; preds = %32
  %37 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 20
  store i32 2, ptr %37, align 8, !tbaa !9
  br label %43

38:                                               ; preds = %32
  %39 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 20
  store i32 3, ptr %39, align 8, !tbaa !9
  %40 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 8
  store ptr null, ptr %40, align 8, !tbaa !27
  %41 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 18
  %42 = load ptr, ptr %41, align 8, !tbaa !28
  call void @_ZN3zmq8object_t18send_pipe_term_ackEPNS_6pipe_tE(ptr noundef nonnull align 8 dereferenceable(20) %3, ptr noundef %42)
  br label %43

43:                                               ; preds = %38, %36
  br label %64

44:                                               ; preds = %28
  %45 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 20
  %46 = load i32, ptr %45, align 8, !tbaa !9
  %47 = icmp eq i32 %46, 1
  br i1 %47, label %48, label %53

48:                                               ; preds = %44
  %49 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 20
  store i32 3, ptr %49, align 8, !tbaa !9
  %50 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 8
  store ptr null, ptr %50, align 8, !tbaa !27
  %51 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 18
  %52 = load ptr, ptr %51, align 8, !tbaa !28
  call void @_ZN3zmq8object_t18send_pipe_term_ackEPNS_6pipe_tE(ptr noundef nonnull align 8 dereferenceable(20) %3, ptr noundef %52)
  br label %63

53:                                               ; preds = %44
  %54 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 20
  %55 = load i32, ptr %54, align 8, !tbaa !9
  %56 = icmp eq i32 %55, 4
  br i1 %56, label %57, label %62

57:                                               ; preds = %53
  %58 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 20
  store i32 5, ptr %58, align 8, !tbaa !9
  %59 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 8
  store ptr null, ptr %59, align 8, !tbaa !27
  %60 = getelementptr inbounds %"class.zmq::pipe_t", ptr %3, i32 0, i32 18
  %61 = load ptr, ptr %60, align 8, !tbaa !28
  call void @_ZN3zmq8object_t18send_pipe_term_ackEPNS_6pipe_tE(ptr noundef nonnull align 8 dereferenceable(20) %3, ptr noundef %61)
  br label %62

62:                                               ; preds = %57, %53
  br label %63

63:                                               ; preds = %62, %48
  br label %64

64:                                               ; preds = %63, %43
  ret void
}

declare void @_ZN3zmq8object_t18send_pipe_term_ackEPNS_6pipe_tE(ptr noundef nonnull align 8 dereferenceable(20), ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { "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 }

!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, !18, i64 152}
!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 = !{!10, !16, i64 156}
!25 = !{i8 0, i8 2}
!26 = !{}
!27 = !{!10, !6, i64 80}
!28 = !{!10, !6, i64 136}


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

@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.13 = external hidden unnamed_addr constant [77 x i8], align 1

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

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

declare void @_ZN3zmq9zmq_abortEPKc(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3zmq6pipe_t17process_pipe_termEv(ptr noundef nonnull align 8 dereferenceable(264) %0) unnamed_addr #2 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 152
  %3 = load i32, ptr %2, align 8, !tbaa !5
  switch i32 %3, label %4 [
    i32 0, label %.critedge
    i32 1, label %.critedge
    i32 4, label %.critedge
  ]

4:                                                ; preds = %1
  %5 = load ptr, ptr @stderr, align 8, !tbaa !23
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.1, i32 noundef 319) #3
  %7 = load ptr, ptr @stderr, align 8, !tbaa !23
  %8 = tail call i32 @fflush(ptr noundef %7)
  tail call void @_ZN3zmq9zmq_abortEPKc(ptr noundef nonnull @.str.13)
  %.pr = load i32, ptr %2, align 8, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %1, %1, %1, %4
  %9 = phi i32 [ %3, %1 ], [ %3, %1 ], [ %3, %1 ], [ %.pr, %4 ]
  switch i32 %9, label %27 [
    i32 0, label %10
    i32 1, label %19
    i32 4, label %23
  ]

10:                                               ; preds = %.critedge
  %11 = getelementptr inbounds i8, ptr %0, i64 156
  %12 = load i8, ptr %11, align 4, !tbaa !24, !range !25, !noundef !26
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  store i32 2, ptr %2, align 8, !tbaa !5
  br label %27

15:                                               ; preds = %10
  store i32 3, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr null, ptr %16, align 8, !tbaa !27
  %17 = getelementptr inbounds i8, ptr %0, i64 136
  %18 = load ptr, ptr %17, align 8, !tbaa !28
  tail call void @_ZN3zmq8object_t18send_pipe_term_ackEPNS_6pipe_tE(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef %18)
  br label %27

19:                                               ; preds = %.critedge
  store i32 3, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr null, ptr %20, align 8, !tbaa !27
  %21 = getelementptr inbounds i8, ptr %0, i64 136
  %22 = load ptr, ptr %21, align 8, !tbaa !28
  tail call void @_ZN3zmq8object_t18send_pipe_term_ackEPNS_6pipe_tE(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef %22)
  br label %27

23:                                               ; preds = %.critedge
  store i32 5, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr null, ptr %24, align 8, !tbaa !27
  %25 = getelementptr inbounds i8, ptr %0, i64 136
  %26 = load ptr, ptr %25, align 8, !tbaa !28
  tail call void @_ZN3zmq8object_t18send_pipe_term_ackEPNS_6pipe_tE(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef %26)
  br label %27

27:                                               ; preds = %.critedge, %19, %23, %14, %15
  ret void
}

declare void @_ZN3zmq8object_t18send_pipe_term_ackEPNS_6pipe_tE(ptr noundef nonnull align 8 dereferenceable(20), ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { 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 #3 = { 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, !17, i64 152}
!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 = !{!8, !8, i64 0}
!24 = !{!6, !15, i64 156}
!25 = !{i8 0, i8 2}
!26 = !{}
!27 = !{!6, !8, i64 80}
!28 = !{!6, !8, i64 136}


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