; LLVM IR from tangjz/acm-icpc :: codeforces/complete (796B)

; 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
@q = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@vis = external dso_local global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 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
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @q)
  br label %7

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

11:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2)
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %14
  store i8 1, ptr %15, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %7, !llvm.loop !11

16:                                               ; preds = %7
  store i32 1, ptr @p, align 4, !tbaa !5
  %17 = load i32, ptr @p, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !9, !range !13, !noundef !14
  %21 = trunc i8 %20 to i1
  br i1 %21, label %22, label %25

22:                                               ; preds = %16
  %23 = load i32, ptr @p, align 4, !tbaa !5
  %24 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %23)
  store i32 0, ptr %1, align 4
  br label %61

25:                                               ; preds = %16
  br label %26

26:                                               ; preds = %57, %55, %25
  %27 = load i32, ptr @q, align 4, !tbaa !5
  %28 = add nsw i32 %27, -1
  store i32 %28, ptr @q, align 4, !tbaa !5
  %29 = icmp ne i32 %27, 0
  br i1 %29, label %30, label %58

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.3, ptr noundef %3, ptr noundef %4)
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr @p, align 4, !tbaa !5
  %34 = icmp eq i32 %32, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %30
  %36 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %36, ptr @p, align 4, !tbaa !5
  br label %45

37:                                               ; preds = %30
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = load i32, ptr @p, align 4, !tbaa !5
  %40 = icmp eq i32 %38, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %37
  %42 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %42, ptr @p, align 4, !tbaa !5
  br label %44

43:                                               ; preds = %37
  store i32 4, ptr %5, align 4
  br label %55, !llvm.loop !15

44:                                               ; preds = %41
  br label %45

45:                                               ; preds = %44, %35
  %46 = load i32, ptr @p, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !9, !range !13, !noundef !14
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %54

51:                                               ; preds = %45
  %52 = load i32, ptr @p, align 4, !tbaa !5
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %52)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %55

54:                                               ; preds = %45
  store i32 0, ptr %5, align 4
  br label %55

55:                                               ; preds = %54, %51, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %56 = load i32, ptr %5, align 4
  switch i32 %56, label %63 [
    i32 0, label %57
    i32 4, label %26
    i32 1, label %61
  ]

57:                                               ; preds = %55
  br label %26, !llvm.loop !15

58:                                               ; preds = %26
  %59 = load i32, ptr @p, align 4, !tbaa !5
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %59)
  store i32 0, ptr %1, align 4
  br label %61

61:                                               ; preds = %58, %55, %22
  %62 = load i32, ptr %1, align 4
  ret i32 %62

63:                                               ; preds = %55
  unreachable
}

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

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

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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !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"

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@p = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local local_unnamed_addr global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @q)
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @m, align 4, !tbaa !5
  %.not9 = icmp eq i32 %5, 0
  br i1 %.not9, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %9
  store i8 1, ptr %10, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  %11 = load i32, ptr @m, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr @m, align 4, !tbaa !5
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %0
  store i32 1, ptr @p, align 4, !tbaa !5
  %13 = load i8, ptr getelementptr inbounds (i8, ptr @vis, i64 1), align 1, !tbaa !9, !range !13, !noundef !14
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %17, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %15 = load i32, ptr @q, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr @q, align 4, !tbaa !5
  %.not510 = icmp eq i32 %15, 0
  br i1 %.not510, label %._crit_edge12, label %.lr.ph11

17:                                               ; preds = %._crit_edge
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef 1)
  br label %38

.lr.ph11:                                         ; preds = %.preheader, %32
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.3, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = load i32, ptr @p, align 4, !tbaa !5
  %22 = icmp eq i32 %20, %21
  %23 = load i32, ptr %3, align 4, !tbaa !5
  br i1 %22, label %26, label %24

24:                                               ; preds = %.lr.ph11
  %25 = icmp eq i32 %23, %21
  br i1 %25, label %26, label %32, !llvm.loop !15

26:                                               ; preds = %.lr.ph11, %24
  %storemerge = phi i32 [ %20, %24 ], [ %23, %.lr.ph11 ]
  store i32 %storemerge, ptr @p, align 4, !tbaa !5
  %27 = sext i32 %storemerge to i64
  %28 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !9, !range !13, !noundef !14
  %30 = trunc nuw i8 %29 to i1
  br i1 %30, label %.thread, label %32

.thread:                                          ; preds = %26
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %storemerge)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  br label %38

32:                                               ; preds = %26, %24
  %33 = phi i32 [ %storemerge, %26 ], [ %21, %24 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  %34 = load i32, ptr @q, align 4, !tbaa !5
  %35 = add nsw i32 %34, -1
  store i32 %35, ptr @q, align 4, !tbaa !5
  %.not5 = icmp eq i32 %34, 0
  br i1 %.not5, label %._crit_edge12, label %.lr.ph11

._crit_edge12:                                    ; preds = %32, %.preheader
  %36 = phi i32 [ 1, %.preheader ], [ %33, %32 ]
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %36)
  br label %38

38:                                               ; preds = %.thread, %._crit_edge12, %17
  ret i32 0
}

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}


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