; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/LONG/AUG15/COOKMACH (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
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@cnt = 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 [5 x i8], align 1
@.str.2 = 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 = %38, %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 %41

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

9:                                                ; preds = %15, %7
  %10 = load i32, ptr @a, align 4, !tbaa !5
  %11 = load i32, ptr @a, align 4, !tbaa !5
  %12 = sub nsw i32 %11, 1
  %13 = and i32 %10, %12
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %9
  %16 = load i32, ptr @a, align 4, !tbaa !5
  %17 = ashr i32 %16, 1
  store i32 %17, ptr @a, align 4, !tbaa !5
  %18 = load i32, ptr @cnt, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @cnt, align 4, !tbaa !5
  br label %9, !llvm.loop !9

20:                                               ; preds = %9
  br label %21

21:                                               ; preds = %35, %20
  %22 = load i32, ptr @a, align 4, !tbaa !5
  %23 = load i32, ptr @b, align 4, !tbaa !5
  %24 = icmp ne i32 %22, %23
  br i1 %24, label %25, label %38

25:                                               ; preds = %21
  %26 = load i32, ptr @a, align 4, !tbaa !5
  %27 = load i32, ptr @b, align 4, !tbaa !5
  %28 = icmp sgt i32 %26, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %25
  %30 = load i32, ptr @a, align 4, !tbaa !5
  %31 = ashr i32 %30, 1
  store i32 %31, ptr @a, align 4, !tbaa !5
  br label %35

32:                                               ; preds = %25
  %33 = load i32, ptr @a, align 4, !tbaa !5
  %34 = shl i32 %33, 1
  store i32 %34, ptr @a, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %32, %29
  %36 = load i32, ptr @cnt, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr @cnt, align 4, !tbaa !5
  br label %21, !llvm.loop !11

38:                                               ; preds = %21
  %39 = load i32, ptr @cnt, align 4, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %39)
  br label %3, !llvm.loop !12

41:                                               ; 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}
!12 = distinct !{!12, !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
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@cnt = 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 [5 x i8], align 1
@.str.2 = 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
  %.not11 = icmp eq i32 %2, 0
  br i1 %.not11, label %._crit_edge14, label %.lr.ph13

.lr.ph13:                                         ; preds = %0, %20
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %a.promoted = load i32, ptr @a, align 4, !tbaa !5
  %5 = add nsw i32 %a.promoted, -1
  %6 = and i32 %5, %a.promoted
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %.preheader

..preheader_crit_edge:                            ; preds = %.lr.ph
  store i32 %10, ptr @a, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %..preheader_crit_edge, %.lr.ph13
  %a.promoted5 = phi i32 [ %10, %..preheader_crit_edge ], [ %a.promoted, %.lr.ph13 ]
  %storemerge.lcssa = phi i32 [ %11, %..preheader_crit_edge ], [ 0, %.lr.ph13 ]
  store i32 %storemerge.lcssa, ptr @cnt, align 4, !tbaa !5
  %8 = load i32, ptr @b, align 4, !tbaa !5
  %.not27 = icmp eq i32 %a.promoted5, %8
  br i1 %.not27, label %20, label %.lr.ph9

.lr.ph:                                           ; preds = %.lr.ph13, %.lr.ph
  %storemerge4 = phi i32 [ %11, %.lr.ph ], [ 0, %.lr.ph13 ]
  %9 = phi i32 [ %10, %.lr.ph ], [ %a.promoted, %.lr.ph13 ]
  %10 = ashr i32 %9, 1
  %11 = add nuw nsw i32 %storemerge4, 1
  %12 = add nsw i32 %10, -1
  %13 = and i32 %12, %10
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %..preheader_crit_edge, !llvm.loop !9

.lr.ph9:                                          ; preds = %.preheader, %.lr.ph9
  %storemerge368 = phi i32 [ %storemerge3, %.lr.ph9 ], [ %a.promoted5, %.preheader ]
  %15 = phi i32 [ %19, %.lr.ph9 ], [ %storemerge.lcssa, %.preheader ]
  %16 = icmp sgt i32 %storemerge368, %8
  %17 = shl i32 %storemerge368, 1
  %18 = ashr i32 %storemerge368, 1
  %storemerge3 = select i1 %16, i32 %18, i32 %17
  %19 = add nsw i32 %15, 1
  %.not2 = icmp eq i32 %storemerge3, %8
  br i1 %.not2, label %._crit_edge, label %.lr.ph9, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph9
  store i32 %8, ptr @a, align 4, !tbaa !5
  store i32 %19, ptr @cnt, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %._crit_edge, %.preheader
  %21 = phi i32 [ %19, %._crit_edge ], [ %storemerge.lcssa, %.preheader ]
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %21)
  %23 = load i32, ptr @t, align 4, !tbaa !5
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %._crit_edge14, label %.lr.ph13, !llvm.loop !12

._crit_edge14:                                    ; preds = %20, %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}
!12 = distinct !{!12, !10}


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