; LLVM IR from godzilla-foundation/godzilla-community :: core/deps/nanomsg-1.1.5/src/transports/inproc (msgqueue)

; 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_msgqueue = type { %struct.anon, %struct.anon.0, i64, i64, i64, ptr }
%struct.anon = type { ptr, i32 }
%struct.anon.0 = type { ptr, i32 }
%struct.nn_msgqueue_chunk = type { [126 x %struct.nn_msg], ptr }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [23 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [129 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

declare ptr @nn_alloc_(i64 noundef) #1

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

declare void @nn_backtrace_print() #1

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

declare i32 @fflush(ptr noundef) #1

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

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

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

19:                                               ; preds = %2
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.nn_msgqueue, ptr %20, i32 0, i32 3
  %22 = load i64, ptr %21, align 8, !tbaa !15
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = add i64 %22, %23
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.nn_msgqueue, ptr %25, i32 0, i32 4
  %27 = load i64, ptr %26, align 8, !tbaa !16
  %28 = icmp uge i64 %24, %27
  br label %29

29:                                               ; preds = %19, %2
  %30 = phi i1 [ false, %2 ], [ %28, %19 ]
  %31 = zext i1 %30 to i32
  %32 = sext i32 %31 to i64
  %33 = call i64 @llvm.expect.i64(i64 %32, i64 0)
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %29
  store i32 -11, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %129

36:                                               ; preds = %29
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.nn_msgqueue, ptr %37, i32 0, i32 2
  %39 = load i64, ptr %38, align 8, !tbaa !11
  %40 = add i64 %39, 1
  store i64 %40, ptr %38, align 8, !tbaa !11
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.nn_msgqueue, ptr %42, i32 0, i32 3
  %44 = load i64, ptr %43, align 8, !tbaa !15
  %45 = add i64 %44, %41
  store i64 %45, ptr %43, align 8, !tbaa !15
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.nn_msgqueue, ptr %46, i32 0, i32 0
  %48 = getelementptr inbounds %struct.anon, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = getelementptr inbounds %struct.nn_msgqueue_chunk, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.nn_msgqueue, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds %struct.anon, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !18
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [126 x %struct.nn_msg], ptr %50, i64 0, i64 %55
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  call void @nn_msg_mv(ptr noundef %56, ptr noundef %57)
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.nn_msgqueue, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds %struct.anon, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 8, !tbaa !18
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %60, align 8, !tbaa !18
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.nn_msgqueue, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds %struct.anon, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 8, !tbaa !18
  %67 = icmp eq i32 %66, 126
  %68 = zext i1 %67 to i32
  %69 = sext i32 %68 to i64
  %70 = call i64 @llvm.expect.i64(i64 %69, i64 0)
  %71 = icmp ne i64 %70, 0
  br i1 %71, label %72, label %128

72:                                               ; preds = %36
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.nn_msgqueue, ptr %73, i32 0, i32 5
  %75 = load ptr, ptr %74, align 8, !tbaa !19
  %76 = icmp ne ptr %75, null
  %77 = xor i1 %76, true
  %78 = zext i1 %77 to i32
  %79 = sext i32 %78 to i64
  %80 = call i64 @llvm.expect.i64(i64 %79, i64 0)
  %81 = icmp ne i64 %80, 0
  br i1 %81, label %82, label %108

82:                                               ; preds = %72
  %83 = call ptr @nn_alloc_(i64 noundef 12104)
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.nn_msgqueue, ptr %84, i32 0, i32 5
  store ptr %83, ptr %85, align 8, !tbaa !19
  br label %86

86:                                               ; preds = %82
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.nn_msgqueue, ptr %87, i32 0, i32 5
  %89 = load ptr, ptr %88, align 8, !tbaa !19
  %90 = icmp ne ptr %89, null
  %91 = xor i1 %90, true
  %92 = zext i1 %91 to i32
  %93 = sext i32 %92 to i64
  %94 = call i64 @llvm.expect.i64(i64 %93, i64 0)
  %95 = icmp ne i64 %94, 0
  br i1 %95, label %96, label %101

96:                                               ; preds = %86
  call void @nn_backtrace_print()
  %97 = load ptr, ptr @stderr, align 8, !tbaa !5
  %98 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %97, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 105) #6
  %99 = load ptr, ptr @stderr, align 8, !tbaa !5
  %100 = call i32 @fflush(ptr noundef %99)
  call void @nn_err_abort() #7
  unreachable

101:                                              ; preds = %86
  br label %102

102:                                              ; preds = %101
  br label %103

103:                                              ; preds = %102
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.nn_msgqueue, ptr %104, i32 0, i32 5
  %106 = load ptr, ptr %105, align 8, !tbaa !19
  %107 = getelementptr inbounds %struct.nn_msgqueue_chunk, ptr %106, i32 0, i32 1
  store ptr null, ptr %107, align 8, !tbaa !20
  br label %108

108:                                              ; preds = %103, %72
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.nn_msgqueue, ptr %109, i32 0, i32 5
  %111 = load ptr, ptr %110, align 8, !tbaa !19
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.nn_msgqueue, ptr %112, i32 0, i32 0
  %114 = getelementptr inbounds %struct.anon, ptr %113, i32 0, i32 0
  %115 = load ptr, ptr %114, align 8, !tbaa !17
  %116 = getelementptr inbounds %struct.nn_msgqueue_chunk, ptr %115, i32 0, i32 1
  store ptr %111, ptr %116, align 8, !tbaa !20
  %117 = load ptr, ptr %4, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.nn_msgqueue, ptr %117, i32 0, i32 5
  %119 = load ptr, ptr %118, align 8, !tbaa !19
  %120 = load ptr, ptr %4, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.nn_msgqueue, ptr %120, i32 0, i32 0
  %122 = getelementptr inbounds %struct.anon, ptr %121, i32 0, i32 0
  store ptr %119, ptr %122, align 8, !tbaa !17
  %123 = load ptr, ptr %4, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.nn_msgqueue, ptr %123, i32 0, i32 5
  store ptr null, ptr %124, align 8, !tbaa !19
  %125 = load ptr, ptr %4, align 8, !tbaa !5
  %126 = getelementptr inbounds %struct.nn_msgqueue, ptr %125, i32 0, i32 0
  %127 = getelementptr inbounds %struct.anon, ptr %126, i32 0, i32 1
  store i32 0, ptr %127, align 8, !tbaa !18
  br label %128

128:                                              ; preds = %108, %36
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %129

129:                                              ; preds = %128, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %130 = load i32, ptr %3, align 4
  ret i32 %130
}

declare i64 @nn_chunkref_size(ptr noundef) #1

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { 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 #5 = { 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 #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"nn_msgqueue", !13, i64 0, !13, i64 16, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56}
!13 = !{!"", !6, i64 0, !14, i64 8}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !10, i64 40}
!16 = !{!12, !10, i64 48}
!17 = !{!12, !6, i64 0}
!18 = !{!12, !14, i64 8}
!19 = !{!12, !6, i64 56}
!20 = !{!21, !6, i64 12096}
!21 = !{!"nn_msgqueue_chunk", !7, i64 0, !6, i64 12096}


; 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 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [129 x i8], align 1

declare ptr @nn_alloc_(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -11, 1) i32 @nn_msgqueue_send(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = tail call i64 @nn_chunkref_size(ptr noundef %1) #4
  %4 = getelementptr inbounds i8, ptr %1, i64 64
  %5 = tail call i64 @nn_chunkref_size(ptr noundef nonnull %4) #4
  %6 = add i64 %5, %3
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %.not = icmp eq i64 %8, 0
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 40
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !13
  %.pre27 = add i64 %.pre, %6
  br i1 %.not, label %.critedge, label %9

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  %11 = load i64, ptr %10, align 8, !tbaa !14
  %.not26 = icmp ult i64 %.pre27, %11
  br i1 %.not26, label %.critedge, label %38, !prof !15

.critedge:                                        ; preds = %2, %9
  %12 = add i64 %8, 1
  store i64 %12, ptr %7, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %.pre27, ptr %13, align 8, !tbaa !13
  %14 = load ptr, ptr %0, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !17
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [126 x %struct.nn_msg], ptr %14, i64 0, i64 %17
  tail call void @nn_msg_mv(ptr noundef %18, ptr noundef %1) #4
  %19 = load i32, ptr %15, align 8, !tbaa !17
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %15, align 8, !tbaa !17
  %21 = icmp eq i32 %20, 126
  br i1 %21, label %22, label %38, !prof !18

22:                                               ; preds = %.critedge
  %23 = getelementptr inbounds i8, ptr %0, i64 56
  %24 = load ptr, ptr %23, align 8, !tbaa !19
  %.not24 = icmp eq ptr %24, null
  br i1 %.not24, label %25, label %34, !prof !18

25:                                               ; preds = %22
  %26 = tail call ptr @nn_alloc_(i64 noundef 12104) #4
  store ptr %26, ptr %23, align 8, !tbaa !19
  %.not25 = icmp eq ptr %26, null
  br i1 %.not25, label %27, label %32, !prof !18

27:                                               ; preds = %25
  tail call void @nn_backtrace_print() #4
  %28 = load ptr, ptr @stderr, align 8, !tbaa !20
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 105) #5
  %30 = load ptr, ptr @stderr, align 8, !tbaa !20
  %31 = tail call i32 @fflush(ptr noundef %30)
  tail call void @nn_err_abort() #6
  unreachable

32:                                               ; preds = %25
  %33 = getelementptr inbounds i8, ptr %26, i64 12096
  store ptr null, ptr %33, align 8, !tbaa !21
  br label %34

34:                                               ; preds = %32, %22
  %35 = phi ptr [ %26, %32 ], [ %24, %22 ]
  %36 = load ptr, ptr %0, align 8, !tbaa !16
  %37 = getelementptr inbounds i8, ptr %36, i64 12096
  store ptr %35, ptr %37, align 8, !tbaa !21
  store ptr %35, ptr %0, align 8, !tbaa !16
  store ptr null, ptr %23, align 8, !tbaa !19
  store i32 0, ptr %15, align 8, !tbaa !17
  br label %38

38:                                               ; preds = %.critedge, %34, %9
  %.0 = phi i32 [ -11, %9 ], [ 0, %34 ], [ 0, %.critedge ]
  ret i32 %.0
}

declare i64 @nn_chunkref_size(ptr noundef) local_unnamed_addr #0

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

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 = { nounwind }
attributes #5 = { cold nounwind }
attributes #6 = { 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, !12, i64 32}
!6 = !{!"nn_msgqueue", !7, i64 0, !7, i64 16, !12, i64 32, !12, i64 40, !12, i64 48, !8, i64 56}
!7 = !{!"", !8, i64 0, !11, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!6, !12, i64 40}
!14 = !{!6, !12, i64 48}
!15 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!16 = !{!6, !8, i64 0}
!17 = !{!6, !11, i64 8}
!18 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!19 = !{!6, !8, i64 56}
!20 = !{!8, !8, i64 0}
!21 = !{!22, !8, i64 12096}
!22 = !{!"nn_msgqueue_chunk", !9, i64 0, !8, i64 12096}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass