; LLVM IR from simonaertssen/MIT-6.172-Performance-Engineering-of-Software-Systems :: Project 1 - Bit Hacks/everybit (tests)

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

@test_verbose = external hidden global i8, align 1
@fibs = external dso_local constant [54 x double], align 16
@.str.9 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [64 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 i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @timed_rotation(double noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca double, align 8
  %10 = alloca [20 x i8], align 16
  %11 = alloca i32, align 4
  store double %0, ptr %3, align 8, !tbaa !5
  store i8 0, ptr @test_verbose, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !11
  br label %12

12:                                               ; preds = %97, %1
  %13 = load i32, ptr %4, align 4, !tbaa !11
  %14 = add nsw i32 %13, 3
  %15 = icmp slt i32 %14, 54
  br i1 %15, label %16, label %98

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %17 = load i32, ptr %4, align 4, !tbaa !11
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [54 x double], ptr @fibs, i64 0, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = fptoui double %20 to i64
  store i64 %21, ptr %5, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %22 = load i32, ptr %4, align 4, !tbaa !11
  %23 = add nsw i32 %22, 1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [54 x double], ptr @fibs, i64 0, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = fptoui double %26 to i64
  store i64 %27, ptr %6, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %28 = load i32, ptr %4, align 4, !tbaa !11
  %29 = add nsw i32 %28, 2
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [54 x double], ptr @fibs, i64 0, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = fptoui double %32 to i64
  store i64 %33, ptr %7, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %34 = load i32, ptr %4, align 4, !tbaa !11
  %35 = add nsw i32 %34, 3
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [54 x double], ptr @fibs, i64 0, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !5
  %39 = fptoui double %38 to i64
  store i64 %39, ptr %8, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %40 = load i64, ptr %5, align 8, !tbaa !13
  %41 = load i64, ptr %6, align 8, !tbaa !13
  %42 = load i64, ptr %7, align 8, !tbaa !13
  %43 = load i64, ptr %8, align 8, !tbaa !13
  %44 = call double @timed_rotation_variable(i64 noundef %40, i64 noundef %41, i64 noundef %42, i64 noundef %43)
  store double %44, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 20, ptr %10) #4
  %45 = load i64, ptr %7, align 8, !tbaa !13
  %46 = icmp ult i64 %45, 8192
  br i1 %46, label %47, label %52

47:                                               ; preds = %16
  %48 = getelementptr inbounds [20 x i8], ptr %10, i64 0, i64 0
  %49 = load i64, ptr %7, align 8, !tbaa !13
  %50 = udiv i64 %49, 8
  %51 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %48, ptr noundef @.str.9, i64 noundef %50) #4
  br label %75

52:                                               ; preds = %16
  %53 = load i64, ptr %7, align 8, !tbaa !13
  %54 = icmp ult i64 %53, 8388608
  br i1 %54, label %55, label %60

55:                                               ; preds = %52
  %56 = getelementptr inbounds [20 x i8], ptr %10, i64 0, i64 0
  %57 = load i64, ptr %7, align 8, !tbaa !13
  %58 = udiv i64 %57, 8192
  %59 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %56, ptr noundef @.str.10, i64 noundef %58) #4
  br label %74

60:                                               ; preds = %52
  %61 = load i64, ptr %7, align 8, !tbaa !13
  %62 = icmp ult i64 %61, 8589934592
  br i1 %62, label %63, label %68

63:                                               ; preds = %60
  %64 = getelementptr inbounds [20 x i8], ptr %10, i64 0, i64 0
  %65 = load i64, ptr %7, align 8, !tbaa !13
  %66 = udiv i64 %65, 8388608
  %67 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %64, ptr noundef @.str.11, i64 noundef %66) #4
  br label %73

68:                                               ; preds = %60
  %69 = getelementptr inbounds [20 x i8], ptr %10, i64 0, i64 0
  %70 = load i64, ptr %7, align 8, !tbaa !13
  %71 = udiv i64 %70, 8589934592
  %72 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %69, ptr noundef @.str.12, i64 noundef %71) #4
  br label %73

73:                                               ; preds = %68, %63
  br label %74

74:                                               ; preds = %73, %55
  br label %75

75:                                               ; preds = %74, %47
  %76 = load double, ptr %9, align 8, !tbaa !5
  %77 = load double, ptr %3, align 8, !tbaa !5
  %78 = fcmp olt double %76, %77
  br i1 %78, label %79, label %86

79:                                               ; preds = %75
  %80 = load i32, ptr %4, align 4, !tbaa !11
  %81 = getelementptr inbounds [20 x i8], ptr %10, i64 0, i64 0
  %82 = load double, ptr %9, align 8, !tbaa !5
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, i32 noundef %80, ptr noundef %81, double noundef %82)
  %84 = load i32, ptr %4, align 4, !tbaa !11
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %4, align 4, !tbaa !11
  br label %94

86:                                               ; preds = %75
  %87 = load i32, ptr %4, align 4, !tbaa !11
  %88 = getelementptr inbounds [20 x i8], ptr %10, i64 0, i64 0
  %89 = load double, ptr %3, align 8, !tbaa !5
  %90 = load double, ptr %9, align 8, !tbaa !5
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.14, i32 noundef %87, ptr noundef %88, double noundef %89, double noundef %90)
  %92 = load i32, ptr %4, align 4, !tbaa !11
  %93 = sub nsw i32 %92, 1
  store i32 %93, ptr %2, align 4
  store i32 1, ptr %11, align 4
  br label %95

94:                                               ; preds = %79
  store i32 0, ptr %11, align 4
  br label %95

95:                                               ; preds = %94, %86
  call void @llvm.lifetime.end.p0(i64 20, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %96 = load i32, ptr %11, align 4
  switch i32 %96, label %101 [
    i32 0, label %97
  ]

97:                                               ; preds = %95
  br label %12, !llvm.loop !15

98:                                               ; preds = %12
  %99 = load i32, ptr %4, align 4, !tbaa !11
  %100 = sub nsw i32 %99, 1
  store i32 %100, ptr %2, align 4
  store i32 1, ptr %11, align 4
  br label %101

101:                                              ; preds = %98, %95
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %102 = load i32, ptr %2, align 4
  ret i32 %102
}

; Function Attrs: nounwind uwtable
declare dso_local double @timed_rotation_variable(i64 noundef, i64 noundef, i64 noundef, i64 noundef) #2

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #3

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 "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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

@test_verbose = external hidden local_unnamed_addr global i8, align 1
@fibs = external dso_local local_unnamed_addr constant [54 x double], align 16
@.str.9 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [64 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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @timed_rotation(double noundef %0) local_unnamed_addr #2 {
  %2 = alloca [20 x i8], align 16
  store i8 0, ptr @test_verbose, align 1, !tbaa !5
  %.pre = load double, ptr @fibs, align 16, !tbaa !9
  %.pre44 = load double, ptr getelementptr inbounds (i8, ptr @fibs, i64 8), align 8, !tbaa !9
  %.pre45 = load double, ptr getelementptr inbounds (i8, ptr @fibs, i64 16), align 16, !tbaa !9
  br label %3

3:                                                ; preds = %1, %27
  %4 = phi double [ %.pre45, %1 ], [ %12, %27 ]
  %5 = phi double [ %.pre44, %1 ], [ %4, %27 ]
  %6 = phi double [ %.pre, %1 ], [ %5, %27 ]
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %27 ]
  %7 = add nuw nsw i64 %indvars.iv, 3
  %8 = fptoui double %6 to i64
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = fptoui double %5 to i64
  %10 = fptoui double %4 to i64
  %11 = getelementptr inbounds [54 x double], ptr @fibs, i64 0, i64 %7
  %12 = load double, ptr %11, align 8, !tbaa !9
  %13 = fptoui double %12 to i64
  %14 = call double @timed_rotation_variable(i64 noundef %8, i64 noundef %9, i64 noundef %10, i64 noundef %13)
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %2) #3
  %15 = icmp ult i64 %10, 8192
  br i1 %15, label %20, label %16

16:                                               ; preds = %3
  %17 = icmp ult i64 %10, 8388608
  br i1 %17, label %20, label %18

18:                                               ; preds = %16
  %19 = icmp ult i64 %10, 8589934592
  %. = select i1 %19, i64 23, i64 33
  %.str.11..str.12 = select i1 %19, ptr @.str.11, ptr @.str.12
  br label %20

20:                                               ; preds = %18, %16, %3
  %.sink48 = phi i64 [ 3, %3 ], [ 13, %16 ], [ %., %18 ]
  %.str.10.sink = phi ptr [ @.str.9, %3 ], [ @.str.10, %16 ], [ %.str.11..str.12, %18 ]
  %21 = lshr i64 %10, %.sink48
  %22 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) %.str.10.sink, i64 noundef %21) #3
  %23 = fcmp olt double %14, %0
  %24 = trunc nuw nsw i64 %indvars.iv to i32
  br i1 %23, label %27, label %.thread

.thread:                                          ; preds = %20
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14, i32 noundef %24, ptr noundef nonnull %2, double noundef %0, double noundef %14)
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %2) #3
  %26 = add nsw i32 %24, -1
  br label %.loopexit

27:                                               ; preds = %20
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, i32 noundef %24, ptr noundef nonnull %2, double noundef %14)
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %2) #3
  %exitcond.not = icmp eq i64 %indvars.iv.next, 51
  br i1 %exitcond.not, label %.loopexit, label %3

.loopexit:                                        ; preds = %27, %.thread
  %.02839 = phi i32 [ %26, %.thread ], [ 50, %27 ]
  ret i32 %.02839
}

; Function Attrs: nounwind uwtable
declare dso_local double @timed_rotation_variable(i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

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

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


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass