; LLVM IR from jwerle/libhypercore-crypto :: deps/merkle (merkle)

; 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.merkle_options = type { %struct.merkle_codec }
%struct.merkle_codec = type { ptr, ptr }
%struct.merkle = type { i8, %struct.merkle_node_list, i64, %struct.merkle_codec }
%struct.merkle_node_list = type { i8, i64, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @merkle_init(ptr noundef %0, ptr %1, ptr %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca %struct.merkle_options, align 8
  %6 = alloca ptr, align 8
  %7 = getelementptr inbounds { ptr, ptr }, ptr %5, i32 0, i32 0
  store ptr %1, ptr %7, align 8
  %8 = getelementptr inbounds { ptr, ptr }, ptr %5, i32 0, i32 1
  store ptr %2, ptr %8, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = icmp eq ptr null, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %3
  store i32 14, ptr %4, align 4
  br label %50

12:                                               ; preds = %3
  %13 = getelementptr inbounds %struct.merkle_options, ptr %5, i32 0, i32 0
  %14 = getelementptr inbounds %struct.merkle_codec, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = icmp eq ptr null, %15
  br i1 %16, label %17, label %20

17:                                               ; preds = %12
  %18 = getelementptr inbounds %struct.merkle_options, ptr %5, i32 0, i32 0
  %19 = getelementptr inbounds %struct.merkle_codec, ptr %18, i32 0, i32 0
  store ptr @default_node_callback, ptr %19, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %17, %12
  %21 = getelementptr inbounds %struct.merkle_options, ptr %5, i32 0, i32 0
  %22 = getelementptr inbounds %struct.merkle_codec, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = icmp eq ptr null, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %20
  %26 = getelementptr inbounds %struct.merkle_options, ptr %5, i32 0, i32 0
  %27 = getelementptr inbounds %struct.merkle_codec, ptr %26, i32 0, i32 1
  store ptr @default_parent_callback, ptr %27, align 8, !tbaa !12
  br label %28

28:                                               ; preds = %25, %20
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.merkle, ptr %29, i32 0, i32 2
  store i64 0, ptr %30, align 8, !tbaa !13
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.merkle, ptr %31, i32 0, i32 3
  %33 = getelementptr inbounds %struct.merkle_options, ptr %5, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %32, ptr align 8 %33, i64 16, i1 false), !tbaa.struct !18
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.merkle, ptr %34, i32 0, i32 1
  %36 = getelementptr inbounds %struct.merkle_node_list, ptr %35, i32 0, i32 1
  store i64 0, ptr %36, align 8, !tbaa !19
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.merkle, ptr %37, i32 0, i32 1
  %39 = load i8, ptr %38, align 8
  %40 = and i8 %39, -2
  %41 = or i8 %40, 0
  store i8 %41, ptr %38, align 8
  %42 = call ptr @merkle_alloc(i64 noundef 56)
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.merkle, ptr %43, i32 0, i32 1
  %45 = getelementptr inbounds %struct.merkle_node_list, ptr %44, i32 0, i32 2
  store ptr %42, ptr %45, align 8, !tbaa !20
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.merkle, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds %struct.merkle_node_list, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !20
  call void @llvm.memset.p0.i64(ptr align 8 %49, i8 0, i64 56, i1 false)
  store i32 0, ptr %4, align 4
  br label %50

50:                                               ; preds = %28, %11
  %51 = load i32, ptr %4, align 4
  ret i32 %51
}

; Function Attrs: nounwind uwtable
declare hidden i64 @default_node_callback(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @default_parent_callback(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare ptr @merkle_alloc(i64 noundef) #2

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

attributes #0 = { 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 nounwind willreturn memory(argmem: readwrite) }
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 nounwind willreturn memory(argmem: write) }

!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/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"merkle_options", !11, i64 0}
!11 = !{!"merkle_codec", !6, i64 0, !6, i64 8}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !17, i64 32}
!14 = !{!"merkle", !15, i64 0, !16, i64 8, !17, i64 32, !11, i64 40}
!15 = !{!"int", !7, i64 0}
!16 = !{!"merkle_node_list", !15, i64 0, !17, i64 8, !6, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{i64 0, i64 8, !5, i64 8, i64 8, !5}
!19 = !{!14, !17, i64 16}
!20 = !{!14, !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: nounwind uwtable
define dso_local range(i32 0, 15) i32 @merkle_init(ptr noundef %0, ptr %1, ptr %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %18, label %5

5:                                                ; preds = %3
  %6 = insertelement <2 x ptr> poison, ptr %1, i64 0
  %7 = insertelement <2 x ptr> %6, ptr %2, i64 1
  %8 = icmp eq <2 x ptr> %7, zeroinitializer
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 0, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = select <2 x i1> %8, <2 x ptr> <ptr @default_node_callback, ptr @default_parent_callback>, <2 x ptr> %7
  store <2 x ptr> %11, ptr %10, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 0, ptr %13, align 8, !tbaa !15
  %14 = load i8, ptr %12, align 8
  %15 = and i8 %14, -2
  store i8 %15, ptr %12, align 8
  %16 = tail call ptr @merkle_alloc(i64 noundef 56) #3
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %16, ptr %17, align 8, !tbaa !16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %16, i8 0, i64 56, i1 false)
  br label %18

18:                                               ; preds = %3, %5
  %.0 = phi i32 [ 0, %5 ], [ 14, %3 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i64 @default_node_callback(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @default_parent_callback(ptr noundef, ptr noundef, ptr noundef) #0

declare ptr @merkle_alloc(i64 noundef) local_unnamed_addr #1

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

attributes #0 = { 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 = { "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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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, !11, i64 32}
!6 = !{!"merkle", !7, i64 0, !10, i64 8, !11, i64 32, !13, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"merkle_node_list", !7, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"merkle_codec", !12, i64 0, !12, i64 8}
!14 = !{!12, !12, i64 0}
!15 = !{!6, !11, i64 16}
!16 = !{!6, !12, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass