; LLVM IR from AnzoDK/RPAudio :: includes/minimp3/huffopt (huffopt)

; 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.huff_t = type { ptr, ptr, [2 x ptr], i32, i32, i32, %struct.anon, i32, i32, i32 }
%struct.anon = type { i32, i32, float }

; Function Attrs: nounwind uwtable
define dso_local ptr @huff_create(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !9
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %54, label %16

16:                                               ; preds = %6
  %17 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 72) #3
  store ptr %17, ptr %7, align 8, !tbaa !5
  %18 = load i32, ptr %11, align 4, !tbaa !9
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.huff_t, ptr %19, i32 0, i32 3
  store i32 %18, ptr %20, align 8, !tbaa !11
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %16
  br label %26

24:                                               ; preds = %16
  %25 = load i32, ptr %8, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %24, %23
  %27 = phi i32 [ -1, %23 ], [ %25, %24 ]
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.huff_t, ptr %28, i32 0, i32 4
  store i32 %27, ptr %29, align 4, !tbaa !15
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %26
  br label %35

33:                                               ; preds = %26
  %34 = load i32, ptr %9, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %33, %32
  %36 = phi i32 [ -1, %32 ], [ %34, %33 ]
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.huff_t, ptr %37, i32 0, i32 5
  store i32 %36, ptr %38, align 8, !tbaa !16
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.huff_t, ptr %39, i32 0, i32 6
  %41 = getelementptr inbounds %struct.anon, ptr %40, i32 0, i32 1
  store i32 1, ptr %41, align 4, !tbaa !17
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = shl i32 1, %42
  %44 = sitofp i32 %43 to float
  %45 = fdiv float 1.000000e+00, %44
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.huff_t, ptr %46, i32 0, i32 6
  %48 = getelementptr inbounds %struct.anon, ptr %47, i32 0, i32 2
  store float %45, ptr %48, align 4, !tbaa !18
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.huff_t, ptr %49, i32 0, i32 7
  store i32 -1, ptr %50, align 8, !tbaa !19
  %51 = load i32, ptr %12, align 4, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.huff_t, ptr %52, i32 0, i32 9
  store i32 %51, ptr %53, align 8, !tbaa !20
  br label %54

54:                                               ; preds = %35, %6
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %84

57:                                               ; preds = %54
  %58 = load i32, ptr %10, align 4, !tbaa !9
  %59 = icmp sgt i32 %58, 0
  br i1 %59, label %60, label %84

60:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr %10, align 4, !tbaa !9
  %64 = lshr i32 %61, %63
  %65 = and i32 %64, 1
  store i32 %65, ptr %13, align 4, !tbaa !9
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.huff_t, ptr %66, i32 0, i32 2
  %68 = load i32, ptr %13, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [2 x ptr], ptr %67, i64 0, i64 %69
  %71 = load ptr, ptr %70, align 8, !tbaa !5
  %72 = load i32, ptr %8, align 4, !tbaa !9
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = load i32, ptr %11, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  %77 = load i32, ptr %12, align 4, !tbaa !9
  %78 = call ptr @huff_create(ptr noundef %71, i32 noundef %72, i32 noundef %73, i32 noundef %74, i32 noundef %76, i32 noundef %77)
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.huff_t, ptr %79, i32 0, i32 2
  %81 = load i32, ptr %13, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [2 x ptr], ptr %80, i64 0, i64 %82
  store ptr %78, ptr %83, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %84

84:                                               ; preds = %60, %57, %54
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  ret ptr %85
}

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nounwind allocsize(0,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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind allocsize(0,1) }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"huff_t", !6, i64 0, !6, i64 8, !7, i64 16, !10, i64 32, !10, i64 36, !10, i64 40, !13, i64 44, !10, i64 56, !10, i64 60, !10, i64 64}
!13 = !{!"", !10, i64 0, !10, i64 4, !14, i64 8}
!14 = !{!"float", !7, i64 0}
!15 = !{!12, !10, i64 36}
!16 = !{!12, !10, i64 40}
!17 = !{!12, !10, i64 48}
!18 = !{!12, !14, i64 52}
!19 = !{!12, !10, i64 56}
!20 = !{!12, !10, i64 64}


; 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: nofree nounwind uwtable
define dso_local noundef ptr @huff_create(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %7, label %21

7:                                                ; preds = %6
  %8 = tail call noalias dereferenceable_or_null(72) ptr @calloc(i64 noundef 1, i64 noundef 72) #2
  %9 = getelementptr inbounds i8, ptr %8, i64 32
  store i32 %4, ptr %9, align 8, !tbaa !5
  %.not31 = icmp eq i32 %3, 0
  %10 = select i1 %.not31, i32 %1, i32 -1
  %11 = getelementptr inbounds i8, ptr %8, i64 36
  store i32 %10, ptr %11, align 4, !tbaa !13
  %12 = select i1 %.not31, i32 %2, i32 -1
  %13 = getelementptr inbounds i8, ptr %8, i64 40
  store i32 %12, ptr %13, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %8, i64 48
  store i32 1, ptr %14, align 4, !tbaa !15
  %15 = shl nuw i32 1, %4
  %16 = sitofp i32 %15 to float
  %17 = fdiv float 1.000000e+00, %16
  %18 = getelementptr inbounds i8, ptr %8, i64 52
  store float %17, ptr %18, align 4, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %8, i64 56
  store i32 -1, ptr %19, align 8, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %8, i64 64
  store i32 %5, ptr %20, align 8, !tbaa !18
  br label %21

21:                                               ; preds = %7, %6
  %.0 = phi ptr [ %0, %6 ], [ %8, %7 ]
  %22 = icmp sgt i32 %3, 0
  br i1 %22, label %23, label %common.ret32

common.ret32:                                     ; preds = %21, %23
  ret ptr %.0

23:                                               ; preds = %21
  %24 = add nsw i32 %3, -1
  %25 = lshr i32 %2, %24
  %26 = and i32 %25, 1
  %27 = getelementptr inbounds i8, ptr %.0, i64 16
  %28 = zext nneg i32 %26 to i64
  %29 = getelementptr inbounds [2 x ptr], ptr %27, i64 0, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !19
  %31 = add nsw i32 %4, 1
  %32 = tail call ptr @huff_create(ptr noundef %30, i32 noundef %1, i32 noundef %2, i32 noundef %24, i32 noundef %31, i32 noundef %5)
  store ptr %32, ptr %29, align 8, !tbaa !19
  br label %common.ret32
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { nofree 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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(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 #2 = { nounwind allocsize(0,1) }

!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 32}
!6 = !{!"huff_t", !7, i64 0, !7, i64 8, !8, i64 16, !10, i64 32, !10, i64 36, !10, i64 40, !11, i64 44, !10, i64 56, !10, i64 60, !10, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !10, i64 0, !10, i64 4, !12, i64 8}
!12 = !{!"float", !8, i64 0}
!13 = !{!6, !10, i64 36}
!14 = !{!6, !10, i64 40}
!15 = !{!6, !10, i64 48}
!16 = !{!6, !12, i64 52}
!17 = !{!6, !10, i64 56}
!18 = !{!6, !10, i64 64}
!19 = !{!7, !7, i64 0}


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