; LLVM IR from erwincoumans/tiny-differentiable-simulator :: third_party/zeromq/src (socks)

; 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::socks_greeting_encoder_t" = type <{ i64, i64, [257 x i8], [7 x i8] }>
%"struct.zmq::socks_greeting_t" = type { [255 x i8], i64 }

; 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(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3zmq24socks_greeting_encoder_t6encodeERKNS_16socks_greeting_tE(ptr noundef nonnull align 8 dereferenceable(273) %0, ptr noundef nonnull align 8 dereferenceable(264) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %8 = getelementptr inbounds %"class.zmq::socks_greeting_encoder_t", ptr %7, i32 0, i32 2
  %9 = getelementptr inbounds [257 x i8], ptr %8, i64 0, i64 0
  store ptr %9, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i32 1
  store ptr %11, ptr %5, align 8, !tbaa !5
  store i8 5, ptr %10, align 1, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %"struct.zmq::socks_greeting_t", ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !10
  %15 = trunc i64 %14 to i8
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i32 1
  store ptr %17, ptr %5, align 8, !tbaa !5
  store i8 %15, ptr %16, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  store i8 0, ptr %6, align 1, !tbaa !9
  br label %18

18:                                               ; preds = %35, %2
  %19 = load i8, ptr %6, align 1, !tbaa !9
  %20 = zext i8 %19 to i64
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.zmq::socks_greeting_t", ptr %21, i32 0, i32 1
  %23 = load i64, ptr %22, align 8, !tbaa !10
  %24 = icmp ult i64 %20, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  br label %38

26:                                               ; preds = %18
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.zmq::socks_greeting_t", ptr %27, i32 0, i32 0
  %29 = load i8, ptr %6, align 1, !tbaa !9
  %30 = zext i8 %29 to i64
  %31 = getelementptr inbounds [255 x i8], ptr %28, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i32 1
  store ptr %34, ptr %5, align 8, !tbaa !5
  store i8 %32, ptr %33, align 1, !tbaa !9
  br label %35

35:                                               ; preds = %26
  %36 = load i8, ptr %6, align 1, !tbaa !9
  %37 = add i8 %36, 1
  store i8 %37, ptr %6, align 1, !tbaa !9
  br label %18, !llvm.loop !13

38:                                               ; preds = %25
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.zmq::socks_greeting_t", ptr %39, i32 0, i32 1
  %41 = load i64, ptr %40, align 8, !tbaa !10
  %42 = add i64 2, %41
  %43 = getelementptr inbounds %"class.zmq::socks_greeting_encoder_t", ptr %7, i32 0, i32 0
  store i64 %42, ptr %43, align 8, !tbaa !15
  %44 = getelementptr inbounds %"class.zmq::socks_greeting_encoder_t", ptr %7, i32 0, i32 1
  store i64 0, ptr %44, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 256}
!11 = !{!"_ZTSN3zmq16socks_greeting_tE", !7, i64 0, !12, i64 256}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !12, i64 0}
!16 = !{!"_ZTSN3zmq24socks_greeting_encoder_tE", !12, i64 0, !12, i64 8, !7, i64 16}
!17 = !{!16, !12, i64 8}


; 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 nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN3zmq24socks_greeting_encoder_t6encodeERKNS_16socks_greeting_tE(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(273) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(264) %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = getelementptr inbounds i8, ptr %0, i64 17
  store i8 5, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 256
  %6 = load i64, ptr %5, align 8, !tbaa !8
  %7 = trunc i64 %6 to i8
  store i8 %7, ptr %4, align 1, !tbaa !5
  %8 = load i64, ptr %5, align 8, !tbaa !8
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 18
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %10 = add nuw nsw i64 %18, 2
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.lcssa = phi i64 [ 2, %2 ], [ %10, %._crit_edge.loopexit ]
  store i64 %.lcssa, ptr %0, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 0, ptr %11, align 8, !tbaa !13
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %12 = phi i64 [ %17, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.014 = phi i8 [ %16, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.01013 = phi ptr [ %15, %.lr.ph ], [ %9, %.lr.ph.preheader ]
  %13 = getelementptr inbounds [255 x i8], ptr %1, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.01013, i64 1
  store i8 %14, ptr %.01013, align 1, !tbaa !5
  %16 = add i8 %.014, 1
  %17 = zext i8 %16 to i64
  %18 = load i64, ptr %5, align 8, !tbaa !8
  %19 = icmp ugt i64 %18, %17
  br i1 %19, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !14
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) 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" }

!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 = !{!9, !10, i64 256}
!9 = !{!"_ZTSN3zmq16socks_greeting_tE", !6, i64 0, !10, i64 256}
!10 = !{!"long", !6, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN3zmq24socks_greeting_encoder_tE", !10, i64 0, !10, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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