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

; 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::trie_t" = type { i32, i8, i16, i16, %union.anon }
%union.anon = type { ptr }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [108 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

declare i32 @fflush(ptr noundef) #2

declare void @_ZN3zmq9zmq_abortEPKc(ptr noundef) #2

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

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

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3zmq6trie_t12apply_helperEPPhmmPFvS1_mPvES3_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) #5 align 2 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i16, align 2
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8
  %15 = getelementptr inbounds %"class.zmq::trie_t", ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %24

18:                                               ; preds = %6
  %19 = load ptr, ptr %11, align 8, !tbaa !5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  call void %19(ptr noundef %21, i64 noundef %22, ptr noundef %23)
  br label %24

24:                                               ; preds = %18, %6
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = load i64, ptr %10, align 8, !tbaa !9
  %27 = icmp uge i64 %25, %26
  br i1 %27, label %28, label %51

28:                                               ; preds = %24
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = add i64 %29, 256
  store i64 %30, ptr %10, align 8, !tbaa !9
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = load i64, ptr %10, align 8, !tbaa !9
  %34 = call ptr @realloc(ptr noundef %32, i64 noundef %33) #6
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %34, ptr %35, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %28
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  %40 = xor i1 %39, true
  %41 = zext i1 %40 to i64
  %42 = call i64 @llvm.expect.i64(i64 %41, i64 0)
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %44, label %49

44:                                               ; preds = %36
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str, ptr noundef @.str.15, ptr noundef @.str.2, i32 noundef 296) #7
  %47 = load ptr, ptr @stderr, align 8, !tbaa !5
  %48 = call i32 @fflush(ptr noundef %47)
  call void @_ZN3zmq9zmq_abortEPKc(ptr noundef @.str.15)
  br label %49

49:                                               ; preds = %44, %36
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50, %24
  %52 = getelementptr inbounds %"class.zmq::trie_t", ptr %14, i32 0, i32 2
  %53 = load i16, ptr %52, align 2, !tbaa !15
  %54 = zext i16 %53 to i32
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %51
  br label %123

57:                                               ; preds = %51
  %58 = getelementptr inbounds %"class.zmq::trie_t", ptr %14, i32 0, i32 2
  %59 = load i16, ptr %58, align 2, !tbaa !15
  %60 = zext i16 %59 to i32
  %61 = icmp eq i32 %60, 1
  br i1 %61, label %62, label %78

62:                                               ; preds = %57
  %63 = getelementptr inbounds %"class.zmq::trie_t", ptr %14, i32 0, i32 1
  %64 = load i8, ptr %63, align 4, !tbaa !16
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = load i64, ptr %9, align 8, !tbaa !9
  %68 = getelementptr inbounds i8, ptr %66, i64 %67
  store i8 %64, ptr %68, align 1, !tbaa !17
  %69 = load i64, ptr %9, align 8, !tbaa !9
  %70 = add i64 %69, 1
  store i64 %70, ptr %9, align 8, !tbaa !9
  %71 = getelementptr inbounds %"class.zmq::trie_t", ptr %14, i32 0, i32 4
  %72 = load ptr, ptr %71, align 8, !tbaa !17
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = load i64, ptr %9, align 8, !tbaa !9
  %75 = load i64, ptr %10, align 8, !tbaa !9
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = load ptr, ptr %12, align 8, !tbaa !5
  call void @_ZNK3zmq6trie_t12apply_helperEPPhmmPFvS1_mPvES3_(ptr noundef nonnull align 8 dereferenceable(24) %72, ptr noundef %73, i64 noundef %74, i64 noundef %75, ptr noundef %76, ptr noundef %77)
  br label %123

78:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #7
  store i16 0, ptr %13, align 2, !tbaa !18
  br label %79

79:                                               ; preds = %120, %78
  %80 = load i16, ptr %13, align 2, !tbaa !18
  %81 = zext i16 %80 to i32
  %82 = getelementptr inbounds %"class.zmq::trie_t", ptr %14, i32 0, i32 2
  %83 = load i16, ptr %82, align 2, !tbaa !15
  %84 = zext i16 %83 to i32
  %85 = icmp ne i32 %81, %84
  br i1 %85, label %87, label %86

86:                                               ; preds = %79
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #7
  br label %123

87:                                               ; preds = %79
  %88 = getelementptr inbounds %"class.zmq::trie_t", ptr %14, i32 0, i32 1
  %89 = load i8, ptr %88, align 4, !tbaa !16
  %90 = zext i8 %89 to i32
  %91 = load i16, ptr %13, align 2, !tbaa !18
  %92 = zext i16 %91 to i32
  %93 = add nsw i32 %90, %92
  %94 = trunc i32 %93 to i8
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = load ptr, ptr %95, align 8, !tbaa !5
  %97 = load i64, ptr %9, align 8, !tbaa !9
  %98 = getelementptr inbounds i8, ptr %96, i64 %97
  store i8 %94, ptr %98, align 1, !tbaa !17
  %99 = getelementptr inbounds %"class.zmq::trie_t", ptr %14, i32 0, i32 4
  %100 = load ptr, ptr %99, align 8, !tbaa !17
  %101 = load i16, ptr %13, align 2, !tbaa !18
  %102 = zext i16 %101 to i64
  %103 = getelementptr inbounds ptr, ptr %100, i64 %102
  %104 = load ptr, ptr %103, align 8, !tbaa !5
  %105 = icmp ne ptr %104, null
  br i1 %105, label %106, label %119

106:                                              ; preds = %87
  %107 = getelementptr inbounds %"class.zmq::trie_t", ptr %14, i32 0, i32 4
  %108 = load ptr, ptr %107, align 8, !tbaa !17
  %109 = load i16, ptr %13, align 2, !tbaa !18
  %110 = zext i16 %109 to i64
  %111 = getelementptr inbounds ptr, ptr %108, i64 %110
  %112 = load ptr, ptr %111, align 8, !tbaa !5
  %113 = load ptr, ptr %8, align 8, !tbaa !5
  %114 = load i64, ptr %9, align 8, !tbaa !9
  %115 = add i64 %114, 1
  %116 = load i64, ptr %10, align 8, !tbaa !9
  %117 = load ptr, ptr %11, align 8, !tbaa !5
  %118 = load ptr, ptr %12, align 8, !tbaa !5
  call void @_ZNK3zmq6trie_t12apply_helperEPPhmmPFvS1_mPvES3_(ptr noundef nonnull align 8 dereferenceable(24) %112, ptr noundef %113, i64 noundef %115, i64 noundef %116, ptr noundef %117, ptr noundef %118)
  br label %119

119:                                              ; preds = %106, %87
  br label %120

120:                                              ; preds = %119
  %121 = load i16, ptr %13, align 2, !tbaa !18
  %122 = add i16 %121, 1
  store i16 %122, ptr %13, align 2, !tbaa !18
  br label %79, !llvm.loop !19

123:                                              ; preds = %86, %62, %56
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #1 = { 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind allocsize(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 #5 = { 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 #6 = { nounwind allocsize(1) }
attributes #7 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN3zmq6trie_tE", !13, i64 0, !7, i64 4, !14, i64 6, !14, i64 8, !7, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !14, i64 6}
!16 = !{!12, !7, i64 4}
!17 = !{!7, !7, i64 0}
!18 = !{!14, !14, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [108 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #0

declare void @_ZN3zmq9zmq_abortEPKc(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3zmq6trie_t12apply_helperEPPhmmPFvS1_mPvES3_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0, ptr nocapture noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef readonly %4, ptr noundef %5) local_unnamed_addr #3 align 2 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %27, %6
  %.tr = phi ptr [ %0, %6 ], [ %34, %27 ]
  %.tr42 = phi i64 [ %2, %6 ], [ %32, %27 ]
  %.tr43 = phi i64 [ %3, %6 ], [ %.031, %27 ]
  %7 = load i32, ptr %.tr, align 8, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %10, label %8

8:                                                ; preds = %tailrecurse
  %9 = load ptr, ptr %1, align 8, !tbaa !11
  tail call void %4(ptr noundef %9, i64 noundef %.tr42, ptr noundef %5)
  br label %10

10:                                               ; preds = %8, %tailrecurse
  %.not37 = icmp ult i64 %.tr42, %.tr43
  br i1 %.not37, label %20, label %11

11:                                               ; preds = %10
  %12 = add i64 %.tr42, 256
  %13 = load ptr, ptr %1, align 8, !tbaa !11
  %14 = tail call ptr @realloc(ptr noundef %13, i64 noundef %12) #4
  store ptr %14, ptr %1, align 8, !tbaa !11
  %.not38 = icmp eq ptr %14, null
  br i1 %.not38, label %15, label %20, !prof !13

15:                                               ; preds = %11
  %16 = load ptr, ptr @stderr, align 8, !tbaa !11
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.2, i32 noundef 296) #5
  %18 = load ptr, ptr @stderr, align 8, !tbaa !11
  %19 = tail call i32 @fflush(ptr noundef %18)
  tail call void @_ZN3zmq9zmq_abortEPKc(ptr noundef nonnull @.str.15)
  br label %20

20:                                               ; preds = %15, %11, %10
  %.031 = phi i64 [ %12, %15 ], [ %12, %11 ], [ %.tr43, %10 ]
  %21 = getelementptr inbounds i8, ptr %.tr, i64 6
  %22 = load i16, ptr %21, align 2, !tbaa !14
  switch i16 %22, label %.lr.ph [
    i16 0, label %.loopexit
    i16 1, label %27
  ]

.lr.ph:                                           ; preds = %20
  %23 = getelementptr inbounds i8, ptr %.tr, i64 6
  %24 = getelementptr inbounds i8, ptr %.tr, i64 4
  %25 = getelementptr inbounds i8, ptr %.tr, i64 16
  %26 = add i64 %.tr42, 1
  br label %35

27:                                               ; preds = %20
  %28 = getelementptr inbounds i8, ptr %.tr, i64 4
  %29 = load i8, ptr %28, align 4, !tbaa !15
  %30 = load ptr, ptr %1, align 8, !tbaa !11
  %31 = getelementptr inbounds i8, ptr %30, i64 %.tr42
  store i8 %29, ptr %31, align 1, !tbaa !16
  %32 = add i64 %.tr42, 1
  %33 = getelementptr inbounds i8, ptr %.tr, i64 16
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  br label %tailrecurse

35:                                               ; preds = %.lr.ph, %46
  %.053 = phi i16 [ 0, %.lr.ph ], [ %47, %46 ]
  %36 = trunc i16 %.053 to i8
  %37 = load i8, ptr %24, align 4, !tbaa !15
  %38 = add i8 %37, %36
  %39 = load ptr, ptr %1, align 8, !tbaa !11
  %40 = getelementptr inbounds i8, ptr %39, i64 %.tr42
  store i8 %38, ptr %40, align 1, !tbaa !16
  %41 = load ptr, ptr %25, align 8, !tbaa !16
  %42 = zext i16 %.053 to i64
  %43 = getelementptr inbounds ptr, ptr %41, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  %.not40 = icmp eq ptr %44, null
  br i1 %.not40, label %46, label %45

45:                                               ; preds = %35
  tail call void @_ZNK3zmq6trie_t12apply_helperEPPhmmPFvS1_mPvES3_(ptr noundef nonnull align 8 dereferenceable(24) %44, ptr noundef nonnull %1, i64 noundef %26, i64 noundef %.031, ptr noundef %4, ptr noundef %5)
  br label %46

46:                                               ; preds = %35, %45
  %47 = add i16 %.053, 1
  %48 = load i16, ptr %23, align 2, !tbaa !14
  %.not39 = icmp eq i16 %47, %48
  br i1 %.not39, label %.loopexit, label %35, !llvm.loop !17

.loopexit:                                        ; preds = %20, %46
  ret void
}

attributes #0 = { 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 #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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, 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 #3 = { 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 #4 = { nounwind allocsize(1) }
attributes #5 = { cold 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, !7, i64 0}
!6 = !{!"_ZTSN3zmq6trie_tE", !7, i64 0, !8, i64 4, !10, i64 6, !10, i64 8, !8, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!14 = !{!6, !10, i64 6}
!15 = !{!6, !8, i64 4}
!16 = !{!8, !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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