; LLVM IR from VastoLorde95/Competitive-Programming :: Codejam/APAC 2017/Round A/Problem C/C.ll (Z4doitv)

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

@m = external dso_local global i32, align 4
@c = external dso_local global [110 x double], align 16
@.str = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4doitv() #0 {
  %1 = alloca double, align 8
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = load i32, ptr @m, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %24

16:                                               ; preds = %0
  %17 = load double, ptr @c, align 16, !tbaa !9
  %18 = fneg double %17
  %19 = load double, ptr getelementptr inbounds ([110 x double], ptr @c, i64 0, i64 1), align 8, !tbaa !9
  %20 = fsub double %18, %19
  %21 = load double, ptr @c, align 16, !tbaa !9
  %22 = fdiv double %20, %21
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %22)
  br label %127

24:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  %25 = load double, ptr @c, align 16, !tbaa !9
  store double %25, ptr %1, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %26 = load double, ptr @c, align 16, !tbaa !9
  %27 = load double, ptr getelementptr inbounds ([110 x double], ptr @c, i64 0, i64 1), align 8, !tbaa !9
  %28 = call double @llvm.fmuladd.f64(double %26, double 2.000000e+00, double %27)
  store double %28, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %29 = load double, ptr @c, align 16, !tbaa !9
  %30 = load double, ptr getelementptr inbounds ([110 x double], ptr @c, i64 0, i64 1), align 8, !tbaa !9
  %31 = fadd double %29, %30
  %32 = load double, ptr getelementptr inbounds ([110 x double], ptr @c, i64 0, i64 2), align 16, !tbaa !9
  %33 = fadd double %31, %32
  store double %33, ptr %3, align 8, !tbaa !9
  %34 = load double, ptr @c, align 16, !tbaa !9
  %35 = load double, ptr %1, align 8, !tbaa !9
  %36 = fdiv double %35, %34
  store double %36, ptr %1, align 8, !tbaa !9
  %37 = load double, ptr @c, align 16, !tbaa !9
  %38 = load double, ptr %2, align 8, !tbaa !9
  %39 = fdiv double %38, %37
  store double %39, ptr %2, align 8, !tbaa !9
  %40 = load double, ptr @c, align 16, !tbaa !9
  %41 = load double, ptr %3, align 8, !tbaa !9
  %42 = fdiv double %41, %40
  store double %42, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store double 0xBFEFFFFFFF768FA1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %75, %24
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = icmp slt i32 %44, 30
  br i1 %45, label %47, label %46

46:                                               ; preds = %43
  store i32 2, ptr %7, align 4
  br label %78

47:                                               ; preds = %43
  %48 = load double, ptr %4, align 8, !tbaa !9
  store double %48, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %49 = load double, ptr %5, align 8, !tbaa !9
  %50 = load double, ptr %5, align 8, !tbaa !9
  %51 = load double, ptr %2, align 8, !tbaa !9
  %52 = load double, ptr %5, align 8, !tbaa !9
  %53 = fmul double %51, %52
  %54 = call double @llvm.fmuladd.f64(double %49, double %50, double %53)
  %55 = load double, ptr %3, align 8, !tbaa !9
  %56 = fadd double %54, %55
  store double %56, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %57 = load double, ptr %5, align 8, !tbaa !9
  %58 = load double, ptr %2, align 8, !tbaa !9
  %59 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %57, double %58)
  store double %59, ptr %9, align 8, !tbaa !9
  %60 = load double, ptr %5, align 8, !tbaa !9
  %61 = load double, ptr %8, align 8, !tbaa !9
  %62 = load double, ptr %9, align 8, !tbaa !9
  %63 = fdiv double %61, %62
  %64 = fsub double %60, %63
  store double %64, ptr %4, align 8, !tbaa !9
  %65 = load double, ptr %5, align 8, !tbaa !9
  %66 = load double, ptr %4, align 8, !tbaa !9
  %67 = fsub double %65, %66
  %68 = call noundef double @_ZSt3absd(double noundef %67)
  %69 = fcmp olt double %68, 1.000000e-09
  br i1 %69, label %70, label %71

70:                                               ; preds = %47
  store i32 2, ptr %7, align 4
  br label %72

71:                                               ; preds = %47
  store i32 0, ptr %7, align 4
  br label %72

72:                                               ; preds = %71, %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %73 = load i32, ptr %7, align 4
  switch i32 %73, label %78 [
    i32 0, label %74
  ]

74:                                               ; preds = %72
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %6, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %6, align 4, !tbaa !5
  br label %43, !llvm.loop !11

78:                                               ; preds = %72, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %79

79:                                               ; preds = %78
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store double 0x3FEFFFFFFF768FA1, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %112, %79
  %81 = load i32, ptr %11, align 4, !tbaa !5
  %82 = icmp slt i32 %81, 30
  br i1 %82, label %84, label %83

83:                                               ; preds = %80
  store i32 5, ptr %7, align 4
  br label %115

84:                                               ; preds = %80
  %85 = load double, ptr %10, align 8, !tbaa !9
  store double %85, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %86 = load double, ptr %5, align 8, !tbaa !9
  %87 = load double, ptr %5, align 8, !tbaa !9
  %88 = load double, ptr %2, align 8, !tbaa !9
  %89 = load double, ptr %5, align 8, !tbaa !9
  %90 = fmul double %88, %89
  %91 = call double @llvm.fmuladd.f64(double %86, double %87, double %90)
  %92 = load double, ptr %3, align 8, !tbaa !9
  %93 = fadd double %91, %92
  store double %93, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %94 = load double, ptr %5, align 8, !tbaa !9
  %95 = load double, ptr %2, align 8, !tbaa !9
  %96 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %94, double %95)
  store double %96, ptr %13, align 8, !tbaa !9
  %97 = load double, ptr %5, align 8, !tbaa !9
  %98 = load double, ptr %12, align 8, !tbaa !9
  %99 = load double, ptr %13, align 8, !tbaa !9
  %100 = fdiv double %98, %99
  %101 = fsub double %97, %100
  store double %101, ptr %10, align 8, !tbaa !9
  %102 = load double, ptr %5, align 8, !tbaa !9
  %103 = load double, ptr %10, align 8, !tbaa !9
  %104 = fsub double %102, %103
  %105 = call noundef double @_ZSt3absd(double noundef %104)
  %106 = fcmp olt double %105, 1.000000e-09
  br i1 %106, label %107, label %108

107:                                              ; preds = %84
  store i32 5, ptr %7, align 4
  br label %109

108:                                              ; preds = %84
  store i32 0, ptr %7, align 4
  br label %109

109:                                              ; preds = %108, %107
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %110 = load i32, ptr %7, align 4
  switch i32 %110, label %115 [
    i32 0, label %111
  ]

111:                                              ; preds = %109
  br label %112

112:                                              ; preds = %111
  %113 = load i32, ptr %11, align 4, !tbaa !5
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %11, align 4, !tbaa !5
  br label %80, !llvm.loop !13

115:                                              ; preds = %109, %83
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %116

116:                                              ; preds = %115
  %117 = load double, ptr %10, align 8, !tbaa !9
  %118 = fcmp olt double 0xBFF000000044B830, %117
  %119 = zext i1 %118 to i32
  %120 = sitofp i32 %119 to double
  %121 = fcmp olt double %120, 0x3FF000000044B830
  br i1 %121, label %122, label %124

122:                                              ; preds = %116
  %123 = load double, ptr %10, align 8, !tbaa !9
  store double %123, ptr %4, align 8, !tbaa !9
  br label %124

124:                                              ; preds = %122, %116
  %125 = load double, ptr %4, align 8, !tbaa !9
  %126 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %125)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  br label %127

127:                                              ; preds = %124, %16
  ret void
}

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3absd(double noundef) #4

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

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { inlinehint mustprogress 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 #5 = { 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"}
!13 = distinct !{!13, !12}


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

@m = external dso_local local_unnamed_addr global i32, align 4
@c = external dso_local local_unnamed_addr global [110 x double], align 16
@.str = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4doitv() local_unnamed_addr #0 {
  %1 = load i32, ptr @m, align 4, !tbaa !5
  %2 = icmp eq i32 %1, 1
  %3 = load double, ptr @c, align 16, !tbaa !9
  br i1 %2, label %4, label %9

4:                                                ; preds = %0
  %5 = fneg double %3
  %6 = load double, ptr getelementptr inbounds (i8, ptr @c, i64 8), align 8, !tbaa !9
  %7 = fsub double %5, %6
  %8 = fdiv double %7, %3
  br label %.loopexit

9:                                                ; preds = %0
  %10 = load double, ptr getelementptr inbounds (i8, ptr @c, i64 8), align 8, !tbaa !9
  %11 = tail call double @llvm.fmuladd.f64(double %3, double 2.000000e+00, double %10)
  %12 = fadd double %3, %10
  %13 = load double, ptr getelementptr inbounds (i8, ptr @c, i64 16), align 16, !tbaa !9
  %14 = fadd double %12, %13
  %15 = fdiv double %11, %3
  %16 = fdiv double %14, %3
  br label %17

17:                                               ; preds = %17, %9
  %.03945 = phi double [ 0xBFEFFFFFFF768FA1, %9 ], [ %23, %17 ]
  %.04344 = phi i32 [ 0, %9 ], [ %27, %17 ]
  %18 = fmul double %15, %.03945
  %19 = tail call double @llvm.fmuladd.f64(double %.03945, double %.03945, double %18)
  %20 = fadd double %16, %19
  %21 = tail call double @llvm.fmuladd.f64(double %.03945, double 2.000000e+00, double %15)
  %22 = fdiv double %20, %21
  %23 = fsub double %.03945, %22
  %24 = fsub double %.03945, %23
  %25 = tail call noundef double @_ZSt3absd(double noundef %24)
  %26 = fcmp olt double %25, 1.000000e-09
  %27 = add nuw nsw i32 %.04344, 1
  %exitcond.not = icmp eq i32 %27, 30
  %or.cond = select i1 %26, i1 true, i1 %exitcond.not
  br i1 %or.cond, label %.preheader, label %17, !llvm.loop !11

.preheader:                                       ; preds = %17, %.preheader
  %.047 = phi i32 [ %37, %.preheader ], [ 0, %17 ]
  %.03846 = phi double [ %33, %.preheader ], [ 0x3FEFFFFFFF768FA1, %17 ]
  %28 = fmul double %15, %.03846
  %29 = tail call double @llvm.fmuladd.f64(double %.03846, double %.03846, double %28)
  %30 = fadd double %16, %29
  %31 = tail call double @llvm.fmuladd.f64(double %.03846, double 2.000000e+00, double %15)
  %32 = fdiv double %30, %31
  %33 = fsub double %.03846, %32
  %34 = fsub double %.03846, %33
  %35 = tail call noundef double @_ZSt3absd(double noundef %34)
  %36 = fcmp olt double %35, 1.000000e-09
  %37 = add nuw nsw i32 %.047, 1
  %exitcond48.not = icmp eq i32 %37, 30
  %or.cond49 = select i1 %36, i1 true, i1 %exitcond48.not
  br i1 %or.cond49, label %.loopexit, label %.preheader, !llvm.loop !13

.loopexit:                                        ; preds = %.preheader, %4
  %.sink = phi double [ %8, %4 ], [ %33, %.preheader ]
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %.sink)
  ret void
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3absd(double noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { inlinehint mustprogress 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" }

!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"}
!13 = distinct !{!13, !12}


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