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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3zmq16socks_greeting_tC2EPKhh(ptr noundef nonnull align 8 dereferenceable(264) %0, ptr noundef %1, i8 noundef zeroext %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i8 %2, ptr %6, align 1, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %"struct.zmq::socks_greeting_t", ptr %8, i32 0, i32 1
  %10 = load i8, ptr %6, align 1, !tbaa !9
  %11 = zext i8 %10 to i64
  store i64 %11, ptr %9, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !9
  br label %12

12:                                               ; preds = %29, %3
  %13 = load i8, ptr %7, align 1, !tbaa !9
  %14 = zext i8 %13 to i32
  %15 = load i8, ptr %6, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %12
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i8, ptr %7, align 1, !tbaa !9
  %22 = zext i8 %21 to i64
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = getelementptr inbounds %"struct.zmq::socks_greeting_t", ptr %8, i32 0, i32 0
  %26 = load i8, ptr %7, align 1, !tbaa !9
  %27 = zext i8 %26 to i64
  %28 = getelementptr inbounds [255 x i8], ptr %25, i64 0, i64 %27
  store i8 %24, ptr %28, align 1, !tbaa !9
  br label %29

29:                                               ; preds = %19
  %30 = load i8, ptr %7, align 1, !tbaa !9
  %31 = add i8 %30, 1
  store i8 %31, ptr %7, align 1, !tbaa !9
  br label %12, !llvm.loop !13

32:                                               ; preds = %18
  ret void
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"}


; 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(argmem: readwrite) uwtable
define dso_local void @_ZN3zmq16socks_greeting_tC2EPKhh(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(264) %0, ptr nocapture noundef readonly %1, i8 noundef zeroext %2) unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 256
  %5 = zext i8 %2 to i64
  store i64 %5, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i8 %2, 0
  br i1 %.not, label %._crit_edge, label %iter.check

iter.check:                                       ; preds = %3
  %6 = ptrtoint ptr %0 to i64
  %7 = ptrtoint ptr %1 to i64
  %min.iters.check = icmp ult i8 %2, 8
  %8 = sub i64 %6, %7
  %diff.check = icmp ult i64 %8, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check9 = icmp ult i8 %2, 32
  br i1 %min.iters.check9, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %5, 224
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %wide.load = load <16 x i8>, ptr %1, align 1, !tbaa !10
  %wide.load10 = load <16 x i8>, ptr %9, align 1, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  store <16 x i8> %wide.load, ptr %0, align 8, !tbaa !10
  store <16 x i8> %wide.load10, ptr %10, align 8, !tbaa !10
  %11 = icmp eq i64 %n.vec, 32
  br i1 %11, label %middle.block, label %vector.body.1, !llvm.loop !11

vector.body.1:                                    ; preds = %vector.ph
  %12 = getelementptr inbounds i8, ptr %1, i64 32
  %13 = getelementptr inbounds i8, ptr %1, i64 48
  %wide.load.1 = load <16 x i8>, ptr %12, align 1, !tbaa !10
  %wide.load10.1 = load <16 x i8>, ptr %13, align 1, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  store <16 x i8> %wide.load.1, ptr %14, align 8, !tbaa !10
  store <16 x i8> %wide.load10.1, ptr %15, align 8, !tbaa !10
  %16 = icmp eq i64 %n.vec, 64
  br i1 %16, label %middle.block, label %vector.body.2, !llvm.loop !11

vector.body.2:                                    ; preds = %vector.body.1
  %17 = getelementptr inbounds i8, ptr %1, i64 64
  %18 = getelementptr inbounds i8, ptr %1, i64 80
  %wide.load.2 = load <16 x i8>, ptr %17, align 1, !tbaa !10
  %wide.load10.2 = load <16 x i8>, ptr %18, align 1, !tbaa !10
  %19 = getelementptr inbounds i8, ptr %0, i64 64
  %20 = getelementptr inbounds i8, ptr %0, i64 80
  store <16 x i8> %wide.load.2, ptr %19, align 8, !tbaa !10
  store <16 x i8> %wide.load10.2, ptr %20, align 8, !tbaa !10
  %21 = icmp eq i64 %n.vec, 96
  br i1 %21, label %middle.block, label %vector.body.3, !llvm.loop !11

vector.body.3:                                    ; preds = %vector.body.2
  %22 = getelementptr inbounds i8, ptr %1, i64 96
  %23 = getelementptr inbounds i8, ptr %1, i64 112
  %wide.load.3 = load <16 x i8>, ptr %22, align 1, !tbaa !10
  %wide.load10.3 = load <16 x i8>, ptr %23, align 1, !tbaa !10
  %24 = getelementptr inbounds i8, ptr %0, i64 96
  %25 = getelementptr inbounds i8, ptr %0, i64 112
  store <16 x i8> %wide.load.3, ptr %24, align 8, !tbaa !10
  store <16 x i8> %wide.load10.3, ptr %25, align 8, !tbaa !10
  %26 = icmp eq i64 %n.vec, 128
  br i1 %26, label %middle.block, label %vector.body.4, !llvm.loop !11

vector.body.4:                                    ; preds = %vector.body.3
  %27 = getelementptr inbounds i8, ptr %1, i64 128
  %28 = getelementptr inbounds i8, ptr %1, i64 144
  %wide.load.4 = load <16 x i8>, ptr %27, align 1, !tbaa !10
  %wide.load10.4 = load <16 x i8>, ptr %28, align 1, !tbaa !10
  %29 = getelementptr inbounds i8, ptr %0, i64 128
  %30 = getelementptr inbounds i8, ptr %0, i64 144
  store <16 x i8> %wide.load.4, ptr %29, align 8, !tbaa !10
  store <16 x i8> %wide.load10.4, ptr %30, align 8, !tbaa !10
  %31 = icmp eq i64 %n.vec, 160
  br i1 %31, label %middle.block, label %vector.body.5, !llvm.loop !11

vector.body.5:                                    ; preds = %vector.body.4
  %32 = getelementptr inbounds i8, ptr %1, i64 160
  %33 = getelementptr inbounds i8, ptr %1, i64 176
  %wide.load.5 = load <16 x i8>, ptr %32, align 1, !tbaa !10
  %wide.load10.5 = load <16 x i8>, ptr %33, align 1, !tbaa !10
  %34 = getelementptr inbounds i8, ptr %0, i64 160
  %35 = getelementptr inbounds i8, ptr %0, i64 176
  store <16 x i8> %wide.load.5, ptr %34, align 8, !tbaa !10
  store <16 x i8> %wide.load10.5, ptr %35, align 8, !tbaa !10
  %36 = icmp eq i64 %n.vec, 192
  br i1 %36, label %middle.block, label %vector.body.6, !llvm.loop !11

vector.body.6:                                    ; preds = %vector.body.5
  %37 = getelementptr inbounds i8, ptr %1, i64 192
  %38 = getelementptr inbounds i8, ptr %1, i64 208
  %wide.load.6 = load <16 x i8>, ptr %37, align 1, !tbaa !10
  %wide.load10.6 = load <16 x i8>, ptr %38, align 1, !tbaa !10
  %39 = getelementptr inbounds i8, ptr %0, i64 192
  %40 = getelementptr inbounds i8, ptr %0, i64 208
  store <16 x i8> %wide.load.6, ptr %39, align 8, !tbaa !10
  store <16 x i8> %wide.load10.6, ptr %40, align 8, !tbaa !10
  br label %middle.block

middle.block:                                     ; preds = %vector.body.6, %vector.body.5, %vector.body.4, %vector.body.3, %vector.body.2, %vector.body.1, %vector.ph
  %cmp.n = icmp eq i64 %n.vec, %5
  br i1 %cmp.n, label %._crit_edge, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %n.vec.remaining = and i64 %5, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %indvars.iv.ph = phi i64 [ 0, %iter.check ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec12, %vec.epilog.middle.block ]
  %xtraiter = and i64 %5, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %indvars.iv.ph, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %41 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.prol
  %42 = load i8, ptr %41, align 1, !tbaa !10
  %43 = getelementptr inbounds [255 x i8], ptr %0, i64 0, i64 %indvars.iv.prol
  store i8 %42, ptr %43, align 1, !tbaa !10
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !15

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph.preheader ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %44 = sub nsw i64 %indvars.iv.ph, %5
  %45 = icmp ugt i64 %44, -4
  br i1 %45, label %._crit_edge, label %.lr.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec12 = and i64 %5, 248
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index13 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next15, %vec.epilog.vector.body ]
  %46 = getelementptr inbounds i8, ptr %1, i64 %index13
  %wide.load14 = load <8 x i8>, ptr %46, align 1, !tbaa !10
  %47 = getelementptr inbounds [255 x i8], ptr %0, i64 0, i64 %index13
  store <8 x i8> %wide.load14, ptr %47, align 8, !tbaa !10
  %index.next15 = add nuw i64 %index13, 8
  %48 = icmp eq i64 %index.next15, %n.vec12
  br i1 %48, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !17

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n16 = icmp eq i64 %n.vec12, %5
  br i1 %cmp.n16, label %._crit_edge, label %.lr.ph.preheader

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %vec.epilog.middle.block, %3
  ret void

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %49 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  %50 = load i8, ptr %49, align 1, !tbaa !10
  %51 = getelementptr inbounds [255 x i8], ptr %0, i64 0, i64 %indvars.iv
  store i8 %50, ptr %51, align 1, !tbaa !10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %52 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next
  %53 = load i8, ptr %52, align 1, !tbaa !10
  %54 = getelementptr inbounds [255 x i8], ptr %0, i64 0, i64 %indvars.iv.next
  store i8 %53, ptr %54, align 1, !tbaa !10
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %55 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next.1
  %56 = load i8, ptr %55, align 1, !tbaa !10
  %57 = getelementptr inbounds [255 x i8], ptr %0, i64 0, i64 %indvars.iv.next.1
  store i8 %56, ptr %57, align 1, !tbaa !10
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %58 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next.2
  %59 = load i8, ptr %58, align 1, !tbaa !10
  %60 = getelementptr inbounds [255 x i8], ptr %0, i64 0, i64 %indvars.iv.next.2
  store i8 %59, ptr %60, align 1, !tbaa !10
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %5
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !18
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass