; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/65 Beta Divison 2/Problem C (C)

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

8:                                                ; preds = %18, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %21

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100000 x i32], ptr @m, i64 0, i64 %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %16)
  br label %18

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

21:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 3, ptr %3, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %79, %21
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 5, ptr %4, align 4
  br label %82

27:                                               ; preds = %22
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = srem i32 %28, %29
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %78

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %72, %32
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sdiv i32 %35, %36
  %38 = icmp slt i32 %34, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %33
  store i32 8, ptr %4, align 4
  br label %75

40:                                               ; preds = %33
  store i32 1, ptr @flag, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %41, ptr @cur, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %62, %40
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  store i32 11, ptr %4, align 4
  br label %65

47:                                               ; preds = %42
  %48 = load i32, ptr @cur, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100000 x i32], ptr @m, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = icmp ne i32 %51, 1
  br i1 %52, label %53, label %54

53:                                               ; preds = %47
  store i32 0, ptr @flag, align 4, !tbaa !5
  store i32 11, ptr %4, align 4
  br label %65

54:                                               ; preds = %47
  %55 = load i32, ptr @cur, align 4, !tbaa !5
  %56 = load i32, ptr @n, align 4, !tbaa !5
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = sdiv i32 %56, %57
  %59 = add nsw i32 %55, %58
  %60 = load i32, ptr @n, align 4, !tbaa !5
  %61 = srem i32 %59, %60
  store i32 %61, ptr @cur, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %54
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %6, align 4, !tbaa !5
  br label %42, !llvm.loop !11

65:                                               ; preds = %53, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr @flag, align 4, !tbaa !5
  %68 = icmp eq i32 %67, 1
  br i1 %68, label %69, label %71

69:                                               ; preds = %66
  %70 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %75

71:                                               ; preds = %66
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %5, align 4, !tbaa !5
  br label %33, !llvm.loop !12

75:                                               ; preds = %69, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %76 = load i32, ptr %4, align 4
  switch i32 %76, label %82 [
    i32 8, label %77
  ]

77:                                               ; preds = %75
  br label %78

78:                                               ; preds = %77, %27
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %3, align 4, !tbaa !5
  br label %22, !llvm.loop !13

82:                                               ; preds = %75, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %83 = load i32, ptr %4, align 4
  switch i32 %83, label %88 [
    i32 5, label %84
    i32 1, label %86
  ]

84:                                               ; preds = %82
  %85 = call i32 @puts(ptr noundef @.str.2)
  store i32 0, ptr %1, align 4
  br label %86

86:                                               ; preds = %84, %82
  %87 = load i32, ptr %1, align 4
  ret i32 %87

88:                                               ; preds = %82
  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 @puts(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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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 [100000 x i32], align 16
@flag = external dso_local local_unnamed_addr global i32, align 4
@cur = 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
@.str.2 = external hidden unnamed_addr constant [3 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)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

.preheader32:                                     ; preds = %.lr.ph
  %.not46 = icmp slt i32 %6, 3
  br i1 %.not46, label %._crit_edge, label %.lr.ph50

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %4 = getelementptr inbounds [100000 x i32], ptr @m, i64 0, i64 %indvars.iv
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %4)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = icmp slt i64 %indvars.iv.next, %7
  br i1 %8, label %.lr.ph, label %.preheader32, !llvm.loop !9

.lr.ph50:                                         ; preds = %.preheader32, %.thread26
  %.01947 = phi i32 [ %22, %.thread26 ], [ 3, %.preheader32 ]
  %9 = urem i32 %6, %.01947
  %10 = udiv i32 %6, %.01947
  %11 = icmp eq i32 %9, 0
  %.not2536 = icmp sgt i32 %10, 0
  %or.cond = and i1 %11, %.not2536
  br i1 %or.cond, label %.lr.ph38.split.us, label %.thread26

.lr.ph38.split.us:                                ; preds = %.lr.ph50, %.thread.us
  %.01737.us = phi i32 [ %17, %.thread.us ], [ 0, %.lr.ph50 ]
  br label %12

.split.us:                                        ; preds = %18
  store i32 1, ptr @flag, align 4, !tbaa !5
  store i32 %20, ptr @cur, align 4, !tbaa !5
  br label %._crit_edge

12:                                               ; preds = %18, %.lr.ph38.split.us
  %.034.us = phi i32 [ 0, %.lr.ph38.split.us ], [ %21, %18 ]
  %13 = phi i32 [ %.01737.us, %.lr.ph38.split.us ], [ %20, %18 ]
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100000 x i32], ptr @m, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %.not24.us = icmp eq i32 %16, 1
  br i1 %.not24.us, label %18, label %.thread.us

.thread.us:                                       ; preds = %12
  %17 = add nuw nsw i32 %.01737.us, 1
  %exitcond54.not = icmp eq i32 %17, %10
  br i1 %exitcond54.not, label %..thread26.loopexit_crit_edge, label %.lr.ph38.split.us, !llvm.loop !11

18:                                               ; preds = %12
  %19 = add nsw i32 %13, %10
  %20 = srem i32 %19, %6
  %21 = add nuw nsw i32 %.034.us, 1
  %exitcond.not = icmp eq i32 %21, %.01947
  br i1 %exitcond.not, label %.split.us, label %12, !llvm.loop !12

..thread26.loopexit_crit_edge:                    ; preds = %.thread.us
  store i32 0, ptr @flag, align 4, !tbaa !5
  store i32 %13, ptr @cur, align 4, !tbaa !5
  br label %.thread26

.thread26:                                        ; preds = %..thread26.loopexit_crit_edge, %.lr.ph50
  %22 = add nuw nsw i32 %.01947, 1
  %.not.not = icmp slt i32 %.01947, %6
  br i1 %.not.not, label %.lr.ph50, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.thread26, %.preheader32, %0, %.split.us
  %.str.1.sink = phi ptr [ @.str.1, %.split.us ], [ @.str.2, %0 ], [ @.str.2, %.preheader32 ], [ @.str.2, %.thread26 ]
  %23 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.1.sink)
  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 @puts(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}
!13 = distinct !{!13, !10}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass