; LLVM IR from tezc/sc :: sc (sc)

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

@__const.sc_bytes_to_size.suffix = external hidden unnamed_addr constant [6 x ptr], align 16
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [10 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 ptr @sc_bytes_to_size(ptr noundef %0, i64 noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca [6 x ptr], align 16
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 48, ptr %8) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %8, ptr align 16 @__const.sc_bytes_to_size.suffix, i64 48, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %14 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %14, ptr %11, align 8, !tbaa !9
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = icmp ult i64 %15, 1024
  br i1 %16, label %17, label %33

17:                                               ; preds = %3
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = trunc i64 %20 to i32
  %22 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %18, i64 noundef %19, ptr noundef @.str.6, i32 noundef %21) #4
  store i32 %22, ptr %10, align 4, !tbaa !11
  %23 = load i32, ptr %10, align 4, !tbaa !11
  %24 = icmp sle i32 %23, 0
  br i1 %24, label %30, label %25

25:                                               ; preds = %17
  %26 = load i32, ptr %10, align 4, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = load i64, ptr %6, align 8, !tbaa !9
  %29 = icmp uge i64 %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %25, %17
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %75

31:                                               ; preds = %25
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %32, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %75

33:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 40, ptr %13, align 4, !tbaa !11
  br label %34

34:                                               ; preds = %51, %33
  %35 = load i32, ptr %13, align 4, !tbaa !11
  %36 = icmp sge i32 %35, 0
  br i1 %36, label %37, label %43

37:                                               ; preds = %34
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = load i32, ptr %13, align 4, !tbaa !11
  %40 = zext i32 %39 to i64
  %41 = lshr i64 1152865209611504844, %40
  %42 = icmp ugt i64 %38, %41
  br label %43

43:                                               ; preds = %37, %34
  %44 = phi i1 [ false, %34 ], [ %42, %37 ]
  br i1 %44, label %46, label %45

45:                                               ; preds = %43
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %54

46:                                               ; preds = %43
  %47 = load i32, ptr %9, align 4, !tbaa !11
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %9, align 4, !tbaa !11
  %49 = load i64, ptr %11, align 8, !tbaa !9
  %50 = lshr i64 %49, 10
  store i64 %50, ptr %11, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %46
  %52 = load i32, ptr %13, align 4, !tbaa !11
  %53 = sub nsw i32 %52, 10
  store i32 %53, ptr %13, align 4, !tbaa !11
  br label %34, !llvm.loop !13

54:                                               ; preds = %45
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i64, ptr %6, align 8, !tbaa !9
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = uitofp i64 %57 to double
  %59 = fdiv double %58, 1.024000e+03
  %60 = load i32, ptr %9, align 4, !tbaa !11
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [6 x ptr], ptr %8, i64 0, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %55, i64 noundef %56, ptr noundef @.str.7, double noundef %59, ptr noundef %63) #4
  store i32 %64, ptr %10, align 4, !tbaa !11
  %65 = load i32, ptr %10, align 4, !tbaa !11
  %66 = icmp sle i32 %65, 0
  br i1 %66, label %72, label %67

67:                                               ; preds = %54
  %68 = load i32, ptr %10, align 4, !tbaa !11
  %69 = sext i32 %68 to i64
  %70 = load i64, ptr %6, align 8, !tbaa !9
  %71 = icmp uge i64 %69, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %67, %54
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %75

73:                                               ; preds = %67
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %74, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %75

75:                                               ; preds = %73, %72, %31, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr %8) #4
  %76 = load ptr, ptr %4, align 8
  ret ptr %76
}

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 "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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

@__const.sc_bytes_to_size.suffix = external hidden unnamed_addr constant [6 x ptr], align 16
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local ptr @sc_bytes_to_size(ptr noundef writeonly %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp ult i64 %2, 1024
  br i1 %4, label %6, label %.preheader

.preheader:                                       ; preds = %3
  %5 = icmp ugt i64 %2, 1048524
  br i1 %5, label %.lr.ph, label %._crit_edge

6:                                                ; preds = %3
  %7 = trunc nuw nsw i64 %2 to i32
  %8 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %0, i64 noundef %1, ptr noundef nonnull @.str.6, i32 noundef %7) #2
  br label %23

._crit_edge:                                      ; preds = %.lr.ph.3, %.lr.ph, %.lr.ph.1, %.lr.ph.2, %.preheader
  %.024.lcssa = phi i64 [ 0, %.preheader ], [ 1, %.lr.ph ], [ 2, %.lr.ph.1 ], [ 3, %.lr.ph.2 ], [ %spec.select, %.lr.ph.3 ]
  %.023.lcssa = phi i64 [ %2, %.preheader ], [ %14, %.lr.ph ], [ %16, %.lr.ph.1 ], [ %18, %.lr.ph.2 ], [ %spec.select44, %.lr.ph.3 ]
  %9 = uitofp nneg i64 %.023.lcssa to double
  %10 = fmul double %9, 0x3F50000000000000
  %11 = getelementptr inbounds [6 x ptr], ptr @__const.sc_bytes_to_size.suffix, i64 0, i64 %.024.lcssa
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %0, i64 noundef %1, ptr noundef nonnull @.str.7, double noundef %10, ptr noundef %12) #2
  br label %23

.lr.ph:                                           ; preds = %.preheader
  %14 = lshr i64 %2, 10
  %15 = icmp ugt i64 %2, 1073689395
  br i1 %15, label %.lr.ph.1, label %._crit_edge, !llvm.loop !9

.lr.ph.1:                                         ; preds = %.lr.ph
  %16 = lshr i64 %2, 20
  %17 = icmp ugt i64 %2, 1099457940684
  br i1 %17, label %.lr.ph.2, label %._crit_edge, !llvm.loop !9

.lr.ph.2:                                         ; preds = %.lr.ph.1
  %18 = lshr i64 %2, 30
  %19 = icmp ugt i64 %2, 1125844931261235
  br i1 %19, label %.lr.ph.3, label %._crit_edge, !llvm.loop !9

.lr.ph.3:                                         ; preds = %.lr.ph.2
  %20 = lshr i64 %2, 40
  %21 = icmp ugt i64 %2, 1152865209611504844
  %22 = lshr i64 %2, 50
  %spec.select = select i1 %21, i64 5, i64 4
  %spec.select44 = select i1 %21, i64 %22, i64 %20
  br label %._crit_edge, !llvm.loop !9

23:                                               ; preds = %._crit_edge, %6
  %.sink41 = phi i32 [ %13, %._crit_edge ], [ %8, %6 ]
  %24 = icmp sgt i32 %.sink41, 0
  %25 = zext nneg i32 %.sink41 to i64
  %.not = icmp ult i64 %25, %1
  %or.cond30 = select i1 %24, i1 %.not, i1 false
  %spec.select31 = select i1 %or.cond30, ptr %0, ptr null
  ret ptr %spec.select31
}

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) 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 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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