; LLVM IR from fcambus/logswan :: deps/hll (hll)

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

; 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 double @hll_count(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.HLL, ptr %8, i32 0, i32 0
  %10 = load i8, ptr %9, align 8, !tbaa !9
  %11 = zext i8 %10 to i32
  switch i32 %11, label %15 [
    i32 4, label %12
    i32 5, label %13
    i32 6, label %14
  ]

12:                                               ; preds = %1
  store double 6.730000e-01, ptr %3, align 8, !tbaa !12
  br label %23

13:                                               ; preds = %1
  store double 6.970000e-01, ptr %3, align 8, !tbaa !12
  br label %23

14:                                               ; preds = %1
  store double 7.090000e-01, ptr %3, align 8, !tbaa !12
  br label %23

15:                                               ; preds = %1
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.HLL, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !14
  %19 = uitofp i64 %18 to double
  %20 = fdiv double 1.079000e+00, %19
  %21 = fadd double 1.000000e+00, %20
  %22 = fdiv double 7.213000e-01, %21
  store double %22, ptr %3, align 8, !tbaa !12
  br label %23

23:                                               ; preds = %15, %14, %13, %12
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.HLL, ptr %24, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !14
  %27 = uitofp i64 %26 to double
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.HLL, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !14
  %31 = uitofp i64 %30 to double
  %32 = fmul double %27, %31
  %33 = load double, ptr %3, align 8, !tbaa !12
  %34 = fmul double %33, %32
  store double %34, ptr %3, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 0.000000e+00, ptr %5, align 8, !tbaa !12
  store i32 0, ptr %4, align 4, !tbaa !15
  br label %35

35:                                               ; preds = %56, %23
  %36 = load i32, ptr %4, align 4, !tbaa !15
  %37 = zext i32 %36 to i64
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.HLL, ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !14
  %41 = icmp ult i64 %37, %40
  br i1 %41, label %42, label %59

42:                                               ; preds = %35
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.HLL, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = load i32, ptr %4, align 4, !tbaa !15
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !18
  %50 = zext i8 %49 to i32
  %51 = shl i32 1, %50
  %52 = sitofp i32 %51 to double
  %53 = fdiv double 1.000000e+00, %52
  %54 = load double, ptr %5, align 8, !tbaa !12
  %55 = fadd double %54, %53
  store double %55, ptr %5, align 8, !tbaa !12
  br label %56

56:                                               ; preds = %42
  %57 = load i32, ptr %4, align 4, !tbaa !15
  %58 = add i32 %57, 1
  store i32 %58, ptr %4, align 4, !tbaa !15
  br label %35, !llvm.loop !19

59:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %60 = load double, ptr %3, align 8, !tbaa !12
  %61 = load double, ptr %5, align 8, !tbaa !12
  %62 = fdiv double %60, %61
  store double %62, ptr %6, align 8, !tbaa !12
  %63 = load double, ptr %6, align 8, !tbaa !12
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.HLL, ptr %64, i32 0, i32 1
  %66 = load i64, ptr %65, align 8, !tbaa !14
  %67 = uitofp i64 %66 to double
  %68 = fmul double 2.500000e+00, %67
  %69 = fcmp ole double %63, %68
  br i1 %69, label %70, label %112

70:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !15
  store i32 0, ptr %4, align 4, !tbaa !15
  br label %71

71:                                               ; preds = %91, %70
  %72 = load i32, ptr %4, align 4, !tbaa !15
  %73 = zext i32 %72 to i64
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.HLL, ptr %74, i32 0, i32 1
  %76 = load i64, ptr %75, align 8, !tbaa !14
  %77 = icmp ult i64 %73, %76
  br i1 %77, label %78, label %94

78:                                               ; preds = %71
  %79 = load ptr, ptr %2, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.HLL, ptr %79, i32 0, i32 2
  %81 = load ptr, ptr %80, align 8, !tbaa !17
  %82 = load i32, ptr %4, align 4, !tbaa !15
  %83 = zext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %81, i64 %83
  %85 = load i8, ptr %84, align 1, !tbaa !18
  %86 = zext i8 %85 to i32
  %87 = icmp eq i32 %86, 0
  %88 = zext i1 %87 to i32
  %89 = load i32, ptr %7, align 4, !tbaa !15
  %90 = add nsw i32 %89, %88
  store i32 %90, ptr %7, align 4, !tbaa !15
  br label %91

91:                                               ; preds = %78
  %92 = load i32, ptr %4, align 4, !tbaa !15
  %93 = add i32 %92, 1
  store i32 %93, ptr %4, align 4, !tbaa !15
  br label %71, !llvm.loop !21

94:                                               ; preds = %71
  %95 = load i32, ptr %7, align 4, !tbaa !15
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %111

97:                                               ; preds = %94
  %98 = load ptr, ptr %2, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.HLL, ptr %98, i32 0, i32 1
  %100 = load i64, ptr %99, align 8, !tbaa !14
  %101 = uitofp i64 %100 to double
  %102 = load ptr, ptr %2, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.HLL, ptr %102, i32 0, i32 1
  %104 = load i64, ptr %103, align 8, !tbaa !14
  %105 = uitofp i64 %104 to double
  %106 = load i32, ptr %7, align 4, !tbaa !15
  %107 = sitofp i32 %106 to double
  %108 = fdiv double %105, %107
  %109 = call double @log(double noundef %108) #3
  %110 = fmul double %101, %109
  store double %110, ptr %6, align 8, !tbaa !12
  br label %111

111:                                              ; preds = %97, %94
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %122

112:                                              ; preds = %59
  %113 = load double, ptr %6, align 8, !tbaa !12
  %114 = fcmp ogt double %113, 0x41A1111111111111
  br i1 %114, label %115, label %121

115:                                              ; preds = %112
  %116 = load double, ptr %6, align 8, !tbaa !12
  %117 = fdiv double %116, 0x41F0000000000000
  %118 = fsub double 1.000000e+00, %117
  %119 = call double @log(double noundef %118) #3
  %120 = fmul double 0xC1F0000000000000, %119
  store double %120, ptr %6, align 8, !tbaa !12
  br label %121

121:                                              ; preds = %115, %112
  br label %122

122:                                              ; preds = %121, %111
  %123 = load double, ptr %6, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret double %123
}

; Function Attrs: nounwind
declare double @log(double noundef) #2

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 = { 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 = { 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, !7, i64 0}
!10 = !{!"HLL", !7, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!10, !11, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!10, !6, i64 16}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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"

@switch.table.hll_count = private unnamed_addr constant [3 x double] [double 6.730000e-01, double 6.970000e-01, double 7.090000e-01], align 8

; Function Attrs: nofree nounwind memory(readwrite, inaccessiblemem: write) uwtable
define dso_local double @hll_count(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 8, !tbaa !5
  %switch.tableidx = add i8 %2, -4
  %3 = icmp ult i8 %switch.tableidx, 3
  br i1 %3, label %switch.lookup, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !11
  %7 = uitofp i64 %6 to double
  %8 = fdiv double 1.079000e+00, %7
  %9 = fadd double %8, 1.000000e+00
  %10 = fdiv double 7.213000e-01, %9
  br label %12

switch.lookup:                                    ; preds = %1
  %11 = zext nneg i8 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [3 x double], ptr @switch.table.hll_count, i64 0, i64 %11
  %switch.load = load double, ptr %switch.gep, align 8
  br label %12

12:                                               ; preds = %switch.lookup, %4
  %.031 = phi double [ %10, %4 ], [ %switch.load, %switch.lookup ]
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = uitofp i64 %14 to double
  %16 = fmul double %15, %15
  %17 = fmul double %.031, %16
  %.not45 = icmp eq i64 %14, 0
  br i1 %.not45, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %12
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  br label %20

20:                                               ; preds = %.lr.ph, %20
  %21 = phi i64 [ 0, %.lr.ph ], [ %30, %20 ]
  %.02839 = phi double [ 0.000000e+00, %.lr.ph ], [ %28, %20 ]
  %.02938 = phi i32 [ 0, %.lr.ph ], [ %29, %20 ]
  %22 = getelementptr inbounds i8, ptr %19, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !13
  %24 = zext nneg i8 %23 to i32
  %25 = shl nuw i32 1, %24
  %26 = sitofp i32 %25 to double
  %27 = fdiv double 1.000000e+00, %26
  %28 = fadd double %.02839, %27
  %29 = add i32 %.02938, 1
  %30 = zext i32 %29 to i64
  %31 = icmp ugt i64 %14, %30
  br i1 %31, label %20, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %20
  %32 = fdiv double %17, %28
  %33 = fmul double %15, 2.500000e+00
  %34 = fcmp ugt double %32, %33
  br i1 %34, label %67, label %.preheader

._crit_edge.thread:                               ; preds = %12
  %35 = fdiv double %17, 0.000000e+00
  %36 = fmul double %15, 2.500000e+00
  %37 = fcmp ugt double %35, %36
  br i1 %37, label %67, label %._crit_edge43.thread

.preheader:                                       ; preds = %._crit_edge
  br i1 %.not45, label %._crit_edge43.thread, label %.lr.ph42

.lr.ph42:                                         ; preds = %.preheader
  %38 = getelementptr inbounds i8, ptr %0, i64 16
  %39 = load ptr, ptr %38, align 8, !tbaa !12
  %min.iters.check = icmp ult i64 %14, 12
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.lr.ph42
  %40 = add i64 %14, -1
  %41 = and i64 %40, 4294967295
  %42 = icmp eq i64 %41, 4294967295
  %43 = icmp ugt i64 %40, 4294967295
  %44 = or i1 %42, %43
  br i1 %44, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i64 %14, 8589934584
  %ind.end = trunc i64 %n.vec to i32
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %51, %vector.body ]
  %vec.phi56 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %52, %vector.body ]
  %45 = getelementptr inbounds i8, ptr %39, i64 %index
  %46 = getelementptr inbounds i8, ptr %45, i64 4
  %wide.load = load <4 x i8>, ptr %45, align 1, !tbaa !13
  %wide.load57 = load <4 x i8>, ptr %46, align 1, !tbaa !13
  %47 = icmp eq <4 x i8> %wide.load, zeroinitializer
  %48 = icmp eq <4 x i8> %wide.load57, zeroinitializer
  %49 = zext <4 x i1> %47 to <4 x i32>
  %50 = zext <4 x i1> %48 to <4 x i32>
  %51 = add <4 x i32> %vec.phi, %49
  %52 = add <4 x i32> %vec.phi56, %50
  %index.next = add nuw i64 %index, 8
  %53 = icmp eq i64 %index.next, %n.vec
  br i1 %53, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %52, %51
  %54 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %14, %n.vec
  br i1 %cmp.n, label %._crit_edge43, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.scevcheck, %.lr.ph42
  %.ph = phi i64 [ 0, %vector.scevcheck ], [ 0, %.lr.ph42 ], [ %n.vec, %middle.block ]
  %.041.ph = phi i32 [ 0, %vector.scevcheck ], [ 0, %.lr.ph42 ], [ %54, %middle.block ]
  %.13040.ph = phi i32 [ 0, %vector.scevcheck ], [ 0, %.lr.ph42 ], [ %ind.end, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %55 = phi i64 [ %62, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %.041 = phi i32 [ %60, %scalar.ph ], [ %.041.ph, %scalar.ph.preheader ]
  %.13040 = phi i32 [ %61, %scalar.ph ], [ %.13040.ph, %scalar.ph.preheader ]
  %56 = getelementptr inbounds i8, ptr %39, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !13
  %58 = icmp eq i8 %57, 0
  %59 = zext i1 %58 to i32
  %60 = add nuw nsw i32 %.041, %59
  %61 = add i32 %.13040, 1
  %62 = zext i32 %61 to i64
  %63 = icmp ugt i64 %14, %62
  br i1 %63, label %scalar.ph, label %._crit_edge43, !llvm.loop !19

._crit_edge43:                                    ; preds = %scalar.ph, %middle.block
  %.lcssa = phi i32 [ %54, %middle.block ], [ %60, %scalar.ph ]
  %.not = icmp eq i32 %.lcssa, 0
  br i1 %.not, label %._crit_edge43.thread, label %64

64:                                               ; preds = %._crit_edge43
  %65 = uitofp nneg i32 %.lcssa to double
  %66 = fdiv double %15, %65
  br label %._crit_edge43.thread.sink.split

67:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %68 = phi double [ %35, %._crit_edge.thread ], [ %32, %._crit_edge ]
  %69 = fcmp ogt double %68, 0x41A1111111111111
  br i1 %69, label %70, label %._crit_edge43.thread

70:                                               ; preds = %67
  %71 = fmul double %68, 0x3DF0000000000000
  %72 = fsub double 1.000000e+00, %71
  br label %._crit_edge43.thread.sink.split

._crit_edge43.thread.sink.split:                  ; preds = %70, %64
  %.sink53 = phi double [ %66, %64 ], [ %72, %70 ]
  %.sink52 = phi double [ %15, %64 ], [ 0xC1F0000000000000, %70 ]
  %73 = tail call double @log(double noundef %.sink53) #3
  %74 = fmul double %73, %.sink52
  br label %._crit_edge43.thread

._crit_edge43.thread:                             ; preds = %._crit_edge43.thread.sink.split, %._crit_edge.thread, %.preheader, %._crit_edge43, %67
  %.1 = phi double [ %68, %67 ], [ %32, %._crit_edge43 ], [ %32, %.preheader ], [ %35, %._crit_edge.thread ], [ %74, %._crit_edge43.thread.sink.split ]
  ret double %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #2

attributes #0 = { nofree nounwind memory(readwrite, inaccessiblemem: write) 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 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"HLL", !7, i64 0, !9, i64 8, !10, i64 16}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!6, !9, i64 8}
!12 = !{!6, !10, i64 16}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15, !17, !18}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = distinct !{!19, !15, !17}


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