; LLVM IR from greensoftwarelab/Energy-Languages :: RAPL (rapl)

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

@power_units = external dso_local global double, align 8
@time_units = external dso_local global double, align 8
@.str.22 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @open_msr(i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @read_msr(i32 noundef, i32 noundef) #0

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local void @show_power_limit(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = call i32 @open_msr(i32 noundef %9)
  store i32 %10, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = call i64 @read_msr(i32 noundef %11, i32 noundef 1552)
  store i64 %12, ptr %4, align 8, !tbaa !9
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = ashr i64 %13, 63
  %15 = icmp ne i64 %14, 0
  %16 = zext i1 %15 to i64
  %17 = select i1 %15, ptr @.str.23, ptr @.str.24
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.22, ptr noundef %17)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %19 = load double, ptr @power_units, align 8, !tbaa !11
  %20 = load i64, ptr %4, align 8, !tbaa !9
  %21 = ashr i64 %20, 0
  %22 = and i64 %21, 32767
  %23 = sitofp i64 %22 to double
  %24 = fmul double %19, %23
  store double %24, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %25 = load double, ptr @time_units, align 8, !tbaa !11
  %26 = load i64, ptr %4, align 8, !tbaa !9
  %27 = ashr i64 %26, 17
  %28 = and i64 %27, 127
  %29 = sitofp i64 %28 to double
  %30 = fmul double %25, %29
  store double %30, ptr %6, align 8, !tbaa !11
  %31 = load double, ptr %5, align 8, !tbaa !11
  %32 = load double, ptr %6, align 8, !tbaa !11
  %33 = load i64, ptr %4, align 8, !tbaa !9
  %34 = and i64 %33, 32768
  %35 = icmp ne i64 %34, 0
  %36 = zext i1 %35 to i64
  %37 = select i1 %35, ptr @.str.26, ptr @.str.27
  %38 = load i64, ptr %4, align 8, !tbaa !9
  %39 = and i64 %38, 65536
  %40 = icmp ne i64 %39, 0
  %41 = zext i1 %40 to i64
  %42 = select i1 %40, ptr @.str.28, ptr @.str.29
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.25, double noundef %31, double noundef %32, ptr noundef %37, ptr noundef %42)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %44 = load double, ptr @power_units, align 8, !tbaa !11
  %45 = load i64, ptr %4, align 8, !tbaa !9
  %46 = ashr i64 %45, 32
  %47 = and i64 %46, 32767
  %48 = sitofp i64 %47 to double
  %49 = fmul double %44, %48
  store double %49, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %50 = load double, ptr @time_units, align 8, !tbaa !11
  %51 = load i64, ptr %4, align 8, !tbaa !9
  %52 = ashr i64 %51, 49
  %53 = and i64 %52, 127
  %54 = sitofp i64 %53 to double
  %55 = fmul double %50, %54
  store double %55, ptr %8, align 8, !tbaa !11
  %56 = load double, ptr %7, align 8, !tbaa !11
  %57 = load double, ptr %8, align 8, !tbaa !11
  %58 = load i64, ptr %4, align 8, !tbaa !9
  %59 = and i64 %58, 140737488355328
  %60 = icmp ne i64 %59, 0
  %61 = zext i1 %60 to i64
  %62 = select i1 %60, ptr @.str.26, ptr @.str.27
  %63 = load i64, ptr %4, align 8, !tbaa !9
  %64 = and i64 %63, 281474976710656
  %65 = icmp ne i64 %64, 0
  %66 = zext i1 %65 to i64
  %67 = select i1 %65, ptr @.str.28, ptr @.str.29
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.30, double noundef %56, double noundef %57, ptr noundef %62, ptr noundef %67)
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.31)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"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"

@power_units = external dso_local local_unnamed_addr global double, align 8
@time_units = external dso_local local_unnamed_addr global double, align 8
@.str.22 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @open_msr(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @read_msr(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @show_power_limit(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @open_msr(i32 noundef %0)
  %3 = tail call i64 @read_msr(i32 noundef %2, i32 noundef 1552)
  %.not = icmp sgt i64 %3, -1
  %4 = select i1 %.not, ptr @.str.24, ptr @.str.23
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.22, ptr noundef nonnull %4)
  %6 = load double, ptr @power_units, align 8, !tbaa !5
  %7 = and i64 %3, 32767
  %8 = uitofp nneg i64 %7 to double
  %9 = fmul double %6, %8
  %10 = load double, ptr @time_units, align 8, !tbaa !5
  %11 = lshr i64 %3, 17
  %12 = and i64 %11, 127
  %13 = uitofp nneg i64 %12 to double
  %14 = fmul double %10, %13
  %15 = and i64 %3, 32768
  %.not14 = icmp eq i64 %15, 0
  %16 = select i1 %.not14, ptr @.str.27, ptr @.str.26
  %17 = and i64 %3, 65536
  %.not15 = icmp eq i64 %17, 0
  %18 = select i1 %.not15, ptr @.str.29, ptr @.str.28
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.25, double noundef %9, double noundef %14, ptr noundef nonnull %16, ptr noundef nonnull %18)
  %20 = load double, ptr @power_units, align 8, !tbaa !5
  %21 = lshr i64 %3, 32
  %22 = and i64 %21, 32767
  %23 = uitofp nneg i64 %22 to double
  %24 = fmul double %20, %23
  %25 = load double, ptr @time_units, align 8, !tbaa !5
  %26 = lshr i64 %3, 49
  %27 = and i64 %26, 127
  %28 = uitofp nneg i64 %27 to double
  %29 = fmul double %25, %28
  %30 = and i64 %3, 140737488355328
  %.not16 = icmp eq i64 %30, 0
  %31 = select i1 %.not16, ptr @.str.27, ptr @.str.26
  %32 = and i64 %3, 281474976710656
  %.not17 = icmp eq i64 %32, 0
  %33 = select i1 %.not17, ptr @.str.29, ptr @.str.28
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.30, double noundef %24, double noundef %29, ptr noundef nonnull %31, ptr noundef nonnull %33)
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.31)
  ret void
}

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

!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"}


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