; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/250 Division 2/Problem B (test)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@sc = external dso_local global [105000 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = 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
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %53, %0
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %13

9:                                                ; preds = %6
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load i32, ptr @m, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br label %13

13:                                               ; preds = %9, %6
  %14 = phi i1 [ false, %6 ], [ %12, %9 ]
  br i1 %14, label %15, label %56

15:                                               ; preds = %13
  %16 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %16, ptr %3, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %47, %15
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = load i32, ptr @m, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %21, label %52

21:                                               ; preds = %17
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %46

24:                                               ; preds = %21
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = and i32 %25, %26
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %36, label %29

29:                                               ; preds = %24
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = mul nsw i32 %31, 2
  %33 = add nsw i32 %30, %32
  %34 = load i32, ptr @m, align 4, !tbaa !5
  %35 = icmp sle i32 %33, %34
  br i1 %35, label %36, label %45

36:                                               ; preds = %29, %24
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = load i32, ptr @sc, align 16, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr @sc, align 16, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [105000 x i32], ptr @sc, i64 0, i64 %40
  store i32 %37, ptr %41, align 4, !tbaa !5
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = load i32, ptr @n, align 4, !tbaa !5
  %44 = sub nsw i32 %43, %42
  store i32 %44, ptr @n, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %36, %29
  br label %46

46:                                               ; preds = %45, %21
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = mul nsw i32 %48, 2
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, %49
  store i32 %51, ptr %3, align 4, !tbaa !5
  br label %17, !llvm.loop !9

52:                                               ; preds = %17
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = shl i32 %54, 1
  store i32 %55, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !11

56:                                               ; preds = %13
  %57 = load i32, ptr @n, align 4, !tbaa !5
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %61

59:                                               ; preds = %56
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %83

61:                                               ; preds = %56
  %62 = load i32, ptr @sc, align 16, !tbaa !5
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %62)
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %74, %61
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = load i32, ptr @sc, align 16, !tbaa !5
  %67 = icmp slt i32 %65, %66
  br i1 %67, label %68, label %77

68:                                               ; preds = %64
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [105000 x i32], ptr @sc, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %72)
  br label %74

74:                                               ; preds = %68
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %2, align 4, !tbaa !5
  br label %64, !llvm.loop !12

77:                                               ; preds = %64
  %78 = load i32, ptr @sc, align 16, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [105000 x i32], ptr @sc, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %81)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %83

83:                                               ; preds = %77, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %84 = load i32, ptr %1, align 4
  ret i32 %84
}

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

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

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

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

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@sc = external dso_local local_unnamed_addr global [105000 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = 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 @n, ptr noundef nonnull @m)
  %2 = load i32, ptr @m, align 4
  %n.promoted25 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp ne i32 %n.promoted25, 0
  %4 = icmp sgt i32 %2, 0
  %5 = select i1 %3, i1 %4, i1 false
  br i1 %5, label %.preheader, label %._crit_edge

.preheader:                                       ; preds = %0, %20
  %.01530 = phi i32 [ %6, %20 ], [ 1, %0 ]
  %n.promoted2829 = phi i32 [ %n.promoted26, %20 ], [ %n.promoted25, %0 ]
  %6 = shl i32 %.01530, 1
  br label %7

7:                                                ; preds = %.preheader, %18
  %n.promoted27 = phi i32 [ %n.promoted2829, %.preheader ], [ %n.promoted26, %18 ]
  %.024 = phi i32 [ %.01530, %.preheader ], [ %.pre-phi, %18 ]
  %8 = phi i32 [ %n.promoted2829, %.preheader ], [ %19, %18 ]
  %.not20 = icmp eq i32 %8, 0
  br i1 %.not20, label %._crit_edge38, label %9

._crit_edge38:                                    ; preds = %7
  %.pre = add nsw i32 %.024, %6
  br label %18

9:                                                ; preds = %7
  %10 = and i32 %8, %.01530
  %.not21 = icmp eq i32 %10, 0
  %11 = add nsw i32 %.024, %6
  %.not22 = icmp sgt i32 %11, %2
  %or.cond = select i1 %.not21, i1 %.not22, i1 false
  br i1 %or.cond, label %18, label %12

12:                                               ; preds = %9
  %13 = load i32, ptr @sc, align 16, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr @sc, align 16, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [105000 x i32], ptr @sc, i64 0, i64 %15
  store i32 %.024, ptr %16, align 4, !tbaa !5
  %17 = sub nsw i32 %8, %.01530
  store i32 %17, ptr @n, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %._crit_edge38, %9, %12
  %.pre-phi = phi i32 [ %.pre, %._crit_edge38 ], [ %11, %9 ], [ %11, %12 ]
  %n.promoted26 = phi i32 [ %n.promoted27, %._crit_edge38 ], [ %n.promoted27, %9 ], [ %17, %12 ]
  %19 = phi i32 [ 0, %._crit_edge38 ], [ %8, %9 ], [ %17, %12 ]
  %.not = icmp sgt i32 %.pre-phi, %2
  br i1 %.not, label %20, label %7, !llvm.loop !9

20:                                               ; preds = %18
  %21 = icmp ne i32 %n.promoted26, 0
  %22 = icmp sle i32 %6, %2
  %23 = select i1 %21, i1 %22, i1 false
  br i1 %23, label %.preheader, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %20, %0
  %.lcssa23 = phi i1 [ %3, %0 ], [ %21, %20 ]
  br i1 %.lcssa23, label %24, label %26

24:                                               ; preds = %._crit_edge
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %40

26:                                               ; preds = %._crit_edge
  %27 = load i32, ptr @sc, align 16, !tbaa !5
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %27)
  %29 = load i32, ptr @sc, align 16, !tbaa !5
  %30 = icmp sgt i32 %29, 1
  br i1 %30, label %.lr.ph, label %.._crit_edge33_crit_edge

.._crit_edge33_crit_edge:                         ; preds = %26
  %.pre39 = sext i32 %29 to i64
  br label %._crit_edge33

.lr.ph:                                           ; preds = %26, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %26 ]
  %31 = getelementptr inbounds [105000 x i32], ptr @sc, i64 0, i64 %indvars.iv
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %32)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %34 = load i32, ptr @sc, align 16, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = icmp slt i64 %indvars.iv.next, %35
  br i1 %36, label %.lr.ph, label %._crit_edge33, !llvm.loop !12

._crit_edge33:                                    ; preds = %.lr.ph, %.._crit_edge33_crit_edge
  %.pre-phi40 = phi i64 [ %.pre39, %.._crit_edge33_crit_edge ], [ %35, %.lr.ph ]
  %37 = getelementptr inbounds [105000 x i32], ptr @sc, i64 0, i64 %.pre-phi40
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %38)
  br label %40

40:                                               ; preds = %._crit_edge33, %24
  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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass