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

@pp1_before = external dso_local global double, align 8
@dram_before = external dso_local global double, align 8
@cpu_model = external dso_local global i32, align 4
@energy_units = external dso_local global double, align 8
@package_before = external dso_local global double, align 8
@pp0_before = external dso_local global double, align 8
@package_after = external dso_local global double, align 8
@.str.32 = external hidden unnamed_addr constant [8 x i8], align 1
@pp0_after = external dso_local global double, align 8
@pp1_after = external dso_local global double, align 8
@.str.33 = external hidden unnamed_addr constant [4 x i8], align 1
@dram_after = external dso_local global double, align 8

; 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; 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

; Function Attrs: nounwind uwtable
define dso_local void @rapl_after(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = call i32 @open_msr(i32 noundef %7)
  store i32 %8, ptr %5, align 4, !tbaa !9
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = call i64 @read_msr(i32 noundef %9, i32 noundef 1553)
  store i64 %10, ptr %6, align 8, !tbaa !11
  %11 = load i64, ptr %6, align 8, !tbaa !11
  %12 = sitofp i64 %11 to double
  %13 = load double, ptr @energy_units, align 8, !tbaa !13
  %14 = fmul double %12, %13
  store double %14, ptr @package_after, align 8, !tbaa !13
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load double, ptr @package_after, align 8, !tbaa !13
  %17 = load double, ptr @package_before, align 8, !tbaa !13
  %18 = fsub double %16, %17
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str.32, double noundef %18) #3
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = call i64 @read_msr(i32 noundef %20, i32 noundef 1593)
  store i64 %21, ptr %6, align 8, !tbaa !11
  %22 = load i64, ptr %6, align 8, !tbaa !11
  %23 = sitofp i64 %22 to double
  %24 = load double, ptr @energy_units, align 8, !tbaa !13
  %25 = fmul double %23, %24
  store double %25, ptr @pp0_after, align 8, !tbaa !13
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load double, ptr @pp0_after, align 8, !tbaa !13
  %28 = load double, ptr @pp0_before, align 8, !tbaa !13
  %29 = fsub double %27, %28
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef @.str.32, double noundef %29) #3
  %31 = load i32, ptr @cpu_model, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 42
  br i1 %32, label %39, label %33

33:                                               ; preds = %2
  %34 = load i32, ptr @cpu_model, align 4, !tbaa !9
  %35 = icmp eq i32 %34, 58
  br i1 %35, label %39, label %36

36:                                               ; preds = %33
  %37 = load i32, ptr @cpu_model, align 4, !tbaa !9
  %38 = icmp eq i32 %37, 60
  br i1 %38, label %39, label %51

39:                                               ; preds = %36, %33, %2
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = call i64 @read_msr(i32 noundef %40, i32 noundef 1601)
  store i64 %41, ptr %6, align 8, !tbaa !11
  %42 = load i64, ptr %6, align 8, !tbaa !11
  %43 = sitofp i64 %42 to double
  %44 = load double, ptr @energy_units, align 8, !tbaa !13
  %45 = fmul double %43, %44
  store double %45, ptr @pp1_after, align 8, !tbaa !13
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load double, ptr @pp1_after, align 8, !tbaa !13
  %48 = load double, ptr @pp1_before, align 8, !tbaa !13
  %49 = fsub double %47, %48
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str.32, double noundef %49) #3
  br label %54

51:                                               ; preds = %36
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str.33) #3
  br label %54

54:                                               ; preds = %51, %39
  %55 = load i32, ptr @cpu_model, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 45
  br i1 %56, label %63, label %57

57:                                               ; preds = %54
  %58 = load i32, ptr @cpu_model, align 4, !tbaa !9
  %59 = icmp eq i32 %58, 62
  br i1 %59, label %63, label %60

60:                                               ; preds = %57
  %61 = load i32, ptr @cpu_model, align 4, !tbaa !9
  %62 = icmp eq i32 %61, 60
  br i1 %62, label %63, label %75

63:                                               ; preds = %60, %57, %54
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = call i64 @read_msr(i32 noundef %64, i32 noundef 1561)
  store i64 %65, ptr %6, align 8, !tbaa !11
  %66 = load i64, ptr %6, align 8, !tbaa !11
  %67 = sitofp i64 %66 to double
  %68 = load double, ptr @energy_units, align 8, !tbaa !13
  %69 = fmul double %67, %68
  store double %69, ptr @dram_after, align 8, !tbaa !13
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = load double, ptr @dram_after, align 8, !tbaa !13
  %72 = load double, ptr @dram_before, align 8, !tbaa !13
  %73 = fsub double %71, %72
  %74 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str.32, double noundef %73) #3
  br label %78

75:                                               ; preds = %60
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %76, ptr noundef @.str.33) #3
  br label %78

78:                                               ; preds = %75, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #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 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"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"

@pp1_before = external dso_local local_unnamed_addr global double, align 8
@dram_before = external dso_local local_unnamed_addr global double, align 8
@cpu_model = external dso_local local_unnamed_addr global i32, align 4
@energy_units = external dso_local local_unnamed_addr global double, align 8
@package_before = external dso_local local_unnamed_addr global double, align 8
@pp0_before = external dso_local local_unnamed_addr global double, align 8
@package_after = external dso_local local_unnamed_addr global double, align 8
@.str.32 = external hidden unnamed_addr constant [8 x i8], align 1
@pp0_after = external dso_local local_unnamed_addr global double, align 8
@pp1_after = external dso_local local_unnamed_addr global double, align 8
@.str.33 = external hidden unnamed_addr constant [4 x i8], align 1
@dram_after = external dso_local local_unnamed_addr global double, align 8

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @rapl_after(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @open_msr(i32 noundef %1)
  %4 = tail call i64 @read_msr(i32 noundef %3, i32 noundef 1553)
  %5 = sitofp i64 %4 to double
  %6 = load double, ptr @energy_units, align 8, !tbaa !5
  %7 = fmul double %6, %5
  store double %7, ptr @package_after, align 8, !tbaa !5
  %8 = load double, ptr @package_before, align 8, !tbaa !5
  %9 = fsub double %7, %8
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.32, double noundef %9) #2
  %11 = tail call i64 @read_msr(i32 noundef %3, i32 noundef 1593)
  %12 = sitofp i64 %11 to double
  %13 = load double, ptr @energy_units, align 8, !tbaa !5
  %14 = fmul double %13, %12
  store double %14, ptr @pp0_after, align 8, !tbaa !5
  %15 = load double, ptr @pp0_before, align 8, !tbaa !5
  %16 = fsub double %14, %15
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.32, double noundef %16) #2
  %18 = load i32, ptr @cpu_model, align 4
  switch i32 %18, label %27 [
    i32 60, label %19
    i32 58, label %19
    i32 42, label %19
  ]

19:                                               ; preds = %2, %2, %2
  %20 = tail call i64 @read_msr(i32 noundef %3, i32 noundef 1601)
  %21 = sitofp i64 %20 to double
  %22 = load double, ptr @energy_units, align 8, !tbaa !5
  %23 = fmul double %22, %21
  store double %23, ptr @pp1_after, align 8, !tbaa !5
  %24 = load double, ptr @pp1_before, align 8, !tbaa !5
  %25 = fsub double %23, %24
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.32, double noundef %25) #2
  br label %29

27:                                               ; preds = %2
  %28 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.33) #2
  br label %29

29:                                               ; preds = %27, %19
  %30 = load i32, ptr @cpu_model, align 4
  switch i32 %30, label %39 [
    i32 62, label %31
    i32 60, label %31
    i32 45, label %31
  ]

31:                                               ; preds = %29, %29, %29
  %32 = tail call i64 @read_msr(i32 noundef %3, i32 noundef 1561)
  %33 = sitofp i64 %32 to double
  %34 = load double, ptr @energy_units, align 8, !tbaa !5
  %35 = fmul double %34, %33
  store double %35, ptr @dram_after, align 8, !tbaa !5
  %36 = load double, ptr @dram_before, align 8, !tbaa !5
  %37 = fsub double %35, %36
  %38 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.32, double noundef %37) #2
  br label %41

39:                                               ; preds = %29
  %40 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.33) #2
  br label %41

41:                                               ; preds = %39, %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" }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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