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

; 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 }
%struct.anon.0 = type { ptr, [33 x i8], i8, i8, i8, [16 x i8], i32 }
%struct.anon.1 = type { ptr, ptr, [26 x i8], i8, i8, [16 x i8], i32 }
%"struct.zmq::msg_t::content_t" = type { ptr, i64, ptr, ptr, %"class.zmq::atomic_counter_t" }
%"class.zmq::atomic_counter_t" = type { %"struct.std::atomic", [4 x i8] }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3zmq5msg_t9init_sizeEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %6 = load ptr, ptr %4, align 8
  %7 = load i64, ptr %5, align 8, !tbaa !9
  %8 = icmp ule i64 %7, 33
  br i1 %8, label %9, label %25

9:                                                ; preds = %2
  %10 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %11 = getelementptr inbounds %struct.anon.0, ptr %10, i32 0, i32 0
  store ptr null, ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %13 = getelementptr inbounds %struct.anon.0, ptr %12, i32 0, i32 3
  store i8 101, ptr %13, align 2, !tbaa !11
  %14 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %15 = getelementptr inbounds %struct.anon.0, ptr %14, i32 0, i32 4
  store i8 0, ptr %15, align 1, !tbaa !11
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = trunc i64 %16 to i8
  %18 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %19 = getelementptr inbounds %struct.anon.0, ptr %18, i32 0, i32 2
  store i8 %17, ptr %19, align 1, !tbaa !11
  %20 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %21 = getelementptr inbounds %struct.anon.0, ptr %20, i32 0, i32 5
  %22 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  store i8 0, ptr %22, align 4, !tbaa !11
  %23 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %24 = getelementptr inbounds %struct.anon.0, ptr %23, i32 0, i32 6
  store i32 0, ptr %24, align 4, !tbaa !11
  br label %86

25:                                               ; preds = %2
  %26 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %27 = getelementptr inbounds %struct.anon.1, ptr %26, i32 0, i32 0
  store ptr null, ptr %27, align 8, !tbaa !11
  %28 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %29 = getelementptr inbounds %struct.anon.1, ptr %28, i32 0, i32 3
  store i8 102, ptr %29, align 2, !tbaa !11
  %30 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %31 = getelementptr inbounds %struct.anon.1, ptr %30, i32 0, i32 4
  store i8 0, ptr %31, align 1, !tbaa !11
  %32 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %33 = getelementptr inbounds %struct.anon.1, ptr %32, i32 0, i32 5
  %34 = getelementptr inbounds [16 x i8], ptr %33, i64 0, i64 0
  store i8 0, ptr %34, align 4, !tbaa !11
  %35 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %36 = getelementptr inbounds %struct.anon.1, ptr %35, i32 0, i32 6
  store i32 0, ptr %36, align 4, !tbaa !11
  %37 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %38 = getelementptr inbounds %struct.anon.1, ptr %37, i32 0, i32 1
  store ptr null, ptr %38, align 8, !tbaa !11
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = add i64 40, %39
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = icmp ugt i64 %40, %41
  br i1 %42, label %43, label %49

43:                                               ; preds = %25
  %44 = load i64, ptr %5, align 8, !tbaa !9
  %45 = add i64 40, %44
  %46 = call noalias ptr @malloc(i64 noundef %45) #5
  %47 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %48 = getelementptr inbounds %struct.anon.1, ptr %47, i32 0, i32 1
  store ptr %46, ptr %48, align 8, !tbaa !11
  br label %49

49:                                               ; preds = %43, %25
  %50 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %51 = getelementptr inbounds %struct.anon.1, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !11
  %53 = icmp ne ptr %52, null
  %54 = xor i1 %53, true
  %55 = zext i1 %54 to i64
  %56 = call i64 @llvm.expect.i64(i64 %55, i64 0)
  %57 = icmp ne i64 %56, 0
  br i1 %57, label %58, label %60

58:                                               ; preds = %49
  %59 = call ptr @__errno_location() #6
  store i32 12, ptr %59, align 4, !tbaa !12
  store i32 -1, ptr %3, align 4
  br label %87

60:                                               ; preds = %49
  %61 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %62 = getelementptr inbounds %struct.anon.1, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !11
  %64 = getelementptr inbounds %"struct.zmq::msg_t::content_t", ptr %63, i64 1
  %65 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %66 = getelementptr inbounds %struct.anon.1, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !11
  %68 = getelementptr inbounds %"struct.zmq::msg_t::content_t", ptr %67, i32 0, i32 0
  store ptr %64, ptr %68, align 8, !tbaa !14
  %69 = load i64, ptr %5, align 8, !tbaa !9
  %70 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %71 = getelementptr inbounds %struct.anon.1, ptr %70, i32 0, i32 1
  %72 = load ptr, ptr %71, align 8, !tbaa !11
  %73 = getelementptr inbounds %"struct.zmq::msg_t::content_t", ptr %72, i32 0, i32 1
  store i64 %69, ptr %73, align 8, !tbaa !19
  %74 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %75 = getelementptr inbounds %struct.anon.1, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !11
  %77 = getelementptr inbounds %"struct.zmq::msg_t::content_t", ptr %76, i32 0, i32 2
  store ptr null, ptr %77, align 8, !tbaa !20
  %78 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %79 = getelementptr inbounds %struct.anon.1, ptr %78, i32 0, i32 1
  %80 = load ptr, ptr %79, align 8, !tbaa !11
  %81 = getelementptr inbounds %"struct.zmq::msg_t::content_t", ptr %80, i32 0, i32 3
  store ptr null, ptr %81, align 8, !tbaa !21
  %82 = getelementptr inbounds %"class.zmq::msg_t", ptr %6, i32 0, i32 0
  %83 = getelementptr inbounds %struct.anon.1, ptr %82, i32 0, i32 1
  %84 = load ptr, ptr %83, align 8, !tbaa !11
  %85 = getelementptr inbounds %"struct.zmq::msg_t::content_t", ptr %84, i32 0, i32 4
  call void @_ZN3zmq16atomic_counter_tC2Ej(ptr noundef nonnull align 8 dereferenceable(4) %85, i32 noundef 0)
  br label %86

86:                                               ; preds = %60, %9
  store i32 0, ptr %3, align 4
  br label %87

87:                                               ; preds = %86, %58
  %88 = load i32, ptr %3, align 4
  ret i32 %88
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3zmq16atomic_counter_tC2Ej(ptr noundef nonnull align 8 dereferenceable(4), i32 noundef) unnamed_addr #4 align 2

attributes #0 = { 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 #1 = { nounwind allocsize(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 #2 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #3 = { nounwind willreturn memory(none) "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 = { inlinehint mustprogress 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 = { nounwind allocsize(0) }
attributes #6 = { nounwind willreturn memory(none) }

!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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTSN3zmq5msg_t9content_tE", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !16, i64 32}
!16 = !{!"_ZTSN3zmq16atomic_counter_tE", !17, i64 0}
!17 = !{!"_ZTSSt6atomicIjE", !18, i64 0}
!18 = !{!"_ZTSSt13__atomic_baseIjE", !13, i64 0}
!19 = !{!15, !10, i64 8}
!20 = !{!15, !6, i64 16}
!21 = !{!15, !6, i64 24}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 -1, 1) i32 @_ZN3zmq5msg_t9init_sizeEm(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(64) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = icmp ult i64 %1, 34
  store ptr null, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 42
  %5 = getelementptr inbounds i8, ptr %0, i64 43
  br i1 %3, label %6, label %11

6:                                                ; preds = %2
  store i8 101, ptr %4, align 2, !tbaa !5
  store i8 0, ptr %5, align 1, !tbaa !5
  %7 = trunc nuw nsw i64 %1 to i8
  %8 = getelementptr inbounds i8, ptr %0, i64 41
  store i8 %7, ptr %8, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 44
  store i8 0, ptr %9, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %25

11:                                               ; preds = %2
  store i8 102, ptr %4, align 2, !tbaa !5
  store i8 0, ptr %5, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 44
  store i8 0, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 0, ptr %13, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %14, align 8, !tbaa !5
  %15 = icmp ult i64 %1, -40
  br i1 %15, label %16, label %.thread

16:                                               ; preds = %11
  %17 = add nuw i64 %1, 40
  %18 = tail call noalias ptr @malloc(i64 noundef %17) #5
  store ptr %18, ptr %14, align 8, !tbaa !5
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %.thread, label %20, !prof !8

.thread:                                          ; preds = %11, %16
  %19 = tail call ptr @__errno_location() #6
  store i32 12, ptr %19, align 4, !tbaa !9
  br label %25

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %18, i64 40
  store ptr %21, ptr %18, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %18, i64 8
  store i64 %1, ptr %22, align 8, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %18, i64 16
  %24 = getelementptr inbounds i8, ptr %18, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %23, i8 0, i64 16, i1 false)
  tail call void @_ZN3zmq16atomic_counter_tC2Ej(ptr noundef nonnull align 8 dereferenceable(4) %24, i32 noundef 0)
  br label %25

25:                                               ; preds = %6, %20, %.thread
  %.0 = phi i32 [ -1, %.thread ], [ 0, %20 ], [ 0, %6 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3zmq16atomic_counter_tC2Ej(ptr noundef nonnull align 8 dereferenceable(4), i32 noundef) unnamed_addr #3 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { mustprogress 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nofree nosync nounwind willreturn memory(none) "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 = { inlinehint mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!"branch_weights", !"expected", i32 0, i32 -2147483648}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !6, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN3zmq5msg_t9content_tE", !13, i64 0, !14, i64 8, !13, i64 16, !13, i64 24, !15, i64 32}
!13 = !{!"any pointer", !6, i64 0}
!14 = !{!"long", !6, i64 0}
!15 = !{!"_ZTSN3zmq16atomic_counter_tE", !16, i64 0}
!16 = !{!"_ZTSSt6atomicIjE", !17, i64 0}
!17 = !{!"_ZTSSt13__atomic_baseIjE", !10, i64 0}
!18 = !{!12, !14, i64 8}


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