; LLVM IR from kala13x/libxutils :: src/sys (type)

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

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [8 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

; Function Attrs: nounwind uwtable
define dso_local i64 @XBytesToUnit(ptr noundef %0, i64 noundef %1, i64 noundef %2, i8 noundef zeroext %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i8 %3, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store double 0.000000e+00, ptr %11, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #3
  store i8 0, ptr %12, align 1, !tbaa !11
  %14 = load i64, ptr %8, align 8, !tbaa !9
  %15 = icmp ugt i64 %14, 1073741824
  br i1 %15, label %16, label %25

16:                                               ; preds = %4
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = uitofp i64 %17 to double
  %19 = fdiv double %18, 0x41D0000000000000
  store double %19, ptr %11, align 8, !tbaa !12
  %20 = load i8, ptr %9, align 1, !tbaa !11
  %21 = zext i8 %20 to i32
  %22 = icmp ne i32 %21, 0
  %23 = zext i1 %22 to i64
  %24 = select i1 %22, ptr @.str, ptr @.str.1
  store ptr %24, ptr %10, align 8, !tbaa !5
  store i8 1, ptr %12, align 1, !tbaa !11
  br label %59

25:                                               ; preds = %4
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = icmp ugt i64 %26, 1048576
  br i1 %27, label %28, label %37

28:                                               ; preds = %25
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = uitofp i64 %29 to double
  %31 = fdiv double %30, 0x4130000000000000
  store double %31, ptr %11, align 8, !tbaa !12
  %32 = load i8, ptr %9, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  %34 = icmp ne i32 %33, 0
  %35 = zext i1 %34 to i64
  %36 = select i1 %34, ptr @.str.2, ptr @.str.3
  store ptr %36, ptr %10, align 8, !tbaa !5
  br label %58

37:                                               ; preds = %25
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = icmp ugt i64 %38, 1024
  br i1 %39, label %40, label %49

40:                                               ; preds = %37
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = uitofp i64 %41 to double
  %43 = fdiv double %42, 1.024000e+03
  store double %43, ptr %11, align 8, !tbaa !12
  %44 = load i8, ptr %9, align 1, !tbaa !11
  %45 = zext i8 %44 to i32
  %46 = icmp ne i32 %45, 0
  %47 = zext i1 %46 to i64
  %48 = select i1 %46, ptr @.str.4, ptr @.str.5
  store ptr %48, ptr %10, align 8, !tbaa !5
  br label %57

49:                                               ; preds = %37
  %50 = load i64, ptr %8, align 8, !tbaa !9
  %51 = uitofp i64 %50 to double
  store double %51, ptr %11, align 8, !tbaa !12
  %52 = load i8, ptr %9, align 1, !tbaa !11
  %53 = zext i8 %52 to i32
  %54 = icmp ne i32 %53, 0
  %55 = zext i1 %54 to i64
  %56 = select i1 %54, ptr @.str.6, ptr @.str.7
  store ptr %56, ptr %10, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %49, %40
  br label %58

58:                                               ; preds = %57, %28
  br label %59

59:                                               ; preds = %58, %16
  %60 = load i8, ptr %12, align 1, !tbaa !11
  %61 = icmp ne i8 %60, 0
  br i1 %61, label %62, label %80

62:                                               ; preds = %59
  %63 = load i8, ptr %9, align 1, !tbaa !11
  %64 = zext i8 %63 to i32
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %72

66:                                               ; preds = %62
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load i64, ptr %7, align 8, !tbaa !9
  %69 = load double, ptr %11, align 8, !tbaa !12
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %67, i64 noundef %68, ptr noundef @.str.8, double noundef %69, ptr noundef %70)
  br label %78

72:                                               ; preds = %62
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load i64, ptr %7, align 8, !tbaa !9
  %75 = load double, ptr %11, align 8, !tbaa !12
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %73, i64 noundef %74, ptr noundef @.str.9, double noundef %75, ptr noundef %76)
  br label %78

78:                                               ; preds = %72, %66
  %79 = phi i64 [ %71, %66 ], [ %77, %72 ]
  store i64 %79, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %98

80:                                               ; preds = %59
  %81 = load i8, ptr %9, align 1, !tbaa !11
  %82 = zext i8 %81 to i32
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %90

84:                                               ; preds = %80
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = load i64, ptr %7, align 8, !tbaa !9
  %87 = load double, ptr %11, align 8, !tbaa !12
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %85, i64 noundef %86, ptr noundef @.str.10, double noundef %87, ptr noundef %88)
  br label %96

90:                                               ; preds = %80
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = load i64, ptr %7, align 8, !tbaa !9
  %93 = load double, ptr %11, align 8, !tbaa !12
  %94 = load ptr, ptr %10, align 8, !tbaa !5
  %95 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %91, i64 noundef %92, ptr noundef @.str.11, double noundef %93, ptr noundef %94)
  br label %96

96:                                               ; preds = %90, %84
  %97 = phi i64 [ %89, %84 ], [ %95, %90 ]
  store i64 %97, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %98

98:                                               ; preds = %96, %78
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %99 = load i64, ptr %5, align 8
  ret i64 %99
}

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr 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 = { "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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}


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

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @XBytesToUnit(ptr noundef %0, i64 noundef %1, i64 noundef %2, i8 noundef zeroext %3) local_unnamed_addr #0 {
  %5 = icmp ult i64 %2, 1073741825
  br i1 %5, label %6, label %20

6:                                                ; preds = %4
  %7 = icmp ugt i64 %2, 1048576
  br i1 %7, label %8, label %12

8:                                                ; preds = %6
  %9 = uitofp nneg i64 %2 to double
  %10 = fmul double %9, 0x3EB0000000000000
  %.not35 = icmp eq i8 %3, 0
  %11 = select i1 %.not35, ptr @.str.3, ptr @.str.2
  br label %27

12:                                               ; preds = %6
  %13 = icmp ugt i64 %2, 1024
  %14 = uitofp nneg i64 %2 to double
  br i1 %13, label %15, label %18

15:                                               ; preds = %12
  %16 = fmul double %14, 0x3F50000000000000
  %.not34 = icmp eq i8 %3, 0
  %17 = select i1 %.not34, ptr @.str.5, ptr @.str.4
  br label %27

18:                                               ; preds = %12
  %.not = icmp eq i8 %3, 0
  %19 = select i1 %.not, ptr @.str.7, ptr @.str.6
  br label %27

20:                                               ; preds = %4
  %21 = uitofp i64 %2 to double
  %22 = fmul double %21, 0x3E10000000000000
  %.not39 = icmp eq i8 %3, 0
  br i1 %.not39, label %25, label %23

23:                                               ; preds = %20
  %24 = tail call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %0, i64 noundef %1, ptr noundef nonnull @.str.8, double noundef %22, ptr noundef nonnull @.str) #2
  br label %32

25:                                               ; preds = %20
  %26 = tail call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %0, i64 noundef %1, ptr noundef nonnull @.str.9, double noundef %22, ptr noundef nonnull @.str.1) #2
  br label %32

27:                                               ; preds = %8, %18, %15
  %.031.ph = phi ptr [ %19, %18 ], [ %17, %15 ], [ %11, %8 ]
  %.030.ph = phi double [ %14, %18 ], [ %16, %15 ], [ %10, %8 ]
  %.not38 = icmp eq i8 %3, 0
  br i1 %.not38, label %30, label %28

28:                                               ; preds = %27
  %29 = tail call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %0, i64 noundef %1, ptr noundef nonnull @.str.10, double noundef %.030.ph, ptr noundef nonnull %.031.ph) #2
  br label %32

30:                                               ; preds = %27
  %31 = tail call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %0, i64 noundef %1, ptr noundef nonnull @.str.11, double noundef %.030.ph, ptr noundef nonnull %.031.ph) #2
  br label %32

32:                                               ; preds = %28, %30, %23, %25
  %.032 = phi i64 [ %24, %23 ], [ %26, %25 ], [ %29, %28 ], [ %31, %30 ]
  ret i64 %.032
}

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #1

attributes #0 = { 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 = { "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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass