; LLVM IR from rolinh/dfc :: src (util)

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

@mflag = external global i32, align 4

; 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 i32 @humanize(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store double 1.024000e+03, ptr %4, align 8, !tbaa !11
  %5 = load i32, ptr @mflag, align 4, !tbaa !9
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  store double 1.000000e+03, ptr %4, align 8, !tbaa !11
  br label %8

8:                                                ; preds = %7, %1
  br label %9

9:                                                ; preds = %18, %8
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load double, ptr %10, align 8, !tbaa !11
  %12 = fcmp oge double %11, 1.000000e+03
  br i1 %12, label %13, label %16

13:                                               ; preds = %9
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 8
  br label %16

16:                                               ; preds = %13, %9
  %17 = phi i1 [ false, %9 ], [ %15, %13 ]
  br i1 %17, label %18, label %25

18:                                               ; preds = %16
  %19 = load double, ptr %4, align 8, !tbaa !11
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = load double, ptr %20, align 8, !tbaa !11
  %22 = fdiv double %21, %19
  store double %22, ptr %20, align 8, !tbaa !11
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %3, align 4, !tbaa !9
  br label %9, !llvm.loop !13

25:                                               ; preds = %16
  %26 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %26
}

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 }

!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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@mflag = external local_unnamed_addr global i32, align 4

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local i32 @humanize(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @mflag, align 4, !tbaa !5
  %.not = icmp eq i32 %2, 0
  %spec.store.select = select i1 %.not, double 1.024000e+03, double 1.000000e+03
  %.promoted = load double, ptr %0, align 8, !tbaa !9
  %3 = fcmp ult double %.promoted, 1.000000e+03
  br i1 %3, label %19, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = fdiv double %.promoted, %spec.store.select
  %5 = fcmp ult double %4, 1.000000e+03
  br i1 %5, label %._crit_edge, label %.lr.ph.1, !llvm.loop !11

.lr.ph.1:                                         ; preds = %.lr.ph
  %6 = fdiv double %4, %spec.store.select
  %7 = fcmp ult double %6, 1.000000e+03
  br i1 %7, label %._crit_edge, label %.lr.ph.2, !llvm.loop !11

.lr.ph.2:                                         ; preds = %.lr.ph.1
  %8 = fdiv double %6, %spec.store.select
  %9 = fcmp ult double %8, 1.000000e+03
  br i1 %9, label %._crit_edge, label %.lr.ph.3, !llvm.loop !11

.lr.ph.3:                                         ; preds = %.lr.ph.2
  %10 = fdiv double %8, %spec.store.select
  %11 = fcmp ult double %10, 1.000000e+03
  br i1 %11, label %._crit_edge, label %.lr.ph.4, !llvm.loop !11

.lr.ph.4:                                         ; preds = %.lr.ph.3
  %12 = fdiv double %10, %spec.store.select
  %13 = fcmp ult double %12, 1.000000e+03
  br i1 %13, label %._crit_edge, label %.lr.ph.5, !llvm.loop !11

.lr.ph.5:                                         ; preds = %.lr.ph.4
  %14 = fdiv double %12, %spec.store.select
  %15 = fcmp ult double %14, 1.000000e+03
  br i1 %15, label %._crit_edge, label %.lr.ph.6, !llvm.loop !11

.lr.ph.6:                                         ; preds = %.lr.ph.5
  %16 = fdiv double %14, %spec.store.select
  %17 = fcmp ult double %16, 1.000000e+03
  br i1 %17, label %._crit_edge, label %.lr.ph.7, !llvm.loop !11

.lr.ph.7:                                         ; preds = %.lr.ph.6
  %18 = fdiv double %16, %spec.store.select
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.7, %.lr.ph.6, %.lr.ph.5, %.lr.ph.4, %.lr.ph.3, %.lr.ph.2, %.lr.ph.1, %.lr.ph
  %.lcssa10 = phi double [ %4, %.lr.ph ], [ %6, %.lr.ph.1 ], [ %8, %.lr.ph.2 ], [ %10, %.lr.ph.3 ], [ %12, %.lr.ph.4 ], [ %14, %.lr.ph.5 ], [ %16, %.lr.ph.6 ], [ %18, %.lr.ph.7 ]
  %.lcssa = phi i32 [ 1, %.lr.ph ], [ 2, %.lr.ph.1 ], [ 3, %.lr.ph.2 ], [ 4, %.lr.ph.3 ], [ 5, %.lr.ph.4 ], [ 6, %.lr.ph.5 ], [ 7, %.lr.ph.6 ], [ 8, %.lr.ph.7 ]
  store double %.lcssa10, ptr %0, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %._crit_edge, %1
  %.0.lcssa = phi i32 [ %.lcssa, %._crit_edge ], [ 0, %1 ]
  ret i32 %.0.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass