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

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

@opterr = external global i32, align 4
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@optarg = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [32 x i8], align 1

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

13:                                               ; preds = %83, %2
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = call i32 @__posix_getopt(i32 noundef %14, ptr noundef %15, ptr noundef @.str) #5
  %17 = trunc i32 %16 to i8
  store i8 %17, ptr %7, align 1, !tbaa !11
  %18 = sext i8 %17 to i32
  %19 = icmp ne i32 %18, -1
  br i1 %19, label %20, label %84

20:                                               ; preds = %13
  %21 = load i8, ptr %7, align 1, !tbaa !11
  %22 = sext i8 %21 to i32
  switch i32 %22, label %83 [
    i32 110, label %23
    i32 116, label %26
    i32 100, label %29
    i32 99, label %30
    i32 112, label %31
    i32 115, label %68
    i32 109, label %73
    i32 108, label %78
  ]

23:                                               ; preds = %20
  %24 = load ptr, ptr @optarg, align 8, !tbaa !9
  %25 = call i32 @atoi(ptr noundef %24) #6
  store i32 %25, ptr %8, align 4, !tbaa !5
  br label %83

26:                                               ; preds = %20
  %27 = load ptr, ptr @optarg, align 8, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !5
  call void @parse_and_run_tests(ptr noundef %27, i32 noundef %28)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %88

29:                                               ; preds = %20
  call void @debugging()
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %88

30:                                               ; preds = %20
  call void @create_reverse_bit_table()
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %88

31:                                               ; preds = %20
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %33 = call double @timed_rotation_variable(i64 noundef 46368, i64 noundef 75025, i64 noundef 121393, i64 noundef 196418)
  store double %33, ptr %9, align 8, !tbaa !12
  store i32 5, ptr %10, align 4, !tbaa !5
  %34 = load double, ptr %9, align 8, !tbaa !12
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = sitofp i32 %35 to double
  %37 = fcmp olt double %34, %36
  br i1 %37, label %38, label %64

38:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %39 = load i32, ptr %10, align 4, !tbaa !5
  %40 = sitofp i32 %39 to double
  %41 = load double, ptr %9, align 8, !tbaa !12
  %42 = fsub double %40, %41
  %43 = load double, ptr %9, align 8, !tbaa !12
  %44 = fdiv double %42, %43
  %45 = fptosi double %44 to i32
  store i32 %45, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %55, %38
  %47 = load i32, ptr %12, align 4, !tbaa !5
  %48 = load i32, ptr %11, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %58

51:                                               ; preds = %46
  %52 = call double @timed_rotation_variable(i64 noundef 46368, i64 noundef 75025, i64 noundef 121393, i64 noundef 196418)
  %53 = load double, ptr %9, align 8, !tbaa !12
  %54 = fadd double %53, %52
  store double %54, ptr %9, align 8, !tbaa !12
  br label %55

55:                                               ; preds = %51
  %56 = load i32, ptr %12, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %12, align 4, !tbaa !5
  br label %46, !llvm.loop !14

58:                                               ; preds = %50
  %59 = load i32, ptr %11, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  %61 = sitofp i32 %60 to double
  %62 = load double, ptr %9, align 8, !tbaa !12
  %63 = fdiv double %62, %61
  store double %63, ptr %9, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %64

64:                                               ; preds = %58, %31
  %65 = load double, ptr %9, align 8, !tbaa !12
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %65)
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %88

68:                                               ; preds = %20
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %70 = call i32 @timed_rotation(double noundef 1.000000e-02)
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %70)
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %88

73:                                               ; preds = %20
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %75 = call i32 @timed_rotation(double noundef 1.000000e-01)
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %75)
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %88

78:                                               ; preds = %20
  %79 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %80 = call i32 @timed_rotation(double noundef 1.000000e+00)
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %80)
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %88

83:                                               ; preds = %23, %20
  br label %13, !llvm.loop !16

84:                                               ; preds = %13
  %85 = load ptr, ptr %5, align 8, !tbaa !9
  %86 = getelementptr inbounds ptr, ptr %85, i64 0
  %87 = load ptr, ptr %86, align 8, !tbaa !9
  call void @print_usage(ptr noundef %87)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %84, %78, %73, %68, %64, %30, %29, %26
  %89 = load i32, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  ret i32 %89
}

; 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 @__posix_getopt(i32 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #3

declare void @parse_and_run_tests(ptr noundef, i32 noundef) #4

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

declare double @timed_rotation_variable(i64 noundef, i64 noundef, i64 noundef, i64 noundef) #4

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

declare i32 @timed_rotation(double noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local void @print_usage(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @debugging() #0

; Function Attrs: nounwind uwtable
declare dso_local void @create_reverse_bit_table() #0

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 = { inlinehint nounwind willreturn memory(read) 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 = { "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@opterr = external local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@optarg = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  store i32 0, ptr @opterr, align 4, !tbaa !5
  %3 = tail call i32 @__posix_getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str) #5
  %sext32 = shl i32 %3, 24
  %.not33 = icmp eq i32 %sext32, -16777216
  br i1 %.not33, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %45
  %sext35 = phi i32 [ %sext, %45 ], [ %sext32, %2 ]
  %.01834 = phi i32 [ %.1, %45 ], [ -1, %2 ]
  %4 = ashr exact i32 %sext35, 24
  switch i32 %4, label %45 [
    i32 110, label %5
    i32 116, label %8
    i32 100, label %10
    i32 99, label %11
    i32 112, label %12
    i32 115, label %30
    i32 109, label %35
    i32 108, label %40
  ]

5:                                                ; preds = %.lr.ph
  %6 = load ptr, ptr @optarg, align 8, !tbaa !9
  %7 = tail call i32 @atoi(ptr nocapture noundef %6) #6
  br label %45

8:                                                ; preds = %.lr.ph
  %9 = load ptr, ptr @optarg, align 8, !tbaa !9
  tail call void @parse_and_run_tests(ptr noundef %9, i32 noundef %.01834) #5
  br label %48

10:                                               ; preds = %.lr.ph
  tail call void @debugging()
  br label %48

11:                                               ; preds = %.lr.ph
  tail call void @create_reverse_bit_table()
  br label %48

12:                                               ; preds = %.lr.ph
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %14 = tail call double @timed_rotation_variable(i64 noundef 46368, i64 noundef 75025, i64 noundef 121393, i64 noundef 196418) #5
  %15 = fcmp olt double %14, 5.000000e+00
  br i1 %15, label %16, label %27

16:                                               ; preds = %12
  %17 = fsub double 5.000000e+00, %14
  %18 = fdiv double %17, %14
  %19 = fptosi double %18 to i32
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %.lr.ph39, label %._crit_edge40

._crit_edge40:                                    ; preds = %.lr.ph39, %16
  %.019.lcssa = phi double [ %14, %16 ], [ %25, %.lr.ph39 ]
  %21 = add nsw i32 %19, 1
  %22 = sitofp i32 %21 to double
  %23 = fdiv double %.019.lcssa, %22
  br label %27

.lr.ph39:                                         ; preds = %16, %.lr.ph39
  %.037 = phi i32 [ %26, %.lr.ph39 ], [ 0, %16 ]
  %.01936 = phi double [ %25, %.lr.ph39 ], [ %14, %16 ]
  %24 = tail call double @timed_rotation_variable(i64 noundef 46368, i64 noundef 75025, i64 noundef 121393, i64 noundef 196418) #5
  %25 = fadd double %.01936, %24
  %26 = add nuw nsw i32 %.037, 1
  %exitcond.not = icmp eq i32 %26, %19
  br i1 %exitcond.not, label %._crit_edge40, label %.lr.ph39, !llvm.loop !11

27:                                               ; preds = %._crit_edge40, %12
  %.120 = phi double [ %23, %._crit_edge40 ], [ %14, %12 ]
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %.120)
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %48

30:                                               ; preds = %.lr.ph
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %32 = tail call i32 @timed_rotation(double noundef 1.000000e-02) #5
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %32)
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %48

35:                                               ; preds = %.lr.ph
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %37 = tail call i32 @timed_rotation(double noundef 1.000000e-01) #5
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %37)
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %48

40:                                               ; preds = %.lr.ph
  %41 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %42 = tail call i32 @timed_rotation(double noundef 1.000000e+00) #5
  %43 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %42)
  %44 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %48

45:                                               ; preds = %5, %.lr.ph
  %.1 = phi i32 [ %.01834, %.lr.ph ], [ %7, %5 ]
  %46 = tail call i32 @__posix_getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str) #5
  %sext = shl i32 %46, 24
  %.not = icmp eq i32 %sext, -16777216
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %45, %2
  %47 = load ptr, ptr %1, align 8, !tbaa !9
  tail call void @print_usage(ptr noundef %47)
  br label %48

48:                                               ; preds = %._crit_edge, %40, %35, %30, %27, %11, %10, %8
  ret i32 0
}

; Function Attrs: nounwind
declare i32 @__posix_getopt(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #2

declare void @parse_and_run_tests(ptr noundef, i32 noundef) local_unnamed_addr #3

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

declare double @timed_rotation_variable(i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #3

declare i32 @timed_rotation(double noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @print_usage(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @debugging() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @create_reverse_bit_table() local_unnamed_addr #0

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 = { 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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 = { "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 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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