; LLVM IR from tangjz/acm-icpc :: Summer_Training/2016-07-21 (K - Keep On Movin - lizy)

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %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 %43

7:                                                ; preds = %3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 0, ptr @y, align 4, !tbaa !5
  store i32 0, ptr @x, align 4, !tbaa !5
  br label %9

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

13:                                               ; preds = %9
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @a)
  %15 = load i32, ptr @a, align 4, !tbaa !5
  %16 = and i32 %15, 1
  %17 = load i32, ptr @x, align 4, !tbaa !5
  %18 = add nsw i32 %17, %16
  store i32 %18, ptr @x, align 4, !tbaa !5
  %19 = load i32, ptr @a, align 4, !tbaa !5
  %20 = ashr i32 %19, 1
  %21 = load i32, ptr @y, align 4, !tbaa !5
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr @y, align 4, !tbaa !5
  br label %9, !llvm.loop !9

23:                                               ; preds = %9
  %24 = load i32, ptr @x, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %30

26:                                               ; preds = %23
  %27 = load i32, ptr @y, align 4, !tbaa !5
  %28 = mul nsw i32 %27, 2
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %28)
  br label %42

30:                                               ; preds = %23
  %31 = load i32, ptr @y, align 4, !tbaa !5
  %32 = load i32, ptr @x, align 4, !tbaa !5
  %33 = srem i32 %31, %32
  %34 = load i32, ptr @y, align 4, !tbaa !5
  %35 = sub nsw i32 %34, %33
  store i32 %35, ptr @y, align 4, !tbaa !5
  %36 = load i32, ptr @y, align 4, !tbaa !5
  %37 = load i32, ptr @x, align 4, !tbaa !5
  %38 = sdiv i32 %36, %37
  %39 = mul nsw i32 %38, 2
  %40 = add nsw i32 %39, 1
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %40)
  br label %42

42:                                               ; preds = %30, %26
  br label %3, !llvm.loop !11

43:                                               ; preds = %3
  ret i32 0
}

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

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; 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
@a = external dso_local global i32, align 4
@x = external dso_local local_unnamed_addr global i32, align 4
@y = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 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 @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
  %.not3 = icmp eq i32 %2, 0
  br i1 %.not3, label %._crit_edge6, label %.lr.ph5

.lr.ph5:                                          ; preds = %0, %26
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  store i32 0, ptr @y, align 4, !tbaa !5
  store i32 0, ptr @x, align 4, !tbaa !5
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @n, align 4, !tbaa !5
  %.not12 = icmp eq i32 %5, 0
  br i1 %.not12, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph5, %.lr.ph
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @a)
  %8 = load i32, ptr @a, align 4, !tbaa !5
  %9 = and i32 %8, 1
  %10 = load i32, ptr @x, align 4, !tbaa !5
  %11 = add nsw i32 %10, %9
  store i32 %11, ptr @x, align 4, !tbaa !5
  %12 = ashr i32 %8, 1
  %13 = load i32, ptr @y, align 4, !tbaa !5
  %14 = add nsw i32 %13, %12
  store i32 %14, ptr @y, align 4, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr @n, align 4, !tbaa !5
  %.not1 = icmp eq i32 %15, 0
  br i1 %.not1, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  %17 = icmp eq i32 %11, 0
  br i1 %17, label %._crit_edge.thread, label %20

._crit_edge.thread:                               ; preds = %.lr.ph5, %._crit_edge
  %18 = phi i32 [ %14, %._crit_edge ], [ 0, %.lr.ph5 ]
  %19 = shl nsw i32 %18, 1
  br label %26

20:                                               ; preds = %._crit_edge
  %21 = srem i32 %14, %11
  %22 = sub nsw i32 %14, %21
  store i32 %22, ptr @y, align 4, !tbaa !5
  %23 = sdiv i32 %14, %11
  %24 = shl nsw i32 %23, 1
  %25 = or disjoint i32 %24, 1
  br label %26

26:                                               ; preds = %20, %._crit_edge.thread
  %.sink = phi i32 [ %25, %20 ], [ %19, %._crit_edge.thread ]
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.sink)
  %28 = load i32, ptr @T, align 4, !tbaa !5
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr @T, align 4, !tbaa !5
  %.not = icmp eq i32 %28, 0
  br i1 %.not, label %._crit_edge6, label %.lr.ph5, !llvm.loop !11

._crit_edge6:                                     ; preds = %26, %0
  ret i32 0
}

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

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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