; LLVM IR from VoidRune/Audio-engine :: src/minivorbis.ll (book_maptype1_quantvals)

; 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.static_codebook = type { i64, i64, ptr, i32, i64, i64, i32, i32, ptr, i32 }

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @_book_maptype1_quantvals(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.static_codebook, ptr %9, i32 0, i32 1
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = icmp slt i64 %11, 1
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  store i64 0, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %115

14:                                               ; preds = %1
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.static_codebook, ptr %15, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = sitofp i64 %17 to float
  %19 = fpext float %18 to double
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.static_codebook, ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !13
  %23 = sitofp i64 %22 to float
  %24 = fdiv float 1.000000e+00, %23
  %25 = fpext float %24 to double
  %26 = call double @pow(double noundef %19, double noundef %25) #4
  %27 = call double @llvm.floor.f64(double %26)
  %28 = fptosi double %27 to i64
  store i64 %28, ptr %4, align 8, !tbaa !14
  %29 = load i64, ptr %4, align 8, !tbaa !14
  %30 = icmp slt i64 %29, 1
  br i1 %30, label %31, label %32

31:                                               ; preds = %14
  store i64 1, ptr %4, align 8, !tbaa !14
  br label %32

32:                                               ; preds = %31, %14
  br label %33

33:                                               ; preds = %114, %32
  br label %34

34:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 1, ptr %6, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 1, ptr %7, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !15
  br label %35

35:                                               ; preds = %67, %34
  %36 = load i32, ptr %8, align 4, !tbaa !15
  %37 = sext i32 %36 to i64
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.static_codebook, ptr %38, i32 0, i32 0
  %40 = load i64, ptr %39, align 8, !tbaa !13
  %41 = icmp slt i64 %37, %40
  br i1 %41, label %42, label %70

42:                                               ; preds = %35
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.static_codebook, ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = load i64, ptr %4, align 8, !tbaa !14
  %47 = sdiv i64 %45, %46
  %48 = load i64, ptr %6, align 8, !tbaa !14
  %49 = icmp slt i64 %47, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %42
  br label %70

51:                                               ; preds = %42
  %52 = load i64, ptr %4, align 8, !tbaa !14
  %53 = load i64, ptr %6, align 8, !tbaa !14
  %54 = mul nsw i64 %53, %52
  store i64 %54, ptr %6, align 8, !tbaa !14
  %55 = load i64, ptr %4, align 8, !tbaa !14
  %56 = add nsw i64 %55, 1
  %57 = sdiv i64 9223372036854775807, %56
  %58 = load i64, ptr %7, align 8, !tbaa !14
  %59 = icmp slt i64 %57, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %51
  store i64 9223372036854775807, ptr %7, align 8, !tbaa !14
  br label %66

61:                                               ; preds = %51
  %62 = load i64, ptr %4, align 8, !tbaa !14
  %63 = add nsw i64 %62, 1
  %64 = load i64, ptr %7, align 8, !tbaa !14
  %65 = mul nsw i64 %64, %63
  store i64 %65, ptr %7, align 8, !tbaa !14
  br label %66

66:                                               ; preds = %61, %60
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %8, align 4, !tbaa !15
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %8, align 4, !tbaa !15
  br label %35, !llvm.loop !16

70:                                               ; preds = %50, %35
  %71 = load i32, ptr %8, align 4, !tbaa !15
  %72 = sext i32 %71 to i64
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.static_codebook, ptr %73, i32 0, i32 0
  %75 = load i64, ptr %74, align 8, !tbaa !13
  %76 = icmp sge i64 %72, %75
  br i1 %76, label %77, label %91

77:                                               ; preds = %70
  %78 = load i64, ptr %6, align 8, !tbaa !14
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.static_codebook, ptr %79, i32 0, i32 1
  %81 = load i64, ptr %80, align 8, !tbaa !9
  %82 = icmp sle i64 %78, %81
  br i1 %82, label %83, label %91

83:                                               ; preds = %77
  %84 = load i64, ptr %7, align 8, !tbaa !14
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.static_codebook, ptr %85, i32 0, i32 1
  %87 = load i64, ptr %86, align 8, !tbaa !9
  %88 = icmp sgt i64 %84, %87
  br i1 %88, label %89, label %91

89:                                               ; preds = %83
  %90 = load i64, ptr %4, align 8, !tbaa !14
  store i64 %90, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %112

91:                                               ; preds = %83, %77, %70
  %92 = load i32, ptr %8, align 4, !tbaa !15
  %93 = sext i32 %92 to i64
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.static_codebook, ptr %94, i32 0, i32 0
  %96 = load i64, ptr %95, align 8, !tbaa !13
  %97 = icmp slt i64 %93, %96
  br i1 %97, label %104, label %98

98:                                               ; preds = %91
  %99 = load i64, ptr %6, align 8, !tbaa !14
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.static_codebook, ptr %100, i32 0, i32 1
  %102 = load i64, ptr %101, align 8, !tbaa !9
  %103 = icmp sgt i64 %99, %102
  br i1 %103, label %104, label %107

104:                                              ; preds = %98, %91
  %105 = load i64, ptr %4, align 8, !tbaa !14
  %106 = add nsw i64 %105, -1
  store i64 %106, ptr %4, align 8, !tbaa !14
  br label %110

107:                                              ; preds = %98
  %108 = load i64, ptr %4, align 8, !tbaa !14
  %109 = add nsw i64 %108, 1
  store i64 %109, ptr %4, align 8, !tbaa !14
  br label %110

110:                                              ; preds = %107, %104
  br label %111

111:                                              ; preds = %110
  store i32 0, ptr %5, align 4
  br label %112

112:                                              ; preds = %111, %89
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %113 = load i32, ptr %5, align 4
  switch i32 %113, label %115 [
    i32 0, label %114
  ]

114:                                              ; preds = %112
  br label %33

115:                                              ; preds = %112, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %116 = load i64, ptr %2, align 8
  ret i64 %116
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #2

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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, !11, i64 8}
!10 = !{!"static_codebook", !11, i64 0, !11, i64 8, !6, i64 16, !12, i64 24, !11, i64 32, !11, i64 40, !12, i64 48, !12, i64 52, !6, i64 56, !12, i64 64}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!12, !12, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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: nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local i64 @_book_maptype1_quantvals(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = icmp slt i64 %3, 1
  br i1 %4, label %.thread42, label %5

5:                                                ; preds = %1
  %6 = uitofp nneg i64 %3 to float
  %7 = fpext float %6 to double
  %8 = load i64, ptr %0, align 8, !tbaa !12
  %9 = sitofp i64 %8 to float
  %10 = fdiv float 1.000000e+00, %9
  %11 = fpext float %10 to double
  %12 = tail call double @pow(double noundef %7, double noundef %11) #4
  %13 = load i64, ptr %0, align 8, !tbaa !12
  %14 = icmp sgt i64 %13, 0
  br i1 %14, label %.split.us, label %.lr.ph

.split.us:                                        ; preds = %5
  %15 = tail call double @llvm.floor.f64(double %12)
  %16 = fptosi double %15 to i64
  %spec.store.select = tail call i64 @llvm.smax.i64(i64 %16, i64 1)
  %17 = load i64, ptr %2, align 8, !tbaa !5
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.backedge, %.split.us
  %.033.us = phi i64 [ %spec.store.select, %.split.us ], [ %.033.us.be, %.lr.ph.us.backedge ]
  %18 = sdiv i64 %17, %.033.us
  %19 = add nsw i64 %.033.us, 1
  br label %22

20:                                               ; preds = %._crit_edge.us
  %21 = icmp sgt i64 %25, %17
  br i1 %21, label %.thread41.us, label %.lr.ph.us.backedge

.lr.ph.us.backedge:                               ; preds = %20, %.thread41.us
  %.033.us.be = phi i64 [ %29, %.thread41.us ], [ %19, %20 ]
  br label %.lr.ph.us

22:                                               ; preds = %.lr.ph.us, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next, %24 ]
  %.03049.us = phi i64 [ 1, %.lr.ph.us ], [ %.1.us, %24 ]
  %.03148.us = phi i64 [ 1, %.lr.ph.us ], [ %25, %24 ]
  %23 = icmp slt i64 %18, %.03148.us
  br i1 %23, label %.thread41.us, label %24

24:                                               ; preds = %22
  %25 = mul nsw i64 %.03148.us, %.033.us
  %26 = sdiv i64 9223372036854775807, %19
  %27 = icmp slt i64 %26, %.03049.us
  %28 = mul nsw i64 %.03049.us, %19
  %.1.us = select i1 %27, i64 9223372036854775807, i64 %28
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %13
  br i1 %exitcond.not, label %._crit_edge.us, label %22, !llvm.loop !13

.thread41.us:                                     ; preds = %22, %20
  %29 = add nsw i64 %.033.us, -1
  br label %.lr.ph.us.backedge

._crit_edge.us:                                   ; preds = %24
  %.not40.us = icmp sle i64 %25, %17
  %30 = icmp sgt i64 %.1.us, %17
  %or.cond.us = select i1 %.not40.us, i1 %30, i1 false
  br i1 %or.cond.us, label %.thread42, label %20

.lr.ph:                                           ; preds = %5
  %31 = load i64, ptr %2, align 8, !tbaa !5
  %32 = icmp slt i64 %31, 1
  br i1 %32, label %.thread41.us53, label %.lr.ph.split.split

.thread41.us53:                                   ; preds = %.lr.ph, %.thread41.us53
  br label %.thread41.us53

.lr.ph.split.split:                               ; preds = %.lr.ph, %.lr.ph.split.split
  br label %.lr.ph.split.split

.thread42:                                        ; preds = %._crit_edge.us, %1
  %.237 = phi i64 [ 0, %1 ], [ %.033.us, %._crit_edge.us ]
  ret i64 %.237
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #2

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

attributes #0 = { nofree nounwind memory(write, 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(write) "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 speculatable willreturn memory(none) }
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, !7, i64 8}
!6 = !{!"static_codebook", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !7, i64 32, !7, i64 40, !11, i64 48, !11, i64 52, !10, i64 56, !11, i64 64}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass