; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/LONG/JUNE15/FRNDMTNG (a)

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

@t = external dso_local global i32, align 4
@T1 = external dso_local global i32, align 4
@T2 = external dso_local global i32, align 4
@t1 = external dso_local global i32, align 4
@t2 = external dso_local global i32, align 4
@sum = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %5

5:                                                ; preds = %96, %0
  %6 = load i32, ptr @t, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @t, align 4, !tbaa !5
  %8 = icmp ne i32 %6, 0
  br i1 %8, label %9, label %99

9:                                                ; preds = %5
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @T1, ptr noundef @T2)
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @t1, ptr noundef @t2)
  %12 = load i32, ptr @T1, align 4, !tbaa !5
  %13 = load i32, ptr @T2, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %9
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) @T1, ptr noundef nonnull align 4 dereferenceable(4) @T2) #5
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) @t1, ptr noundef nonnull align 4 dereferenceable(4) @t2) #5
  br label %16

16:                                               ; preds = %15, %9
  %17 = load i32, ptr @t1, align 4, !tbaa !5
  %18 = load i32, ptr @T1, align 4, !tbaa !5
  %19 = sdiv i32 %17, %18
  %20 = sitofp i32 %19 to double
  %21 = load i32, ptr @t2, align 4, !tbaa !5
  %22 = load i32, ptr @T2, align 4, !tbaa !5
  %23 = sdiv i32 %21, %22
  %24 = sitofp i32 %23 to double
  %25 = load i32, ptr @t2, align 4, !tbaa !5
  %26 = load i32, ptr @T1, align 4, !tbaa !5
  %27 = sdiv i32 %25, %26
  %28 = sitofp i32 %27 to double
  %29 = load i32, ptr @t2, align 4, !tbaa !5
  %30 = load i32, ptr @T2, align 4, !tbaa !5
  %31 = sdiv i32 %29, %30
  %32 = sitofp i32 %31 to double
  %33 = fmul double %28, %32
  %34 = fdiv double %33, 2.000000e+00
  %35 = call double @llvm.fmuladd.f64(double %20, double %24, double %34)
  store double %35, ptr @sum, align 8, !tbaa !9
  %36 = load i32, ptr @t2, align 4, !tbaa !5
  %37 = load i32, ptr @T1, align 4, !tbaa !5
  %38 = load i32, ptr @t1, align 4, !tbaa !5
  %39 = sub nsw i32 %37, %38
  %40 = icmp slt i32 %36, %39
  br i1 %40, label %41, label %64

41:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %42 = load i32, ptr @t1, align 4, !tbaa !5
  %43 = load i32, ptr @t2, align 4, !tbaa !5
  %44 = add nsw i32 %42, %43
  %45 = sitofp i32 %44 to double
  %46 = load i32, ptr @T1, align 4, !tbaa !5
  %47 = sitofp i32 %46 to double
  %48 = fdiv double %45, %47
  store double %48, ptr %2, align 8, !tbaa !9
  %49 = load i32, ptr @T2, align 4, !tbaa !5
  %50 = sitofp i32 %49 to double
  %51 = load double, ptr %2, align 8, !tbaa !9
  %52 = fdiv double %51, %50
  store double %52, ptr %2, align 8, !tbaa !9
  %53 = load i32, ptr @T1, align 4, !tbaa !5
  %54 = load i32, ptr @t1, align 4, !tbaa !5
  %55 = sub nsw i32 %53, %54
  %56 = load i32, ptr @t2, align 4, !tbaa !5
  %57 = sub nsw i32 %55, %56
  %58 = sitofp i32 %57 to double
  %59 = load double, ptr %2, align 8, !tbaa !9
  %60 = fmul double %59, %58
  store double %60, ptr %2, align 8, !tbaa !9
  %61 = load double, ptr %2, align 8, !tbaa !9
  %62 = load double, ptr @sum, align 8, !tbaa !9
  %63 = fadd double %62, %61
  store double %63, ptr @sum, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  br label %64

64:                                               ; preds = %41, %16
  %65 = load i32, ptr @t2, align 4, !tbaa !5
  %66 = load i32, ptr @T1, align 4, !tbaa !5
  %67 = icmp slt i32 %65, %66
  br i1 %67, label %68, label %96

68:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %69 = load i32, ptr @t1, align 4, !tbaa !5
  %70 = mul nsw i32 3, %69
  %71 = load i32, ptr @t2, align 4, !tbaa !5
  %72 = mul nsw i32 %70, %71
  %73 = sitofp i32 %72 to double
  %74 = load i32, ptr @T1, align 4, !tbaa !5
  %75 = sitofp i32 %74 to double
  %76 = fdiv double %73, %75
  store double %76, ptr %3, align 8, !tbaa !9
  %77 = load i32, ptr @T2, align 4, !tbaa !5
  %78 = sitofp i32 %77 to double
  %79 = load double, ptr %3, align 8, !tbaa !9
  %80 = fdiv double %79, %78
  store double %80, ptr %3, align 8, !tbaa !9
  %81 = load i32, ptr @t2, align 4, !tbaa !5
  %82 = load i32, ptr @T1, align 4, !tbaa !5
  %83 = sdiv i32 %81, %82
  %84 = sitofp i32 %83 to double
  %85 = load i32, ptr @t2, align 4, !tbaa !5
  %86 = load i32, ptr @T2, align 4, !tbaa !5
  %87 = sdiv i32 %85, %86
  %88 = sitofp i32 %87 to double
  %89 = fmul double %84, %88
  %90 = fdiv double %89, 2.000000e+00
  %91 = load double, ptr %3, align 8, !tbaa !9
  %92 = fsub double %91, %90
  store double %92, ptr %3, align 8, !tbaa !9
  %93 = load double, ptr %3, align 8, !tbaa !9
  %94 = load double, ptr @sum, align 8, !tbaa !9
  %95 = fadd double %94, %93
  store double %95, ptr @sum, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %96

96:                                               ; preds = %68, %64
  %97 = load double, ptr @sum, align 8, !tbaa !9
  %98 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %97)
  br label %5, !llvm.loop !11

99:                                               ; preds = %5
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; 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.start.p0(i64 immarg, ptr nocapture) #4

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

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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"}


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

@t = external dso_local global i32, align 4
@T1 = external dso_local global i32, align 4
@T2 = external dso_local global i32, align 4
@t1 = external dso_local global i32, align 4
@t2 = external dso_local global i32, align 4
@sum = external dso_local local_unnamed_addr global double, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not9 = icmp eq i32 %2, 0
  br i1 %.not9, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %50
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @T1, ptr noundef nonnull @T2)
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @t1, ptr noundef nonnull @t2)
  %6 = load i32, ptr @T1, align 4, !tbaa !5
  %7 = load i32, ptr @T2, align 4, !tbaa !5
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %9, label %10

9:                                                ; preds = %.lr.ph
  tail call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) @T1, ptr noundef nonnull align 4 dereferenceable(4) @T2) #4
  tail call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) @t1, ptr noundef nonnull align 4 dereferenceable(4) @t2) #4
  %.pre = load i32, ptr @T1, align 4, !tbaa !5
  %.pre10 = load i32, ptr @T2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %9, %.lr.ph
  %11 = phi i32 [ %.pre10, %9 ], [ %7, %.lr.ph ]
  %12 = phi i32 [ %.pre, %9 ], [ %6, %.lr.ph ]
  %13 = load i32, ptr @t1, align 4, !tbaa !5
  %14 = sdiv i32 %13, %12
  %15 = sitofp i32 %14 to double
  %16 = load i32, ptr @t2, align 4, !tbaa !5
  %17 = sdiv i32 %16, %11
  %18 = sitofp i32 %17 to double
  %19 = sdiv i32 %16, %12
  %20 = sitofp i32 %19 to double
  %21 = fmul double %18, %20
  %22 = fmul double %21, 5.000000e-01
  %23 = tail call double @llvm.fmuladd.f64(double %15, double %18, double %22)
  %24 = sub nsw i32 %12, %13
  %25 = icmp slt i32 %16, %24
  br i1 %25, label %26, label %37

26:                                               ; preds = %10
  %27 = add nsw i32 %16, %13
  %28 = sitofp i32 %27 to double
  %29 = sitofp i32 %12 to double
  %30 = fdiv double %28, %29
  %31 = sitofp i32 %11 to double
  %32 = fdiv double %30, %31
  %33 = sub nsw i32 %24, %16
  %34 = sitofp i32 %33 to double
  %35 = fmul double %32, %34
  %36 = fadd double %35, %23
  br label %37

37:                                               ; preds = %26, %10
  %38 = phi double [ %36, %26 ], [ %23, %10 ]
  %39 = icmp slt i32 %16, %12
  br i1 %39, label %40, label %50

40:                                               ; preds = %37
  %41 = mul nsw i32 %13, 3
  %42 = mul nsw i32 %41, %16
  %43 = sitofp i32 %42 to double
  %44 = sitofp i32 %12 to double
  %45 = fdiv double %43, %44
  %46 = sitofp i32 %11 to double
  %47 = fdiv double %45, %46
  %48 = fsub double %47, %22
  %49 = fadd double %48, %38
  br label %50

50:                                               ; preds = %40, %37
  %51 = phi double [ %49, %40 ], [ %38, %37 ]
  store double %51, ptr @sum, align 8, !tbaa !9
  %52 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %51)
  %53 = load i32, ptr @t, align 4, !tbaa !5
  %54 = add nsw i32 %53, -1
  store i32 %54, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %53, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %50, %0
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

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

attributes #0 = { mustprogress 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 = { 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 #3 = { mustprogress 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 = !{!"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"}


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