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

@unitflag = external global i8, align 1
@stderr = external global ptr, align 8
@.str.15 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [31 x i8], align 1

; 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

declare i32 @fputs(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @get_req_width(double noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca double, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store double %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store ptr @.str.15, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store i32 4, ptr %7, align 4, !tbaa !11
  %11 = load i32, ptr %7, align 4, !tbaa !11
  store i32 %11, ptr %6, align 4, !tbaa !11
  %12 = load i8, ptr @unitflag, align 1, !tbaa !13
  %13 = sext i8 %12 to i32
  %14 = icmp eq i32 %13, 104
  br i1 %14, label %15, label %18

15:                                               ; preds = %1
  %16 = load i32, ptr %6, align 4, !tbaa !11
  %17 = add nsw i32 %16, 3
  store i32 %17, ptr %6, align 4, !tbaa !11
  br label %59

18:                                               ; preds = %1
  %19 = load ptr, ptr %8, align 8, !tbaa !9
  %20 = load i8, ptr @unitflag, align 1, !tbaa !13
  %21 = sext i8 %20 to i32
  %22 = call ptr @strchr(ptr noundef %19, i32 noundef %21) #7
  store ptr %22, ptr %9, align 8, !tbaa !9
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %18
  %25 = load ptr, ptr @stderr, align 8, !tbaa !9
  %26 = call i32 @fputs(ptr noundef @.str.16, ptr noundef %25)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %69

27:                                               ; preds = %18
  %28 = load double, ptr %3, align 8, !tbaa !5
  %29 = fcmp ogt double %28, 0.000000e+00
  br i1 %29, label %30, label %41

30:                                               ; preds = %27
  %31 = load double, ptr %3, align 8, !tbaa !5
  %32 = call i1 @llvm.is.fpclass.f64(double %31, i32 264)
  br i1 %32, label %33, label %41

33:                                               ; preds = %30
  %34 = load double, ptr %3, align 8, !tbaa !5
  %35 = call double @log10(double noundef %34) #6
  %36 = call double @llvm.trunc.f64(double %35)
  %37 = fadd double 1.000000e+00, %36
  %38 = fptosi double %37 to i32
  %39 = load i32, ptr %6, align 4, !tbaa !11
  %40 = add nsw i32 %39, %38
  store i32 %40, ptr %6, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %33, %30, %27
  %42 = load ptr, ptr %9, align 8, !tbaa !9
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = ptrtoint ptr %42 to i64
  %45 = ptrtoint ptr %43 to i64
  %46 = sub i64 %44, %45
  %47 = add nsw i64 %46, 1
  store i64 %47, ptr %5, align 8, !tbaa !14
  store i64 1, ptr %4, align 8, !tbaa !14
  br label %48

48:                                               ; preds = %55, %41
  %49 = load i64, ptr %4, align 8, !tbaa !14
  %50 = load i64, ptr %5, align 8, !tbaa !14
  %51 = icmp slt i64 %49, %50
  br i1 %51, label %52, label %58

52:                                               ; preds = %48
  %53 = load i32, ptr %6, align 4, !tbaa !11
  %54 = sub nsw i32 %53, 3
  store i32 %54, ptr %6, align 4, !tbaa !11
  br label %55

55:                                               ; preds = %52
  %56 = load i64, ptr %4, align 8, !tbaa !14
  %57 = add nsw i64 %56, 1
  store i64 %57, ptr %4, align 8, !tbaa !14
  br label %48, !llvm.loop !16

58:                                               ; preds = %48
  br label %59

59:                                               ; preds = %58, %15
  %60 = load i32, ptr %6, align 4, !tbaa !11
  %61 = load i32, ptr %7, align 4, !tbaa !11
  %62 = icmp slt i32 %60, %61
  br i1 %62, label %63, label %65

63:                                               ; preds = %59
  %64 = load i32, ptr %7, align 4, !tbaa !11
  br label %67

65:                                               ; preds = %59
  %66 = load i32, ptr %6, align 4, !tbaa !11
  br label %67

67:                                               ; preds = %65, %63
  %68 = phi i32 [ %64, %63 ], [ %66, %65 ]
  store i32 %68, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %69

69:                                               ; preds = %67, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %70 = load i32, ptr %2, align 4
  ret i32 %70
}

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strchr(ptr noundef, i32 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i1 @llvm.is.fpclass.f64(double, i32 immarg) #4

; Function Attrs: nounwind
declare double @log10(double noundef) #5

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { nounwind willreturn memory(read) "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, 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"

@unitflag = external local_unnamed_addr global i8, align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.15 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fputs(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @get_req_width(double noundef %0) local_unnamed_addr #1 {
  %2 = load i8, ptr @unitflag, align 1, !tbaa !5
  %3 = icmp eq i8 %2, 104
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %1
  %5 = sext i8 %2 to i32
  %6 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) @.str.15, i32 noundef %5) #6
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %11

8:                                                ; preds = %4
  %9 = load ptr, ptr @stderr, align 8, !tbaa !8
  %10 = tail call i32 @fputs(ptr noundef nonnull @.str.16, ptr noundef %9) #7
  br label %28

11:                                               ; preds = %4
  %12 = fcmp ogt double %0, 0.000000e+00
  br i1 %12, label %13, label %21

13:                                               ; preds = %11
  %14 = tail call i1 @llvm.is.fpclass.f64(double %0, i32 256)
  br i1 %14, label %15, label %21

15:                                               ; preds = %13
  %16 = tail call double @log10(double noundef %0) #8
  %17 = tail call double @llvm.trunc.f64(double %16)
  %18 = fadd double %17, 1.000000e+00
  %19 = fptosi double %18 to i32
  %20 = add nsw i32 %19, 4
  br label %21

21:                                               ; preds = %15, %13, %11
  %.018 = phi i32 [ %20, %15 ], [ 4, %13 ], [ 4, %11 ]
  %22 = ptrtoint ptr %6 to i64
  %23 = sub i64 %22, ptrtoint (ptr @.str.15 to i64)
  %.not22 = icmp slt i64 %23, 1
  br i1 %.not22, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %21
  %24 = trunc i64 %22 to i32
  %.neg = mul i32 %24, -3
  %25 = add i32 %.018, mul (i32 ptrtoint (ptr @.str.15 to i32), i32 3)
  %26 = add i32 %.neg, %25
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.preheader, %21, %1
  %.2 = phi i32 [ 7, %1 ], [ %.018, %21 ], [ %26, %.lr.ph.preheader ]
  %27 = tail call i32 @llvm.smax.i32(i32 %.2, i32 4)
  br label %28

28:                                               ; preds = %.loopexit, %8
  %.0 = phi i32 [ %27, %.loopexit ], [ -1, %8 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strchr(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i1 @llvm.is.fpclass.f64(double, i32 immarg) #3

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

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

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

attributes #0 = { nofree 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 #1 = { 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 #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { cold }
attributes #8 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}


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