; 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.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 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
@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [4 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 i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @XKBToUnit(ptr noundef %0, i64 noundef %1, i64 noundef %2, i8 noundef zeroext %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca double, align 8
  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
  store i8 %3, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store double 0.000000e+00, ptr %10, align 8, !tbaa !12
  %11 = load i64, ptr %7, align 8, !tbaa !9
  %12 = icmp ugt i64 %11, 1073741824
  br i1 %12, label %13, label %22

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

22:                                               ; preds = %4
  %23 = load i64, ptr %7, align 8, !tbaa !9
  %24 = icmp ugt i64 %23, 1048576
  br i1 %24, label %25, label %34

25:                                               ; preds = %22
  %26 = load i64, ptr %7, align 8, !tbaa !9
  %27 = uitofp i64 %26 to double
  %28 = fdiv double %27, 0x4130000000000000
  store double %28, ptr %10, align 8, !tbaa !12
  %29 = load i8, ptr %8, align 1, !tbaa !11
  %30 = zext i8 %29 to i32
  %31 = icmp ne i32 %30, 0
  %32 = zext i1 %31 to i64
  %33 = select i1 %31, ptr @.str, ptr @.str.14
  store ptr %33, ptr %9, align 8, !tbaa !5
  br label %55

34:                                               ; preds = %22
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = icmp ugt i64 %35, 1024
  br i1 %36, label %37, label %46

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

46:                                               ; preds = %34
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = uitofp i64 %47 to double
  store double %48, ptr %10, align 8, !tbaa !12
  %49 = load i8, ptr %8, align 1, !tbaa !11
  %50 = zext i8 %49 to i32
  %51 = icmp ne i32 %50, 0
  %52 = zext i1 %51 to i64
  %53 = select i1 %51, ptr @.str.4, ptr @.str.16
  store ptr %53, ptr %9, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %46, %37
  br label %55

55:                                               ; preds = %54, %25
  br label %56

56:                                               ; preds = %55, %13
  %57 = load i8, ptr %8, align 1, !tbaa !11
  %58 = zext i8 %57 to i32
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %66

60:                                               ; preds = %56
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load i64, ptr %6, align 8, !tbaa !9
  %63 = load double, ptr %10, align 8, !tbaa !12
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %61, i64 noundef %62, ptr noundef @.str.10, double noundef %63, ptr noundef %64)
  br label %72

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

72:                                               ; preds = %66, %60
  %73 = phi i64 [ %65, %60 ], [ %71, %66 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i64 %73
}

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 }

!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.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 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
@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

6:                                                ; preds = %4
  %7 = uitofp i64 %2 to double
  %8 = fmul double %7, 0x3E10000000000000
  %.not23 = icmp eq i8 %3, 0
  %9 = select i1 %.not23, ptr @.str.13, ptr @.str.12
  br label %24

10:                                               ; preds = %4
  %11 = icmp ugt i64 %2, 1048576
  br i1 %11, label %12, label %16

12:                                               ; preds = %10
  %13 = uitofp nneg i64 %2 to double
  %14 = fmul double %13, 0x3EB0000000000000
  %.not22 = icmp eq i8 %3, 0
  %15 = select i1 %.not22, ptr @.str.14, ptr @.str
  br label %24

16:                                               ; preds = %10
  %17 = icmp ugt i64 %2, 1024
  %18 = uitofp nneg i64 %2 to double
  br i1 %17, label %19, label %22

19:                                               ; preds = %16
  %20 = fmul double %18, 0x3F50000000000000
  %.not21 = icmp eq i8 %3, 0
  %21 = select i1 %.not21, ptr @.str.15, ptr @.str.2
  br label %24

22:                                               ; preds = %16
  %.not = icmp eq i8 %3, 0
  %23 = select i1 %.not, ptr @.str.16, ptr @.str.4
  br label %24

24:                                               ; preds = %12, %22, %19, %6
  %.019 = phi ptr [ %9, %6 ], [ %15, %12 ], [ %21, %19 ], [ %23, %22 ]
  %.0 = phi double [ %8, %6 ], [ %14, %12 ], [ %20, %19 ], [ %18, %22 ]
  %.not24 = icmp eq i8 %3, 0
  %.str.11..str.10 = select i1 %.not24, ptr @.str.11, ptr @.str.10
  %25 = tail call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %0, i64 noundef %1, ptr noundef nonnull %.str.11..str.10, double noundef %.0, ptr noundef nonnull %.019) #2
  ret i64 %25
}

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


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