; LLVM IR from tangjz/acm-icpc :: codeforces/gym (100506C)

; 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
@n = external dso_local global i32, align 4
@r = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@s = 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 [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3gcdii(i32 noundef, i32 noundef) #0

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

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

7:                                                ; preds = %3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @s, ptr noundef @n, ptr noundef @r)
  %9 = load double, ptr @s, align 8, !tbaa !9
  %10 = fmul double %9, 4.000000e+00
  store double %10, ptr @s, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %15, %7
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = add nsw i32 %12, -1
  store i32 %13, ptr @n, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %11
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  %17 = load i32, ptr @r, align 4, !tbaa !5
  %18 = load i32, ptr @x, align 4, !tbaa !5
  %19 = call noundef i32 @_Z3gcdii(i32 noundef %17, i32 noundef %18)
  store i32 %19, ptr @r, align 4, !tbaa !5
  br label %11, !llvm.loop !11

20:                                               ; preds = %11
  br label %21

21:                                               ; preds = %26, %20
  %22 = load i32, ptr @r, align 4, !tbaa !5
  %23 = xor i32 %22, -1
  %24 = and i32 %23, 1
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %21
  %27 = load i32, ptr @r, align 4, !tbaa !5
  %28 = ashr i32 %27, 1
  store i32 %28, ptr @r, align 4, !tbaa !5
  br label %21, !llvm.loop !13

29:                                               ; preds = %21
  %30 = load double, ptr @s, align 8, !tbaa !9
  %31 = load double, ptr @s, align 8, !tbaa !9
  %32 = fptosi double %31 to i32
  %33 = sitofp i32 %32 to double
  %34 = fadd double %33, 0x3EB0C6F7A0B5ED8D
  %35 = fcmp ole double %30, %34
  br i1 %35, label %36, label %42

36:                                               ; preds = %29
  %37 = load double, ptr @s, align 8, !tbaa !9
  %38 = fptosi double %37 to i32
  %39 = load i32, ptr @r, align 4, !tbaa !5
  %40 = srem i32 %38, %39
  %41 = icmp eq i32 %40, 0
  br label %42

42:                                               ; preds = %36, %29
  %43 = phi i1 [ false, %29 ], [ %41, %36 ]
  %44 = zext i1 %43 to i64
  %45 = select i1 %43, ptr @.str.2, ptr @.str.3
  %46 = call i32 @puts(ptr noundef %45)
  br label %3, !llvm.loop !14

47:                                               ; preds = %3
  ret i32 0
}

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

declare i32 @puts(ptr noundef) #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 = { 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 #2 = { "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}
!14 = distinct !{!14, !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"

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@r = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@s = 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 [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3gcdii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %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
  %.not8 = icmp eq i32 %2, 0
  br i1 %.not8, label %._crit_edge11, label %.lr.ph10

.lr.ph10:                                         ; preds = %0, %.thread
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @s, ptr noundef nonnull @n, ptr noundef nonnull @r)
  %5 = load double, ptr @s, align 8, !tbaa !9
  %6 = fmul double %5, 4.000000e+00
  store double %6, ptr @s, align 8, !tbaa !9
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @n, align 4, !tbaa !5
  %.not14 = icmp eq i32 %8, 0
  br i1 %.not14, label %.lr.ph10..preheader_crit_edge, label %.lr.ph

.lr.ph10..preheader_crit_edge:                    ; preds = %.lr.ph10
  %r.promoted.pre = load i32, ptr @r, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph, %.lr.ph10..preheader_crit_edge
  %r.promoted = phi i32 [ %r.promoted.pre, %.lr.ph10..preheader_crit_edge ], [ %13, %.lr.ph ]
  %9 = and i32 %r.promoted, 1
  %.not2.not5 = icmp eq i32 %9, 0
  br i1 %.not2.not5, label %.lr.ph6, label %19

.lr.ph:                                           ; preds = %.lr.ph10, %.lr.ph
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %11 = load i32, ptr @r, align 4, !tbaa !5
  %12 = load i32, ptr @x, align 4, !tbaa !5
  %13 = tail call noundef i32 @_Z3gcdii(i32 noundef %11, i32 noundef %12)
  store i32 %13, ptr @r, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr @n, align 4, !tbaa !5
  %.not1 = icmp eq i32 %15, 0
  br i1 %.not1, label %.preheader, label %.lr.ph, !llvm.loop !11

.lr.ph6:                                          ; preds = %.preheader, %.lr.ph6
  %16 = phi i32 [ %17, %.lr.ph6 ], [ %r.promoted, %.preheader ]
  %17 = ashr exact i32 %16, 1
  %18 = and i32 %16, 2
  %.not2.not = icmp eq i32 %18, 0
  br i1 %.not2.not, label %.lr.ph6, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph6
  store i32 %17, ptr @r, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %._crit_edge, %.preheader
  %.lcssa = phi i32 [ %17, %._crit_edge ], [ %r.promoted, %.preheader ]
  %20 = load double, ptr @s, align 8, !tbaa !9
  %21 = fptosi double %20 to i32
  %22 = sitofp i32 %21 to double
  %23 = fadd double %22, 0x3EB0C6F7A0B5ED8D
  %24 = fcmp ugt double %20, %23
  br i1 %24, label %.thread, label %25

25:                                               ; preds = %19
  %26 = srem i32 %21, %.lcssa
  %.fr = freeze i32 %26
  %27 = icmp eq i32 %.fr, 0
  %spec.select = select i1 %27, ptr @.str.2, ptr @.str.3
  br label %.thread

.thread:                                          ; preds = %25, %19
  %28 = phi ptr [ @.str.3, %19 ], [ %spec.select, %25 ]
  %29 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %28)
  %30 = load i32, ptr @t, align 4, !tbaa !5
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %._crit_edge11, label %.lr.ph10, !llvm.loop !14

._crit_edge11:                                    ; preds = %.thread, %0
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #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 = { 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 #2 = { 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" }

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


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