; LLVM IR from tangjz/acm-icpc :: lydsy (4106)

; 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 i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@last = external dso_local global double, align 8
@now = external dso_local global double, align 8
@ans = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %3

3:                                                ; preds = %58, %0
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @p, ptr noundef @a, ptr noundef @b, ptr noundef @c, ptr noundef @d, ptr noundef @n)
  %5 = icmp eq i32 %4, 6
  br i1 %5, label %6, label %64

6:                                                ; preds = %3
  store double 0.000000e+00, ptr @ans, align 8, !tbaa !5
  %7 = load i32, ptr @a, align 4, !tbaa !9
  %8 = load i32, ptr @b, align 4, !tbaa !9
  %9 = add nsw i32 %7, %8
  %10 = sitofp i32 %9 to double
  %11 = call double @sin(double noundef %10) #4
  %12 = load i32, ptr @c, align 4, !tbaa !9
  %13 = load i32, ptr @d, align 4, !tbaa !9
  %14 = add nsw i32 %12, %13
  %15 = sitofp i32 %14 to double
  %16 = call double @cos(double noundef %15) #4
  %17 = fadd double %11, %16
  store double %17, ptr @last, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 2, ptr %2, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %55, %6
  %19 = load i32, ptr %2, align 4, !tbaa !9
  %20 = load i32, ptr @n, align 4, !tbaa !9
  %21 = icmp sle i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %58

23:                                               ; preds = %18
  %24 = load i32, ptr @a, align 4, !tbaa !9
  %25 = load i32, ptr %2, align 4, !tbaa !9
  %26 = mul nsw i32 %24, %25
  %27 = load i32, ptr @b, align 4, !tbaa !9
  %28 = add nsw i32 %26, %27
  %29 = sitofp i32 %28 to double
  %30 = call double @sin(double noundef %29) #4
  %31 = load i32, ptr @c, align 4, !tbaa !9
  %32 = load i32, ptr %2, align 4, !tbaa !9
  %33 = mul nsw i32 %31, %32
  %34 = load i32, ptr @d, align 4, !tbaa !9
  %35 = add nsw i32 %33, %34
  %36 = sitofp i32 %35 to double
  %37 = call double @cos(double noundef %36) #4
  %38 = fadd double %30, %37
  store double %38, ptr @now, align 8, !tbaa !5
  %39 = load double, ptr @ans, align 8, !tbaa !5
  %40 = load double, ptr @last, align 8, !tbaa !5
  %41 = load double, ptr @now, align 8, !tbaa !5
  %42 = fsub double %40, %41
  %43 = fcmp olt double %39, %42
  br i1 %43, label %44, label %48

44:                                               ; preds = %23
  %45 = load double, ptr @last, align 8, !tbaa !5
  %46 = load double, ptr @now, align 8, !tbaa !5
  %47 = fsub double %45, %46
  store double %47, ptr @ans, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %44, %23
  %49 = load double, ptr @last, align 8, !tbaa !5
  %50 = load double, ptr @now, align 8, !tbaa !5
  %51 = fcmp olt double %49, %50
  br i1 %51, label %52, label %54

52:                                               ; preds = %48
  %53 = load double, ptr @now, align 8, !tbaa !5
  store double %53, ptr @last, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %52, %48
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %2, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %2, align 4, !tbaa !9
  br label %18, !llvm.loop !11

58:                                               ; preds = %22
  %59 = load double, ptr @ans, align 8, !tbaa !5
  %60 = load i32, ptr @p, align 4, !tbaa !9
  %61 = sitofp i32 %60 to double
  %62 = fmul double %59, %61
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %62)
  br label %3, !llvm.loop !13

64:                                               ; preds = %3
  ret i32 0
}

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

; Function Attrs: nounwind
declare double @sin(double noundef) #2

; Function Attrs: nounwind
declare double @cos(double noundef) #2

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

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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}
!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"

@p = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@last = external dso_local local_unnamed_addr global double, align 8
@now = external dso_local local_unnamed_addr global double, align 8
@ans = external dso_local local_unnamed_addr global double, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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 @p, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @c, ptr noundef nonnull @d, ptr noundef nonnull @n)
  %2 = icmp eq i32 %1, 6
  br i1 %2, label %.lr.ph9, label %._crit_edge10

.lr.ph9:                                          ; preds = %0, %._crit_edge
  store double 0.000000e+00, ptr @ans, align 8, !tbaa !5
  %3 = load i32, ptr @a, align 4, !tbaa !9
  %4 = load i32, ptr @b, align 4, !tbaa !9
  %5 = add nsw i32 %4, %3
  %6 = sitofp i32 %5 to double
  %7 = tail call double @sin(double noundef %6) #3
  %8 = load i32, ptr @c, align 4, !tbaa !9
  %9 = load i32, ptr @d, align 4, !tbaa !9
  %10 = add nsw i32 %9, %8
  %11 = sitofp i32 %10 to double
  %12 = tail call double @cos(double noundef %11) #3
  %13 = fadd double %7, %12
  store double %13, ptr @last, align 8, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !9
  %.not6 = icmp slt i32 %14, 2
  br i1 %.not6, label %.lr.ph9.._crit_edge_crit_edge, label %.lr.ph

.lr.ph9.._crit_edge_crit_edge:                    ; preds = %.lr.ph9
  %.pre = load double, ptr @ans, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %44, %.lr.ph9.._crit_edge_crit_edge
  %15 = phi double [ %.pre, %.lr.ph9.._crit_edge_crit_edge ], [ %41, %44 ]
  %16 = load i32, ptr @p, align 4, !tbaa !9
  %17 = sitofp i32 %16 to double
  %18 = fmul double %15, %17
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %18)
  %20 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @p, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @c, ptr noundef nonnull @d, ptr noundef nonnull @n)
  %21 = icmp eq i32 %20, 6
  br i1 %21, label %.lr.ph9, label %._crit_edge10, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph9, %44
  %.07 = phi i32 [ %45, %44 ], [ 2, %.lr.ph9 ]
  %22 = load i32, ptr @a, align 4, !tbaa !9
  %23 = mul nsw i32 %22, %.07
  %24 = load i32, ptr @b, align 4, !tbaa !9
  %25 = add nsw i32 %23, %24
  %26 = sitofp i32 %25 to double
  %27 = tail call double @sin(double noundef %26) #3
  %28 = load i32, ptr @c, align 4, !tbaa !9
  %29 = mul nsw i32 %28, %.07
  %30 = load i32, ptr @d, align 4, !tbaa !9
  %31 = add nsw i32 %29, %30
  %32 = sitofp i32 %31 to double
  %33 = tail call double @cos(double noundef %32) #3
  %34 = fadd double %27, %33
  store double %34, ptr @now, align 8, !tbaa !5
  %35 = load double, ptr @ans, align 8, !tbaa !5
  %36 = load double, ptr @last, align 8, !tbaa !5
  %37 = fsub double %36, %34
  %38 = fcmp olt double %35, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %.lr.ph
  store double %37, ptr @ans, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %39, %.lr.ph
  %41 = phi double [ %37, %39 ], [ %35, %.lr.ph ]
  %42 = fcmp olt double %36, %34
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  store double %34, ptr @last, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %40, %43
  %45 = add nuw nsw i32 %.07, 1
  %46 = load i32, ptr @n, align 4, !tbaa !9
  %.not.not = icmp slt i32 %.07, %46
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !13

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #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 nofree nounwind willreturn memory(write) "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 = { 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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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