; 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_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 }
%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] }

; 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: 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_recv(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, 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) #4
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.nn_msgqueue, ptr %8, i32 0, i32 2
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = icmp ne i64 %10, 0
  %12 = xor i1 %11, true
  %13 = zext i1 %12 to i32
  %14 = sext i32 %13 to i64
  %15 = call i64 @llvm.expect.i64(i64 %14, i64 0)
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  store i32 -11, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %94

18:                                               ; preds = %2
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.nn_msgqueue, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds %struct.anon.0, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = getelementptr inbounds %struct.nn_msgqueue_chunk, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.nn_msgqueue, ptr %25, i32 0, i32 1
  %27 = getelementptr inbounds %struct.anon.0, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !15
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [126 x %struct.nn_msg], ptr %24, i64 0, i64 %29
  call void @nn_msg_mv(ptr noundef %19, ptr noundef %30)
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.nn_msgqueue, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.anon.0, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !15
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %33, align 8, !tbaa !15
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.nn_msgqueue, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds %struct.anon.0, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 8, !tbaa !15
  %40 = icmp eq i32 %39, 126
  %41 = zext i1 %40 to i32
  %42 = sext i32 %41 to i64
  %43 = call i64 @llvm.expect.i64(i64 %42, i64 0)
  %44 = icmp ne i64 %43, 0
  br i1 %44, label %45, label %78

45:                                               ; preds = %18
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.nn_msgqueue, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds %struct.anon.0, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  store ptr %49, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.nn_msgqueue, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds %struct.anon.0, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = getelementptr inbounds %struct.nn_msgqueue_chunk, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.nn_msgqueue, ptr %56, i32 0, i32 1
  %58 = getelementptr inbounds %struct.anon.0, ptr %57, i32 0, i32 0
  store ptr %55, ptr %58, align 8, !tbaa !14
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.nn_msgqueue, ptr %59, i32 0, i32 1
  %61 = getelementptr inbounds %struct.anon.0, ptr %60, i32 0, i32 1
  store i32 0, ptr %61, align 8, !tbaa !15
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.nn_msgqueue, ptr %62, i32 0, i32 5
  %64 = load ptr, ptr %63, align 8, !tbaa !18
  %65 = icmp ne ptr %64, null
  %66 = xor i1 %65, true
  %67 = zext i1 %66 to i32
  %68 = sext i32 %67 to i64
  %69 = call i64 @llvm.expect.i64(i64 %68, i64 1)
  %70 = icmp ne i64 %69, 0
  br i1 %70, label %71, label %75

71:                                               ; preds = %45
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.nn_msgqueue, ptr %73, i32 0, i32 5
  store ptr %72, ptr %74, align 8, !tbaa !18
  br label %77

75:                                               ; preds = %45
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  call void @nn_free(ptr noundef %76)
  br label %77

77:                                               ; preds = %75, %71
  br label %78

78:                                               ; preds = %77, %18
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.nn_msgqueue, ptr %79, i32 0, i32 2
  %81 = load i64, ptr %80, align 8, !tbaa !9
  %82 = add i64 %81, -1
  store i64 %82, ptr %80, align 8, !tbaa !9
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.nn_msg, ptr %83, i32 0, i32 0
  %85 = call i64 @nn_chunkref_size(ptr noundef %84)
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.nn_msg, ptr %86, i32 0, i32 2
  %88 = call i64 @nn_chunkref_size(ptr noundef %87)
  %89 = add i64 %85, %88
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.nn_msgqueue, ptr %90, i32 0, i32 3
  %92 = load i64, ptr %91, align 8, !tbaa !19
  %93 = sub i64 %92, %89
  store i64 %93, ptr %91, align 8, !tbaa !19
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %94

94:                                               ; preds = %78, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %95 = load i32, ptr %3, align 4
  ret i32 %95
}

declare void @nn_free(ptr noundef) #3

declare i64 @nn_chunkref_size(ptr noundef) #3

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

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


; 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] }

; Function Attrs: nounwind uwtable
define dso_local range(i32 -11, 1) i32 @nn_msgqueue_recv(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %33, label %5, !prof !13

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i32, ptr %8, align 8, !tbaa !15
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [126 x %struct.nn_msg], ptr %7, i64 0, i64 %10
  tail call void @nn_msg_mv(ptr noundef %1, ptr noundef %11) #2
  %12 = load i32, ptr %8, align 8, !tbaa !15
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr %8, align 8, !tbaa !15
  %14 = icmp eq i32 %13, 126
  br i1 %14, label %15, label %23, !prof !13

15:                                               ; preds = %5
  %16 = load ptr, ptr %6, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %16, i64 12096
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  store ptr %18, ptr %6, align 8, !tbaa !14
  store i32 0, ptr %8, align 8, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  %20 = load ptr, ptr %19, align 8, !tbaa !18
  %.not18 = icmp eq ptr %20, null
  br i1 %.not18, label %21, label %22, !prof !19

21:                                               ; preds = %15
  store ptr %16, ptr %19, align 8, !tbaa !18
  br label %23

22:                                               ; preds = %15
  tail call void @nn_free(ptr noundef nonnull %16) #2
  br label %23

23:                                               ; preds = %21, %22, %5
  %24 = load i64, ptr %3, align 8, !tbaa !5
  %25 = add i64 %24, -1
  store i64 %25, ptr %3, align 8, !tbaa !5
  %26 = tail call i64 @nn_chunkref_size(ptr noundef %1) #2
  %27 = getelementptr inbounds i8, ptr %1, i64 64
  %28 = tail call i64 @nn_chunkref_size(ptr noundef nonnull %27) #2
  %29 = getelementptr inbounds i8, ptr %0, i64 40
  %30 = load i64, ptr %29, align 8, !tbaa !20
  %31 = add i64 %28, %26
  %32 = sub i64 %30, %31
  store i64 %32, ptr %29, align 8, !tbaa !20
  br label %33

33:                                               ; preds = %2, %23
  %.0 = phi i32 [ 0, %23 ], [ -11, %2 ]
  ret i32 %.0
}

declare void @nn_free(ptr noundef) local_unnamed_addr #1

declare i64 @nn_chunkref_size(ptr noundef) local_unnamed_addr #1

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

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

!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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!14 = !{!6, !8, i64 16}
!15 = !{!6, !11, i64 24}
!16 = !{!17, !8, i64 12096}
!17 = !{!"nn_msgqueue_chunk", !9, i64 0, !8, i64 12096}
!18 = !{!6, !8, i64 56}
!19 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!20 = !{!6, !12, i64 40}


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