; LLVM IR from kala13x/libxutils :: tools (xtop)

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

%struct.xcli_bar_ = type { %struct.xcli_size_, i64, i64, i32, i32, i8, i8, i8, i8, double, i32, i8, i8, i8, i8, i8, i8, [256 x i8], [256 x i8], [256 x i8] }
%struct.xcli_size_ = type { i64, i64 }
%struct.XMemInfo = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }

@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.65 = external hidden unnamed_addr constant [13 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

declare i64 @xstrnfill(ptr noundef, i64 noundef, i64 noundef, i8 noundef signext) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XTOPApp_FillSwapBar(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca [2048 x i8], align 16
  %11 = alloca [2048 x i8], align 16
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %25, label %22

22:                                               ; preds = %4
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %22, %4
  store i32 0, ptr %5, align 4
  br label %133

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 2048, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 2048, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.xcli_bar_, ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !11
  store i64 %29, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.xcli_bar_, ptr %30, i32 0, i32 2
  %32 = load i64, ptr %31, align 8, !tbaa !16
  store i64 %32, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.XMemInfo, ptr %33, i32 0, i32 9
  %35 = load i64, ptr %34, align 8, !tbaa !17
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.XMemInfo, ptr %36, i32 0, i32 10
  %38 = load i64, ptr %37, align 8, !tbaa !19
  %39 = sub i64 %35, %38
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.XMemInfo, ptr %40, i32 0, i32 8
  %42 = load i64, ptr %41, align 8, !tbaa !20
  %43 = sub i64 %39, %42
  store i64 %43, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %44 = load i64, ptr %14, align 8, !tbaa !9
  %45 = icmp ne i64 %44, 0
  br i1 %45, label %46, label %55

46:                                               ; preds = %26
  %47 = load i64, ptr %14, align 8, !tbaa !9
  %48 = uitofp i64 %47 to double
  %49 = fdiv double 1.000000e+02, %48
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.XMemInfo, ptr %50, i32 0, i32 8
  %52 = load i64, ptr %51, align 8, !tbaa !20
  %53 = uitofp i64 %52 to double
  %54 = fmul double %49, %53
  br label %56

55:                                               ; preds = %26
  br label %56

56:                                               ; preds = %55, %46
  %57 = phi double [ %54, %46 ], [ 0.000000e+00, %55 ]
  store double %57, ptr %15, align 8, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %58 = load i64, ptr %14, align 8, !tbaa !9
  %59 = icmp ne i64 %58, 0
  br i1 %59, label %60, label %69

60:                                               ; preds = %56
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.XMemInfo, ptr %61, i32 0, i32 9
  %63 = load i64, ptr %62, align 8, !tbaa !17
  %64 = uitofp i64 %63 to double
  %65 = fdiv double 1.000000e+02, %64
  %66 = load i64, ptr %14, align 8, !tbaa !9
  %67 = uitofp i64 %66 to double
  %68 = fmul double %65, %67
  br label %70

69:                                               ; preds = %56
  br label %70

70:                                               ; preds = %69, %60
  %71 = phi double [ %68, %60 ], [ 0.000000e+00, %69 ]
  store double %71, ptr %16, align 8, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %72 = load i64, ptr %13, align 8, !tbaa !9
  %73 = load double, ptr %15, align 8, !tbaa !21
  %74 = call double @llvm.floor.f64(double %73)
  %75 = fptoui double %74 to i64
  %76 = mul i64 %72, %75
  %77 = udiv i64 %76, 100
  store i64 %77, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %78 = load i64, ptr %13, align 8, !tbaa !9
  %79 = load double, ptr %16, align 8, !tbaa !21
  %80 = call double @llvm.floor.f64(double %79)
  %81 = fptoui double %80 to i64
  %82 = mul i64 %78, %81
  %83 = udiv i64 %82, 100
  store i64 %83, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %84 = load i64, ptr %18, align 8, !tbaa !9
  %85 = load i64, ptr %17, align 8, !tbaa !9
  %86 = add i64 %84, %85
  store i64 %86, ptr %19, align 8, !tbaa !9
  %87 = load double, ptr %15, align 8, !tbaa !21
  %88 = fcmp ogt double %87, 0.000000e+00
  br i1 %88, label %89, label %101

89:                                               ; preds = %70
  %90 = load i64, ptr %17, align 8, !tbaa !9
  %91 = icmp ne i64 %90, 0
  br i1 %91, label %101, label %92

92:                                               ; preds = %89
  %93 = load i64, ptr %19, align 8, !tbaa !9
  %94 = load i64, ptr %12, align 8, !tbaa !9
  %95 = icmp ult i64 %93, %94
  br i1 %95, label %96, label %101

96:                                               ; preds = %92
  %97 = load i64, ptr %17, align 8, !tbaa !9
  %98 = add i64 %97, 1
  store i64 %98, ptr %17, align 8, !tbaa !9
  %99 = load i64, ptr %19, align 8, !tbaa !9
  %100 = add i64 %99, 1
  store i64 %100, ptr %19, align 8, !tbaa !9
  br label %101

101:                                              ; preds = %96, %92, %89, %70
  %102 = load double, ptr %16, align 8, !tbaa !21
  %103 = fcmp ogt double %102, 0.000000e+00
  br i1 %103, label %104, label %114

104:                                              ; preds = %101
  %105 = load i64, ptr %18, align 8, !tbaa !9
  %106 = icmp ne i64 %105, 0
  br i1 %106, label %114, label %107

107:                                              ; preds = %104
  %108 = load i64, ptr %19, align 8, !tbaa !9
  %109 = load i64, ptr %12, align 8, !tbaa !9
  %110 = icmp ult i64 %108, %109
  br i1 %110, label %111, label %114

111:                                              ; preds = %107
  %112 = load i64, ptr %18, align 8, !tbaa !9
  %113 = add i64 %112, 1
  store i64 %113, ptr %18, align 8, !tbaa !9
  br label %114

114:                                              ; preds = %111, %107, %104, %101
  %115 = getelementptr inbounds [2048 x i8], ptr %11, i64 0, i64 0
  %116 = load i64, ptr %17, align 8, !tbaa !9
  %117 = load ptr, ptr %6, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.xcli_bar_, ptr %117, i32 0, i32 13
  %119 = load i8, ptr %118, align 2, !tbaa !22
  %120 = call i64 @xstrnfill(ptr noundef %115, i64 noundef 2048, i64 noundef %116, i8 noundef signext %119)
  %121 = getelementptr inbounds [2048 x i8], ptr %10, i64 0, i64 0
  %122 = load i64, ptr %18, align 8, !tbaa !9
  %123 = load ptr, ptr %6, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.xcli_bar_, ptr %123, i32 0, i32 13
  %125 = load i8, ptr %124, align 2, !tbaa !22
  %126 = call i64 @xstrnfill(ptr noundef %121, i64 noundef 2048, i64 noundef %122, i8 noundef signext %125)
  %127 = load ptr, ptr %8, align 8, !tbaa !5
  %128 = load i64, ptr %9, align 8, !tbaa !9
  %129 = getelementptr inbounds [2048 x i8], ptr %10, i64 0, i64 0
  %130 = getelementptr inbounds [2048 x i8], ptr %11, i64 0, i64 0
  %131 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %127, i64 noundef %128, ptr noundef @.str.65, ptr noundef @.str.9, ptr noundef %129, ptr noundef @.str.6, ptr noundef @.str.14, ptr noundef %130, ptr noundef @.str.6)
  %132 = trunc i64 %131 to i32
  store i32 %132, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 2048, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 2048, ptr %10) #4
  br label %133

133:                                              ; preds = %114, %25
  %134 = load i32, ptr %5, align 4
  ret i32 %134
}

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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, !10, i64 16}
!12 = !{!"xcli_bar_", !13, i64 0, !10, i64 16, !10, i64 24, !14, i64 32, !14, i64 36, !7, i64 40, !7, i64 41, !7, i64 42, !7, i64 43, !15, i64 48, !14, i64 56, !7, i64 60, !7, i64 61, !7, i64 62, !7, i64 63, !7, i64 64, !7, i64 65, !7, i64 66, !7, i64 322, !7, i64 578}
!13 = !{!"xcli_size_", !10, i64 0, !10, i64 8}
!14 = !{!"int", !7, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!12, !10, i64 24}
!17 = !{!18, !10, i64 72}
!18 = !{!"XMemInfo", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88}
!19 = !{!18, !10, i64 80}
!20 = !{!18, !10, i64 64}
!21 = !{!15, !15, i64 0}
!22 = !{!12, !7, i64 62}


; 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.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.65 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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, ...) local_unnamed_addr #1

declare i64 @xstrnfill(ptr noundef, i64 noundef, i64 noundef, i8 noundef signext) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XTOPApp_FillSwapBar(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #3 {
  %5 = alloca [2048 x i8], align 16
  %6 = alloca [2048 x i8], align 16
  %7 = icmp ne ptr %2, null
  %8 = icmp ne i64 %3, 0
  %or.cond = and i1 %7, %8
  br i1 %or.cond, label %9, label %53

9:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %6) #4
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %1, i64 72
  %15 = load i64, ptr %14, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %1, i64 80
  %17 = load i64, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %1, i64 64
  %19 = load i64, ptr %18, align 8, !tbaa !17
  %20 = add i64 %19, %17
  %21 = sub i64 %15, %20
  %.not = icmp eq i64 %15, %20
  %22 = uitofp i64 %21 to double
  %23 = fdiv double 1.000000e+02, %22
  %24 = uitofp i64 %19 to double
  %25 = fmul double %23, %24
  %26 = select i1 %.not, double 0.000000e+00, double %25
  %27 = uitofp i64 %15 to double
  %28 = fdiv double 1.000000e+02, %27
  %29 = fmul double %28, %22
  %30 = select i1 %.not, double 0.000000e+00, double %29
  %31 = tail call double @llvm.floor.f64(double %26)
  %32 = fptoui double %31 to i64
  %33 = mul i64 %13, %32
  %34 = udiv i64 %33, 100
  %35 = tail call double @llvm.floor.f64(double %30)
  %36 = fptoui double %35 to i64
  %37 = mul i64 %13, %36
  %38 = udiv i64 %37, 100
  %39 = add nuw nsw i64 %34, %38
  %40 = fcmp ogt double %26, 0.000000e+00
  %41 = icmp ult i64 %33, 100
  %or.cond3.not = and i1 %40, %41
  %42 = icmp ult i64 %39, %11
  %spec.select = zext i1 %42 to i64
  %.042 = select i1 %or.cond3.not, i64 %spec.select, i64 %34
  %narrow = select i1 %or.cond3.not, i1 %42, i1 false
  %spec.select51 = zext i1 %narrow to i64
  %.0 = add nuw nsw i64 %39, %spec.select51
  %43 = fcmp ule double %30, 0.000000e+00
  %44 = icmp ugt i64 %37, 99
  %or.cond5 = select i1 %43, i1 true, i1 %44
  %45 = icmp ult i64 %.0, %11
  %spec.select52 = zext i1 %45 to i64
  %.041 = select i1 %or.cond5, i64 %38, i64 %spec.select52
  %46 = getelementptr inbounds i8, ptr %0, i64 62
  %47 = load i8, ptr %46, align 2, !tbaa !18
  %48 = call i64 @xstrnfill(ptr noundef nonnull %6, i64 noundef 2048, i64 noundef %.042, i8 noundef signext %47) #4
  %49 = load i8, ptr %46, align 2, !tbaa !18
  %50 = call i64 @xstrnfill(ptr noundef nonnull %5, i64 noundef 2048, i64 noundef %.041, i8 noundef signext %49) #4
  %51 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %2, i64 noundef %3, ptr noundef nonnull @.str.65, ptr noundef nonnull @.str.9, ptr noundef nonnull %5, ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.14, ptr noundef nonnull %6, ptr noundef nonnull @.str.6) #4
  %52 = trunc i64 %51 to i32
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %5) #4
  br label %53

53:                                               ; preds = %4, %9
  %.043 = phi i32 [ %52, %9 ], [ 0, %4 ]
  ret i32 %.043
}

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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, !8, i64 16}
!6 = !{!"xcli_bar_", !7, i64 0, !8, i64 16, !8, i64 24, !11, i64 32, !11, i64 36, !9, i64 40, !9, i64 41, !9, i64 42, !9, i64 43, !12, i64 48, !11, i64 56, !9, i64 60, !9, i64 61, !9, i64 62, !9, i64 63, !9, i64 64, !9, i64 65, !9, i64 66, !9, i64 322, !9, i64 578}
!7 = !{!"xcli_size_", !8, i64 0, !8, i64 8}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"double", !9, i64 0}
!13 = !{!6, !8, i64 24}
!14 = !{!15, !8, i64 72}
!15 = !{!"XMemInfo", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88}
!16 = !{!15, !8, i64 80}
!17 = !{!15, !8, i64 64}
!18 = !{!6, !9, i64 62}


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