; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/128 Division 2/Problem D (D)

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

@a = external dso_local global double, align 8
@b = external dso_local global double, align 8
@m = external dso_local global double, align 8
@vx = external dso_local global double, align 8
@vy = external dso_local global double, align 8
@vz = external dso_local global double, align 8
@x0 = external dso_local global double, align 8
@z0 = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @a, ptr noundef @b, ptr noundef @m)
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @vx, ptr noundef @vy, ptr noundef @vz)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %9 = load double, ptr @m, align 8, !tbaa !5
  %10 = load double, ptr @vy, align 8, !tbaa !5
  %11 = fdiv double %9, %10
  %12 = call double @llvm.fabs.f64(double %11)
  store double %12, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %13 = load double, ptr @vx, align 8, !tbaa !5
  %14 = load double, ptr %2, align 8, !tbaa !5
  %15 = fmul double %13, %14
  store double %15, ptr %3, align 8, !tbaa !5
  %16 = load double, ptr %3, align 8, !tbaa !5
  %17 = fcmp oge double %16, 0.000000e+00
  br i1 %17, label %18, label %25

18:                                               ; preds = %0
  %19 = load double, ptr @a, align 8, !tbaa !5
  %20 = fdiv double %19, 2.000000e+00
  %21 = load double, ptr %3, align 8, !tbaa !5
  %22 = fadd double %20, %21
  %23 = load double, ptr @a, align 8, !tbaa !5
  %24 = fcmp ole double %22, %23
  br i1 %24, label %34, label %25

25:                                               ; preds = %18, %0
  %26 = load double, ptr %3, align 8, !tbaa !5
  %27 = fcmp olt double %26, 0.000000e+00
  br i1 %27, label %28, label %39

28:                                               ; preds = %25
  %29 = load double, ptr @a, align 8, !tbaa !5
  %30 = fdiv double %29, 2.000000e+00
  %31 = load double, ptr %3, align 8, !tbaa !5
  %32 = fadd double %30, %31
  %33 = fcmp oge double %32, 0.000000e+00
  br i1 %33, label %34, label %39

34:                                               ; preds = %28, %18
  %35 = load double, ptr @a, align 8, !tbaa !5
  %36 = fdiv double %35, 2.000000e+00
  %37 = load double, ptr %3, align 8, !tbaa !5
  %38 = fadd double %36, %37
  store double %38, ptr @x0, align 8, !tbaa !5
  br label %95

39:                                               ; preds = %28, %25
  %40 = load double, ptr %3, align 8, !tbaa !5
  %41 = fcmp ogt double %40, 0.000000e+00
  br i1 %41, label %42, label %67

42:                                               ; preds = %39
  %43 = load double, ptr @a, align 8, !tbaa !5
  %44 = fdiv double %43, 2.000000e+00
  %45 = load double, ptr %3, align 8, !tbaa !5
  %46 = fsub double %45, %44
  store double %46, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %47 = load double, ptr %3, align 8, !tbaa !5
  %48 = load double, ptr @a, align 8, !tbaa !5
  %49 = fdiv double %47, %48
  %50 = fptosi double %49 to i32
  store i32 %50, ptr %4, align 4, !tbaa !9
  %51 = load double, ptr @a, align 8, !tbaa !5
  %52 = load i32, ptr %4, align 4, !tbaa !9
  %53 = sitofp i32 %52 to double
  %54 = load double, ptr %3, align 8, !tbaa !5
  %55 = fneg double %51
  %56 = call double @llvm.fmuladd.f64(double %55, double %53, double %54)
  store double %56, ptr %3, align 8, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = srem i32 %57, 2
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %60, label %64

60:                                               ; preds = %42
  %61 = load double, ptr @a, align 8, !tbaa !5
  %62 = load double, ptr %3, align 8, !tbaa !5
  %63 = fsub double %61, %62
  store double %63, ptr @x0, align 8, !tbaa !5
  br label %66

64:                                               ; preds = %42
  %65 = load double, ptr %3, align 8, !tbaa !5
  store double %65, ptr @x0, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %64, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %94

67:                                               ; preds = %39
  %68 = load double, ptr @a, align 8, !tbaa !5
  %69 = fdiv double %68, 2.000000e+00
  %70 = load double, ptr %3, align 8, !tbaa !5
  %71 = fadd double %70, %69
  store double %71, ptr %3, align 8, !tbaa !5
  %72 = load double, ptr %3, align 8, !tbaa !5
  %73 = call double @llvm.fabs.f64(double %72)
  store double %73, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %74 = load double, ptr %3, align 8, !tbaa !5
  %75 = load double, ptr @a, align 8, !tbaa !5
  %76 = fdiv double %74, %75
  %77 = fptosi double %76 to i32
  store i32 %77, ptr %5, align 4, !tbaa !9
  %78 = load double, ptr @a, align 8, !tbaa !5
  %79 = load i32, ptr %5, align 4, !tbaa !9
  %80 = sitofp i32 %79 to double
  %81 = load double, ptr %3, align 8, !tbaa !5
  %82 = fneg double %78
  %83 = call double @llvm.fmuladd.f64(double %82, double %80, double %81)
  store double %83, ptr %3, align 8, !tbaa !5
  %84 = load i32, ptr %5, align 4, !tbaa !9
  %85 = srem i32 %84, 2
  %86 = icmp eq i32 %85, 0
  br i1 %86, label %87, label %89

87:                                               ; preds = %67
  %88 = load double, ptr %3, align 8, !tbaa !5
  store double %88, ptr @x0, align 8, !tbaa !5
  br label %93

89:                                               ; preds = %67
  %90 = load double, ptr @a, align 8, !tbaa !5
  %91 = load double, ptr %3, align 8, !tbaa !5
  %92 = fsub double %90, %91
  store double %92, ptr @x0, align 8, !tbaa !5
  br label %93

93:                                               ; preds = %89, %87
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %94

94:                                               ; preds = %93, %66
  br label %95

95:                                               ; preds = %94, %34
  %96 = load double, ptr @vz, align 8, !tbaa !5
  %97 = load double, ptr %2, align 8, !tbaa !5
  %98 = fmul double %96, %97
  store double %98, ptr %3, align 8, !tbaa !5
  %99 = load double, ptr %3, align 8, !tbaa !5
  %100 = load double, ptr @b, align 8, !tbaa !5
  %101 = fcmp ole double %99, %100
  br i1 %101, label %102, label %104

102:                                              ; preds = %95
  %103 = load double, ptr %3, align 8, !tbaa !5
  store double %103, ptr @z0, align 8, !tbaa !5
  br label %128

104:                                              ; preds = %95
  %105 = load double, ptr @b, align 8, !tbaa !5
  %106 = load double, ptr %3, align 8, !tbaa !5
  %107 = fsub double %106, %105
  store double %107, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %108 = load double, ptr %3, align 8, !tbaa !5
  %109 = load double, ptr @b, align 8, !tbaa !5
  %110 = fdiv double %108, %109
  %111 = fptosi double %110 to i32
  store i32 %111, ptr %6, align 4, !tbaa !9
  %112 = load double, ptr @b, align 8, !tbaa !5
  %113 = load i32, ptr %6, align 4, !tbaa !9
  %114 = sitofp i32 %113 to double
  %115 = load double, ptr %3, align 8, !tbaa !5
  %116 = fneg double %112
  %117 = call double @llvm.fmuladd.f64(double %116, double %114, double %115)
  store double %117, ptr %3, align 8, !tbaa !5
  %118 = load i32, ptr %6, align 4, !tbaa !9
  %119 = srem i32 %118, 2
  %120 = icmp eq i32 %119, 0
  br i1 %120, label %121, label %125

121:                                              ; preds = %104
  %122 = load double, ptr @b, align 8, !tbaa !5
  %123 = load double, ptr %3, align 8, !tbaa !5
  %124 = fsub double %122, %123
  store double %124, ptr @z0, align 8, !tbaa !5
  br label %127

125:                                              ; preds = %104
  %126 = load double, ptr %3, align 8, !tbaa !5
  store double %126, ptr @z0, align 8, !tbaa !5
  br label %127

127:                                              ; preds = %125, %121
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %128

128:                                              ; preds = %127, %102
  %129 = load double, ptr @x0, align 8, !tbaa !5
  %130 = load double, ptr @z0, align 8, !tbaa !5
  %131 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %129, double noundef %130)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  ret i32 0
}

declare i32 @__isoc99_scanf(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.fabs.f64(double) #3

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

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

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

attributes #0 = { mustprogress norecurse 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

@a = external dso_local global double, align 8
@b = external dso_local global double, align 8
@m = external dso_local global double, align 8
@vx = external dso_local global double, align 8
@vy = external dso_local global double, align 8
@vz = external dso_local global double, align 8
@x0 = external dso_local local_unnamed_addr global double, align 8
@z0 = external dso_local local_unnamed_addr global double, align 8
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @m)
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @vx, ptr noundef nonnull @vy, ptr noundef nonnull @vz)
  %3 = load double, ptr @m, align 8, !tbaa !5
  %4 = load double, ptr @vy, align 8, !tbaa !5
  %5 = fdiv double %3, %4
  %6 = tail call double @llvm.fabs.f64(double %5)
  %7 = load double, ptr @vx, align 8, !tbaa !5
  %8 = fmul double %7, %6
  %9 = fcmp ult double %8, 0.000000e+00
  br i1 %9, label %15, label %10

10:                                               ; preds = %0
  %11 = load double, ptr @a, align 8, !tbaa !5
  %12 = fmul double %11, 5.000000e-01
  %13 = fadd double %8, %12
  %14 = fcmp ugt double %13, %11
  br i1 %14, label %15, label %47

15:                                               ; preds = %10, %0
  %16 = fcmp olt double %8, 0.000000e+00
  br i1 %16, label %17, label %22

17:                                               ; preds = %15
  %18 = load double, ptr @a, align 8, !tbaa !5
  %19 = fmul double %18, 5.000000e-01
  %20 = fadd double %8, %19
  %21 = fcmp ult double %20, 0.000000e+00
  br i1 %21, label %22, label %47

22:                                               ; preds = %17, %15
  %23 = fcmp ogt double %8, 0.000000e+00
  %24 = load double, ptr @a, align 8, !tbaa !5
  %25 = fmul double %24, 5.000000e-01
  br i1 %23, label %26, label %36

26:                                               ; preds = %22
  %27 = fsub double %8, %25
  %28 = fdiv double %27, %24
  %29 = fptosi double %28 to i32
  %30 = sitofp i32 %29 to double
  %31 = fneg double %24
  %32 = tail call double @llvm.fmuladd.f64(double %31, double %30, double %27)
  %33 = and i32 %29, 1
  %34 = icmp eq i32 %33, 0
  %35 = fsub double %24, %32
  %storemerge34 = select i1 %34, double %35, double %32
  br label %47

36:                                               ; preds = %22
  %37 = fadd double %8, %25
  %38 = tail call double @llvm.fabs.f64(double %37)
  %39 = fdiv double %38, %24
  %40 = fptosi double %39 to i32
  %41 = sitofp i32 %40 to double
  %42 = fneg double %24
  %43 = tail call double @llvm.fmuladd.f64(double %42, double %41, double %38)
  %44 = and i32 %40, 1
  %45 = icmp eq i32 %44, 0
  %46 = fsub double %24, %43
  %storemerge = select i1 %45, double %43, double %46
  br label %47

47:                                               ; preds = %10, %17, %26, %36
  %storemerge34.sink = phi double [ %storemerge34, %26 ], [ %storemerge, %36 ], [ %20, %17 ], [ %13, %10 ]
  store double %storemerge34.sink, ptr @x0, align 8, !tbaa !5
  %48 = load double, ptr @vz, align 8, !tbaa !5
  %49 = fmul double %6, %48
  %50 = load double, ptr @b, align 8, !tbaa !5
  %51 = fcmp ugt double %49, %50
  br i1 %51, label %52, label %62

52:                                               ; preds = %47
  %53 = fsub double %49, %50
  %54 = fdiv double %53, %50
  %55 = fptosi double %54 to i32
  %56 = sitofp i32 %55 to double
  %57 = fneg double %50
  %58 = tail call double @llvm.fmuladd.f64(double %57, double %56, double %53)
  %59 = and i32 %55, 1
  %60 = icmp eq i32 %59, 0
  %61 = fsub double %50, %58
  %storemerge35 = select i1 %60, double %61, double %58
  br label %62

62:                                               ; preds = %47, %52
  %storemerge36 = phi double [ %storemerge35, %52 ], [ %49, %47 ]
  store double %storemerge36, ptr @z0, align 8, !tbaa !5
  %63 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %storemerge34.sink, double noundef %storemerge36)
  ret i32 0
}

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

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

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

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

attributes #0 = { mustprogress nofree norecurse 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) }

!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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass