; LLVM IR from VastoLorde95/Competitive-Programming :: Timus/1887/A.ll (Z7computei)

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

@p = external dso_local global [10 x double], align 16
@dp2 = external dso_local global [1024 x double], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z7computei(i32 noundef %0) #0 {
  %2 = alloca double, align 8
  %3 = alloca i32, align 4
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [1024 x double], ptr @dp2, i64 0, i64 %8
  %10 = load double, ptr %9, align 8, !tbaa !9
  %11 = fcmp oge double %10, 0.000000e+00
  br i1 %11, label %12, label %17

12:                                               ; preds = %1
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1024 x double], ptr @dp2, i64 0, i64 %14
  %16 = load double, ptr %15, align 8, !tbaa !9
  store double %16, ptr %2, align 8
  br label %59

17:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store double 0.000000e+00, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 1.000000e+00, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %48, %17
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = icmp slt i32 %19, 10
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %51

22:                                               ; preds = %18
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = shl i32 1, %24
  %26 = and i32 %23, %25
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %35

28:                                               ; preds = %22
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10 x double], ptr @p, i64 0, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = load double, ptr %4, align 8, !tbaa !9
  %34 = fadd double %33, %32
  store double %34, ptr %4, align 8, !tbaa !9
  br label %47

35:                                               ; preds = %22
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10 x double], ptr @p, i64 0, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = shl i32 1, %41
  %43 = or i32 %40, %42
  %44 = call noundef double @_Z7computei(i32 noundef %43)
  %45 = load double, ptr %5, align 8, !tbaa !9
  %46 = call double @llvm.fmuladd.f64(double %39, double %44, double %45)
  store double %46, ptr %5, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %35, %28
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %6, align 4, !tbaa !5
  br label %18, !llvm.loop !11

51:                                               ; preds = %21
  %52 = load double, ptr %5, align 8, !tbaa !9
  %53 = load double, ptr %4, align 8, !tbaa !9
  %54 = fsub double 1.000000e+00, %53
  %55 = fdiv double %52, %54
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1024 x double], ptr @dp2, i64 0, i64 %57
  store double %55, ptr %58, align 8, !tbaa !9
  store double %55, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %59

59:                                               ; preds = %51, %12
  %60 = load double, ptr %2, align 8
  ret double %60
}

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@p = external dso_local local_unnamed_addr global [10 x double], align 16
@dp2 = external dso_local local_unnamed_addr global [1024 x double], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef double @_Z7computei(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [1024 x double], ptr @dp2, i64 0, i64 %2
  %4 = load double, ptr %3, align 8, !tbaa !5
  %5 = fcmp ult double %4, 0.000000e+00
  br i1 %5, label %.preheader.preheader, label %89

.preheader.preheader:                             ; preds = %1
  %6 = and i32 %0, 1
  %.not = icmp eq i32 %6, 0
  %7 = load double, ptr @p, align 16, !tbaa !5
  br i1 %.not, label %10, label %8

8:                                                ; preds = %.preheader.preheader
  %9 = fadd double %7, 0.000000e+00
  br label %.preheader.1

10:                                               ; preds = %.preheader.preheader
  %11 = or disjoint i32 %0, 1
  %12 = tail call noundef double @_Z7computei(i32 noundef %11)
  %13 = tail call double @llvm.fmuladd.f64(double %7, double %12, double 1.000000e+00)
  br label %.preheader.1

.preheader.1:                                     ; preds = %8, %10
  %.117 = phi double [ %9, %8 ], [ 0.000000e+00, %10 ]
  %.1 = phi double [ 1.000000e+00, %8 ], [ %13, %10 ]
  %14 = and i32 %0, 2
  %.not.1 = icmp eq i32 %14, 0
  %15 = load double, ptr getelementptr inbounds (i8, ptr @p, i64 8), align 8, !tbaa !5
  br i1 %.not.1, label %18, label %16

16:                                               ; preds = %.preheader.1
  %17 = fadd double %.117, %15
  br label %.preheader.2

18:                                               ; preds = %.preheader.1
  %19 = or disjoint i32 %0, 2
  %20 = tail call noundef double @_Z7computei(i32 noundef %19)
  %21 = tail call double @llvm.fmuladd.f64(double %15, double %20, double %.1)
  br label %.preheader.2

.preheader.2:                                     ; preds = %18, %16
  %.117.1 = phi double [ %17, %16 ], [ %.117, %18 ]
  %.1.1 = phi double [ %.1, %16 ], [ %21, %18 ]
  %22 = and i32 %0, 4
  %.not.2 = icmp eq i32 %22, 0
  %23 = load double, ptr getelementptr inbounds (i8, ptr @p, i64 16), align 16, !tbaa !5
  br i1 %.not.2, label %26, label %24

24:                                               ; preds = %.preheader.2
  %25 = fadd double %.117.1, %23
  br label %.preheader.3

26:                                               ; preds = %.preheader.2
  %27 = or disjoint i32 %0, 4
  %28 = tail call noundef double @_Z7computei(i32 noundef %27)
  %29 = tail call double @llvm.fmuladd.f64(double %23, double %28, double %.1.1)
  br label %.preheader.3

.preheader.3:                                     ; preds = %26, %24
  %.117.2 = phi double [ %25, %24 ], [ %.117.1, %26 ]
  %.1.2 = phi double [ %.1.1, %24 ], [ %29, %26 ]
  %30 = and i32 %0, 8
  %.not.3 = icmp eq i32 %30, 0
  %31 = load double, ptr getelementptr inbounds (i8, ptr @p, i64 24), align 8, !tbaa !5
  br i1 %.not.3, label %34, label %32

32:                                               ; preds = %.preheader.3
  %33 = fadd double %.117.2, %31
  br label %.preheader.4

34:                                               ; preds = %.preheader.3
  %35 = or disjoint i32 %0, 8
  %36 = tail call noundef double @_Z7computei(i32 noundef %35)
  %37 = tail call double @llvm.fmuladd.f64(double %31, double %36, double %.1.2)
  br label %.preheader.4

.preheader.4:                                     ; preds = %34, %32
  %.117.3 = phi double [ %33, %32 ], [ %.117.2, %34 ]
  %.1.3 = phi double [ %.1.2, %32 ], [ %37, %34 ]
  %38 = and i32 %0, 16
  %.not.4 = icmp eq i32 %38, 0
  %39 = load double, ptr getelementptr inbounds (i8, ptr @p, i64 32), align 16, !tbaa !5
  br i1 %.not.4, label %42, label %40

40:                                               ; preds = %.preheader.4
  %41 = fadd double %.117.3, %39
  br label %.preheader.5

42:                                               ; preds = %.preheader.4
  %43 = or disjoint i32 %0, 16
  %44 = tail call noundef double @_Z7computei(i32 noundef %43)
  %45 = tail call double @llvm.fmuladd.f64(double %39, double %44, double %.1.3)
  br label %.preheader.5

.preheader.5:                                     ; preds = %42, %40
  %.117.4 = phi double [ %41, %40 ], [ %.117.3, %42 ]
  %.1.4 = phi double [ %.1.3, %40 ], [ %45, %42 ]
  %46 = and i32 %0, 32
  %.not.5 = icmp eq i32 %46, 0
  %47 = load double, ptr getelementptr inbounds (i8, ptr @p, i64 40), align 8, !tbaa !5
  br i1 %.not.5, label %50, label %48

48:                                               ; preds = %.preheader.5
  %49 = fadd double %.117.4, %47
  br label %.preheader.6

50:                                               ; preds = %.preheader.5
  %51 = or disjoint i32 %0, 32
  %52 = tail call noundef double @_Z7computei(i32 noundef %51)
  %53 = tail call double @llvm.fmuladd.f64(double %47, double %52, double %.1.4)
  br label %.preheader.6

.preheader.6:                                     ; preds = %50, %48
  %.117.5 = phi double [ %49, %48 ], [ %.117.4, %50 ]
  %.1.5 = phi double [ %.1.4, %48 ], [ %53, %50 ]
  %54 = and i32 %0, 64
  %.not.6 = icmp eq i32 %54, 0
  %55 = load double, ptr getelementptr inbounds (i8, ptr @p, i64 48), align 16, !tbaa !5
  br i1 %.not.6, label %58, label %56

56:                                               ; preds = %.preheader.6
  %57 = fadd double %.117.5, %55
  br label %.preheader.7

58:                                               ; preds = %.preheader.6
  %59 = or disjoint i32 %0, 64
  %60 = tail call noundef double @_Z7computei(i32 noundef %59)
  %61 = tail call double @llvm.fmuladd.f64(double %55, double %60, double %.1.5)
  br label %.preheader.7

.preheader.7:                                     ; preds = %58, %56
  %.117.6 = phi double [ %57, %56 ], [ %.117.5, %58 ]
  %.1.6 = phi double [ %.1.5, %56 ], [ %61, %58 ]
  %62 = and i32 %0, 128
  %.not.7 = icmp eq i32 %62, 0
  %63 = load double, ptr getelementptr inbounds (i8, ptr @p, i64 56), align 8, !tbaa !5
  br i1 %.not.7, label %66, label %64

64:                                               ; preds = %.preheader.7
  %65 = fadd double %.117.6, %63
  br label %.preheader.8

66:                                               ; preds = %.preheader.7
  %67 = or disjoint i32 %0, 128
  %68 = tail call noundef double @_Z7computei(i32 noundef %67)
  %69 = tail call double @llvm.fmuladd.f64(double %63, double %68, double %.1.6)
  br label %.preheader.8

.preheader.8:                                     ; preds = %66, %64
  %.117.7 = phi double [ %65, %64 ], [ %.117.6, %66 ]
  %.1.7 = phi double [ %.1.6, %64 ], [ %69, %66 ]
  %70 = and i32 %0, 256
  %.not.8 = icmp eq i32 %70, 0
  %71 = load double, ptr getelementptr inbounds (i8, ptr @p, i64 64), align 16, !tbaa !5
  br i1 %.not.8, label %74, label %72

72:                                               ; preds = %.preheader.8
  %73 = fadd double %.117.7, %71
  br label %.preheader.9

74:                                               ; preds = %.preheader.8
  %75 = or disjoint i32 %0, 256
  %76 = tail call noundef double @_Z7computei(i32 noundef %75)
  %77 = tail call double @llvm.fmuladd.f64(double %71, double %76, double %.1.7)
  br label %.preheader.9

.preheader.9:                                     ; preds = %74, %72
  %.117.8 = phi double [ %73, %72 ], [ %.117.7, %74 ]
  %.1.8 = phi double [ %.1.7, %72 ], [ %77, %74 ]
  %78 = and i32 %0, 512
  %.not.9 = icmp eq i32 %78, 0
  %79 = load double, ptr getelementptr inbounds (i8, ptr @p, i64 72), align 8, !tbaa !5
  br i1 %.not.9, label %82, label %80

80:                                               ; preds = %.preheader.9
  %81 = fadd double %.117.8, %79
  br label %86

82:                                               ; preds = %.preheader.9
  %83 = or disjoint i32 %0, 512
  %84 = tail call noundef double @_Z7computei(i32 noundef %83)
  %85 = tail call double @llvm.fmuladd.f64(double %79, double %84, double %.1.8)
  br label %86

86:                                               ; preds = %82, %80
  %.117.9 = phi double [ %81, %80 ], [ %.117.8, %82 ]
  %.1.9 = phi double [ %.1.8, %80 ], [ %85, %82 ]
  %87 = fsub double 1.000000e+00, %.117.9
  %88 = fdiv double %.1.9, %87
  store double %88, ptr %3, align 8, !tbaa !5
  br label %89

89:                                               ; preds = %1, %86
  %.018 = phi double [ %88, %86 ], [ %4, %1 ]
  ret double %.018
}

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

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass