; LLVM IR from godzilla-foundation/godzilla-community :: core/deps/nanomsg-1.1.5/src/protocols/utils (dist)

; 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.nn_msg = type { %struct.nn_chunkref, %struct.nn_chunkref, %struct.nn_chunkref }
%struct.nn_chunkref = type { %union.anon }
%union.anon = type { ptr, [24 x i8] }
%struct.nn_dist = type { i32, %struct.nn_list }
%struct.nn_list = type { ptr, ptr }
%struct.nn_dist_data = type { %struct.nn_list_item, ptr }
%struct.nn_list_item = type { ptr, ptr }

@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [123 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1

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

declare void @nn_backtrace_print() #1

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

declare i32 @fflush(ptr noundef) #1

; Function Attrs: noreturn
declare void @nn_err_abort() #3

declare ptr @nn_list_erase(ptr noundef, ptr noundef) #1

declare ptr @nn_list_end(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @nn_dist_send(ptr noundef %0, ptr noundef %1, ptr noundef %2) #4 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %struct.nn_msg, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 96, ptr %11) #6
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.nn_dist, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = call i64 @llvm.expect.i64(i64 %16, i64 0)
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  call void @nn_msg_term(ptr noundef %20)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %101

21:                                               ; preds = %3
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.nn_dist, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !9
  call void @nn_msg_bulkcopy_start(ptr noundef %22, i32 noundef %25)
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.nn_dist, ptr %26, i32 0, i32 1
  %28 = call ptr @nn_list_begin(ptr noundef %27)
  store ptr %28, ptr %9, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %94, %84, %21
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.nn_dist, ptr %31, i32 0, i32 1
  %33 = call ptr @nn_list_end(ptr noundef %32)
  %34 = icmp ne ptr %30, %33
  br i1 %34, label %35, label %99

35:                                               ; preds = %29
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 0
  br label %42

41:                                               ; preds = %35
  br label %42

42:                                               ; preds = %41, %38
  %43 = phi ptr [ %40, %38 ], [ null, %41 ]
  store ptr %43, ptr %10, align 8, !tbaa !5
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  call void @nn_msg_bulkcopy_cp(ptr noundef %11, ptr noundef %44)
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.nn_dist_data, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = icmp eq ptr %47, %48
  %50 = zext i1 %49 to i32
  %51 = sext i32 %50 to i64
  %52 = call i64 @llvm.expect.i64(i64 %51, i64 1)
  %53 = icmp ne i64 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %42
  call void @nn_msg_term(ptr noundef %11)
  br label %94

55:                                               ; preds = %42
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.nn_dist_data, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  %59 = call i32 @nn_pipe_send(ptr noundef %58, ptr noundef %11)
  store i32 %59, ptr %8, align 4, !tbaa !16
  br label %60

60:                                               ; preds = %55
  %61 = load i32, ptr %8, align 4, !tbaa !16
  %62 = icmp sge i32 %61, 0
  %63 = xor i1 %62, true
  %64 = zext i1 %63 to i32
  %65 = sext i32 %64 to i64
  %66 = call i64 @llvm.expect.i64(i64 %65, i64 0)
  %67 = icmp ne i64 %66, 0
  br i1 %67, label %68, label %78

68:                                               ; preds = %60
  call void @nn_backtrace_print()
  %69 = load ptr, ptr @stderr, align 8, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !16
  %71 = sub nsw i32 0, %70
  %72 = call ptr @nn_err_strerror(i32 noundef %71)
  %73 = load i32, ptr %8, align 4, !tbaa !16
  %74 = sub nsw i32 0, %73
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %69, ptr noundef @.str.3, ptr noundef %72, i32 noundef %74, ptr noundef @.str.2, i32 noundef 95) #6
  %76 = load ptr, ptr @stderr, align 8, !tbaa !5
  %77 = call i32 @fflush(ptr noundef %76)
  call void @nn_err_abort() #7
  unreachable

78:                                               ; preds = %60
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %8, align 4, !tbaa !16
  %82 = and i32 %81, 1
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %93

84:                                               ; preds = %80
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.nn_dist, ptr %85, i32 0, i32 0
  %87 = load i32, ptr %86, align 8, !tbaa !9
  %88 = add i32 %87, -1
  store i32 %88, ptr %86, align 8, !tbaa !9
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.nn_dist, ptr %89, i32 0, i32 1
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  %92 = call ptr @nn_list_erase(ptr noundef %90, ptr noundef %91)
  store ptr %92, ptr %9, align 8, !tbaa !5
  br label %29, !llvm.loop !17

93:                                               ; preds = %80
  br label %94

94:                                               ; preds = %93, %54
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.nn_dist, ptr %95, i32 0, i32 1
  %97 = load ptr, ptr %9, align 8, !tbaa !5
  %98 = call ptr @nn_list_next(ptr noundef %96, ptr noundef %97)
  store ptr %98, ptr %9, align 8, !tbaa !5
  br label %29, !llvm.loop !17

99:                                               ; preds = %29
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  call void @nn_msg_term(ptr noundef %100)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %101

101:                                              ; preds = %99, %19
  call void @llvm.lifetime.end.p0(i64 96, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  %102 = load i32, ptr %4, align 4
  ret i32 %102
}

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

declare void @nn_msg_term(ptr noundef) #1

declare void @nn_msg_bulkcopy_start(ptr noundef, i32 noundef) #1

declare ptr @nn_list_begin(ptr noundef) #1

declare void @nn_msg_bulkcopy_cp(ptr noundef, ptr noundef) #1

declare i32 @nn_pipe_send(ptr noundef, ptr noundef) #1

declare ptr @nn_err_strerror(i32 noundef) #1

declare ptr @nn_list_next(ptr noundef, ptr noundef) #1

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

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

!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, !11, i64 0}
!10 = !{!"nn_dist", !11, i64 0, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"nn_list", !6, i64 0, !6, i64 8}
!13 = !{!14, !6, i64 16}
!14 = !{!"nn_dist_data", !15, i64 0, !6, i64 16}
!15 = !{!"nn_list_item", !6, i64 0, !6, i64 8}
!16 = !{!11, !11, i64 0}
!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"

%struct.nn_msg = type { %struct.nn_chunkref, %struct.nn_chunkref, %struct.nn_chunkref }
%struct.nn_chunkref = type { %union.anon }
%union.anon = type { ptr, [24 x i8] }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [123 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1

declare void @nn_backtrace_print() local_unnamed_addr #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

; Function Attrs: noreturn
declare void @nn_err_abort() local_unnamed_addr #2

declare ptr @nn_list_erase(ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @nn_list_end(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @nn_dist_send(ptr noundef %0, ptr noundef %1, ptr noundef readnone %2) local_unnamed_addr #3 {
  %4 = alloca %struct.nn_msg, align 8
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %4) #5
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %8, !prof !12

7:                                                ; preds = %3
  tail call void @nn_msg_term(ptr noundef %1) #5
  br label %35

8:                                                ; preds = %3
  tail call void @nn_msg_bulkcopy_start(ptr noundef %1, i32 noundef %5) #5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = tail call ptr @nn_list_begin(ptr noundef nonnull %9) #5
  %11 = tail call ptr @nn_list_end(ptr noundef nonnull %9) #5
  %.not25 = icmp eq ptr %10, %11
  br i1 %.not25, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.backedge
  %.02326 = phi ptr [ %.023.be, %.backedge ], [ %10, %8 ]
  call void @nn_msg_bulkcopy_cp(ptr noundef nonnull %4, ptr noundef %1) #5
  %12 = getelementptr inbounds i8, ptr %.02326, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = icmp eq ptr %13, %2
  br i1 %14, label %15, label %16, !prof !12

15:                                               ; preds = %.lr.ph
  call void @nn_msg_term(ptr noundef nonnull %4) #5
  br label %33

16:                                               ; preds = %.lr.ph
  %17 = call i32 @nn_pipe_send(ptr noundef %13, ptr noundef nonnull %4) #5
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %26, !prof !16

19:                                               ; preds = %16
  call void @nn_backtrace_print() #5
  %20 = load ptr, ptr @stderr, align 8, !tbaa !17
  %21 = sub nsw i32 0, %17
  %22 = call ptr @nn_err_strerror(i32 noundef %21) #5
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str.3, ptr noundef %22, i32 noundef %21, ptr noundef nonnull @.str.2, i32 noundef 95) #6
  %24 = load ptr, ptr @stderr, align 8, !tbaa !17
  %25 = call i32 @fflush(ptr noundef %24)
  call void @nn_err_abort() #7
  unreachable

26:                                               ; preds = %16
  %27 = and i32 %17, 1
  %.not24 = icmp eq i32 %27, 0
  br i1 %.not24, label %33, label %28

28:                                               ; preds = %26
  %29 = load i32, ptr %0, align 8, !tbaa !5
  %30 = add i32 %29, -1
  store i32 %30, ptr %0, align 8, !tbaa !5
  %31 = call ptr @nn_list_erase(ptr noundef nonnull %9, ptr noundef nonnull %.02326) #5
  br label %.backedge

.backedge:                                        ; preds = %28, %33
  %.023.be = phi ptr [ %34, %33 ], [ %31, %28 ]
  %32 = call ptr @nn_list_end(ptr noundef nonnull %9) #5
  %.not = icmp eq ptr %.023.be, %32
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

33:                                               ; preds = %26, %15
  %34 = call ptr @nn_list_next(ptr noundef nonnull %9, ptr noundef nonnull %.02326) #5
  br label %.backedge

._crit_edge:                                      ; preds = %.backedge, %8
  call void @nn_msg_term(ptr noundef %1) #5
  br label %35

35:                                               ; preds = %._crit_edge, %7
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %4) #5
  ret i32 0
}

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

declare void @nn_msg_term(ptr noundef) local_unnamed_addr #0

declare void @nn_msg_bulkcopy_start(ptr noundef, i32 noundef) local_unnamed_addr #0

declare ptr @nn_list_begin(ptr noundef) local_unnamed_addr #0

declare void @nn_msg_bulkcopy_cp(ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @nn_pipe_send(ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @nn_err_strerror(i32 noundef) local_unnamed_addr #0

declare ptr @nn_list_next(ptr noundef, ptr noundef) local_unnamed_addr #0

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

attributes #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 = { 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 = { noreturn "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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { cold nounwind }
attributes #7 = { 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, !7, i64 0}
!6 = !{!"nn_dist", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"nn_list", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!13 = !{!14, !11, i64 16}
!14 = !{!"nn_dist_data", !15, i64 0, !11, i64 16}
!15 = !{!"nn_list_item", !11, i64 0, !11, i64 8}
!16 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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