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

; 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.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [108 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3zmq6trie_tD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %"class.zmq::trie_t", ptr %4, i32 0, i32 2
  %6 = load i16, ptr %5, align 2, !tbaa !9
  %7 = zext i16 %6 to i32
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %34

9:                                                ; preds = %1
  br label %10

10:                                               ; preds = %9
  %11 = getelementptr inbounds %"class.zmq::trie_t", ptr %4, i32 0, i32 4
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = icmp ne ptr %12, null
  %14 = xor i1 %13, true
  %15 = zext i1 %14 to i64
  %16 = call i64 @llvm.expect.i64(i64 %15, i64 0)
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %25

18:                                               ; preds = %10
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str, ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 47) #7
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = invoke i32 @fflush(ptr noundef %21)
          to label %23 unwind label %71

23:                                               ; preds = %18
  invoke void @_ZN3zmq9zmq_abortEPKc(ptr noundef @.str.1)
          to label %24 unwind label %71

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24, %10
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = getelementptr inbounds %"class.zmq::trie_t", ptr %4, i32 0, i32 4
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = icmp eq ptr %29, null
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  call void @_ZN3zmq6trie_tD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %29) #7
  call void @_ZdlPvm(ptr noundef %29, i64 noundef 24) #8
  br label %32

32:                                               ; preds = %31, %27
  %33 = getelementptr inbounds %"class.zmq::trie_t", ptr %4, i32 0, i32 4
  store ptr null, ptr %33, align 8, !tbaa !13
  br label %70

34:                                               ; preds = %1
  %35 = getelementptr inbounds %"class.zmq::trie_t", ptr %4, i32 0, i32 2
  %36 = load i16, ptr %35, align 2, !tbaa !9
  %37 = zext i16 %36 to i32
  %38 = icmp sgt i32 %37, 1
  br i1 %38, label %39, label %69

39:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #7
  store i16 0, ptr %3, align 2, !tbaa !14
  br label %40

40:                                               ; preds = %63, %39
  %41 = load i16, ptr %3, align 2, !tbaa !14
  %42 = zext i16 %41 to i32
  %43 = getelementptr inbounds %"class.zmq::trie_t", ptr %4, i32 0, i32 2
  %44 = load i16, ptr %43, align 2, !tbaa !9
  %45 = zext i16 %44 to i32
  %46 = icmp ne i32 %42, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #7
  br label %66

48:                                               ; preds = %40
  %49 = getelementptr inbounds %"class.zmq::trie_t", ptr %4, i32 0, i32 4
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = load i16, ptr %3, align 2, !tbaa !14
  %52 = zext i16 %51 to i64
  %53 = getelementptr inbounds ptr, ptr %50, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = icmp eq ptr %54, null
  br i1 %55, label %57, label %56

56:                                               ; preds = %48
  call void @_ZN3zmq6trie_tD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %54) #7
  call void @_ZdlPvm(ptr noundef %54, i64 noundef 24) #8
  br label %57

57:                                               ; preds = %56, %48
  %58 = getelementptr inbounds %"class.zmq::trie_t", ptr %4, i32 0, i32 4
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = load i16, ptr %3, align 2, !tbaa !14
  %61 = zext i16 %60 to i64
  %62 = getelementptr inbounds ptr, ptr %59, i64 %61
  store ptr null, ptr %62, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %57
  %64 = load i16, ptr %3, align 2, !tbaa !14
  %65 = add i16 %64, 1
  store i16 %65, ptr %3, align 2, !tbaa !14
  br label %40, !llvm.loop !15

66:                                               ; preds = %47
  %67 = getelementptr inbounds %"class.zmq::trie_t", ptr %4, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !13
  call void @free(ptr noundef %68) #7
  br label %69

69:                                               ; preds = %66, %34
  br label %70

70:                                               ; preds = %69, %32
  ret void

71:                                               ; preds = %23, %18
  %72 = landingpad { ptr, i32 }
          catch ptr null
  %73 = extractvalue { ptr, i32 } %72, 0
  call void @__clang_call_terminate(ptr %73) #9
  unreachable
}

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

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

declare i32 @fflush(ptr noundef) #3

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #4

declare void @_ZN3zmq9zmq_abortEPKc(ptr noundef) #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #5

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

declare void @_ZN3zmq6trie_tD1Ev(ptr)

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(none) }
attributes #2 = { 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 #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 = { noinline noreturn nounwind uwtable "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 = { nobuiltin 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 #6 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { nounwind }
attributes #8 = { builtin nounwind }
attributes #9 = { noreturn 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, !12, i64 6}
!10 = !{!"_ZTSN3zmq6trie_tE", !11, i64 0, !7, i64 4, !12, i64 6, !12, i64 8, !7, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [108 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3zmq6trie_tD2Ev(ptr nocapture noundef nonnull align 8 dereferenceable(24) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 6
  %3 = load i16, ptr %2, align 2, !tbaa !5
  switch i16 %3, label %.lr.ph [
    i16 1, label %5
    i16 0, label %32
  ]

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  br label %19

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %.not8 = icmp eq ptr %7, null
  br i1 %.not8, label %8, label %.thread, !prof !12

8:                                                ; preds = %5
  %9 = load ptr, ptr @stderr, align 8, !tbaa !13
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 47) #6
  %11 = load ptr, ptr @stderr, align 8, !tbaa !13
  %12 = tail call i32 @fflush(ptr noundef %11)
  invoke void @_ZN3zmq9zmq_abortEPKc(ptr noundef nonnull @.str.1)
          to label %13 unwind label %33

13:                                               ; preds = %8
  %.pr = load ptr, ptr %6, align 8, !tbaa !11
  %14 = icmp eq ptr %.pr, null
  br i1 %14, label %16, label %.thread

.thread:                                          ; preds = %5, %13
  %15 = phi ptr [ %.pr, %13 ], [ %7, %5 ]
  tail call void @_ZN3zmq6trie_tD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %15) #7
  tail call void @_ZdlPvm(ptr noundef nonnull %15, i64 noundef 24) #8
  br label %16

16:                                               ; preds = %.thread, %13
  store ptr null, ptr %6, align 8, !tbaa !11
  br label %32

._crit_edge:                                      ; preds = %27
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  tail call void @free(ptr noundef %18) #7
  br label %32

19:                                               ; preds = %.lr.ph, %27
  %20 = phi i16 [ %3, %.lr.ph ], [ %28, %27 ]
  %.010 = phi i16 [ 0, %.lr.ph ], [ %31, %27 ]
  %21 = load ptr, ptr %4, align 8, !tbaa !11
  %22 = zext i16 %.010 to i64
  %23 = getelementptr inbounds ptr, ptr %21, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = icmp eq ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %19
  tail call void @_ZN3zmq6trie_tD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %24) #7
  tail call void @_ZdlPvm(ptr noundef nonnull %24, i64 noundef 24) #8
  %.pre = load ptr, ptr %4, align 8, !tbaa !11
  %.pre11 = load i16, ptr %2, align 2, !tbaa !5
  br label %27

27:                                               ; preds = %26, %19
  %28 = phi i16 [ %.pre11, %26 ], [ %20, %19 ]
  %29 = phi ptr [ %.pre, %26 ], [ %21, %19 ]
  %30 = getelementptr inbounds ptr, ptr %29, i64 %22
  store ptr null, ptr %30, align 8, !tbaa !13
  %31 = add i16 %.010, 1
  %.not7 = icmp eq i16 %31, %28
  br i1 %.not7, label %._crit_edge, label %19, !llvm.loop !15

32:                                               ; preds = %1, %._crit_edge, %16
  ret void

33:                                               ; preds = %8
  %34 = landingpad { ptr, i32 }
          catch ptr null
  %35 = extractvalue { ptr, i32 } %34, 0
  tail call void @__clang_call_terminate(ptr %35) #9
  unreachable
}

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

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #2

declare void @_ZN3zmq9zmq_abortEPKc(ptr noundef) local_unnamed_addr #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #5

declare void @_ZN3zmq6trie_tD1Ev(ptr) local_unnamed_addr

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 = { 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 #2 = { noinline noreturn nounwind uwtable "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 = { nobuiltin 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 #5 = { mustprogress nounwind willreturn allockind("free") 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 #6 = { cold nounwind }
attributes #7 = { nounwind }
attributes #8 = { builtin nounwind }
attributes #9 = { noreturn 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, !10, i64 6}
!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 = !{!8, !8, i64 0}
!12 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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