; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 1174C. Ehab and a Special Coloring Problem (main)

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

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

6:                                                ; preds = %14, %0
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp sle i32 %7, 100005
  br i1 %8, label %9, label %17

9:                                                ; preds = %6
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100005 x i32], ptr @arr, i64 0, i64 %12
  store i32 %10, ptr %13, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %9
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = add nsw i32 %15, 2
  store i32 %16, ptr %3, align 4, !tbaa !5
  br label %6, !llvm.loop !9

17:                                               ; preds = %6
  store i32 3, ptr %3, align 4, !tbaa !5
  br label %18

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

21:                                               ; preds = %18
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100005 x i32], ptr @arr, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %51, label %27

27:                                               ; preds = %21
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %5, align 4, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %30, ptr %4, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %46, %27
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = icmp sle i32 %32, 100005
  br i1 %33, label %34, label %50

34:                                               ; preds = %31
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100005 x i32], ptr @arr, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %45, label %40

40:                                               ; preds = %34
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100005 x i32], ptr @arr, i64 0, i64 %43
  store i32 %41, ptr %44, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %40, %34
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = add nsw i32 %48, %47
  store i32 %49, ptr %4, align 4, !tbaa !5
  br label %31, !llvm.loop !11

50:                                               ; preds = %31
  br label %51

51:                                               ; preds = %50, %21
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = add nsw i32 %53, 2
  store i32 %54, ptr %3, align 4, !tbaa !5
  br label %18, !llvm.loop !12

55:                                               ; preds = %18
  br label %56

56:                                               ; preds = %81, %55
  %57 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %58 = icmp ne i32 %57, -1
  br i1 %58, label %59, label %82

59:                                               ; preds = %56
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %78, %59
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = icmp sle i32 %61, %62
  br i1 %63, label %64, label %81

64:                                               ; preds = %60
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100005 x i32], ptr @arr, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %68)
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = icmp eq i32 %70, %71
  br i1 %72, label %73, label %75

73:                                               ; preds = %64
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %77

75:                                               ; preds = %64
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %77

77:                                               ; preds = %75, %73
  br label %78

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

81:                                               ; preds = %60
  br label %56, !llvm.loop !14

82:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

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

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

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

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

@arr = external dso_local local_unnamed_addr global [100005 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 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
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  br label %2

2:                                                ; preds = %2, %0
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next.1, %2 ]
  %3 = getelementptr inbounds [100005 x i32], ptr @arr, i64 0, i64 %indvars.iv
  store i32 1, ptr %3, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %4 = getelementptr inbounds [100005 x i32], ptr @arr, i64 0, i64 %indvars.iv.next
  store i32 1, ptr %4, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 4
  %5 = icmp ult i64 %indvars.iv, 100002
  br i1 %5, label %2, label %.preheader27, !llvm.loop !9

.preheader25:                                     ; preds = %.loopexit26
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not36 = icmp eq i32 %6, -1
  br i1 %.not36, label %._crit_edge, label %.preheader

.preheader27:                                     ; preds = %2, %.loopexit26
  %indvars.iv38 = phi i64 [ %indvars.iv.next39, %.loopexit26 ], [ 3, %2 ]
  %.032 = phi i32 [ %.1, %.loopexit26 ], [ 1, %2 ]
  %7 = getelementptr inbounds [100005 x i32], ptr @arr, i64 0, i64 %indvars.iv38
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not23 = icmp eq i32 %8, 0
  br i1 %.not23, label %.lr.ph.preheader, label %.loopexit26

.lr.ph.preheader:                                 ; preds = %.preheader27
  %9 = add nsw i32 %.032, 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %13
  %indvars.iv40 = phi i64 [ %indvars.iv38, %.lr.ph.preheader ], [ %indvars.iv.next41, %13 ]
  %10 = getelementptr inbounds [100005 x i32], ptr @arr, i64 0, i64 %indvars.iv40
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %.not24 = icmp eq i32 %11, 0
  br i1 %.not24, label %12, label %13

12:                                               ; preds = %.lr.ph
  store i32 %9, ptr %10, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %.lr.ph, %12
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, %indvars.iv38
  %14 = icmp ult i64 %indvars.iv.next41, 100006
  br i1 %14, label %.lr.ph, label %.loopexit26, !llvm.loop !11

.loopexit26:                                      ; preds = %13, %.preheader27
  %.1 = phi i32 [ %.032, %.preheader27 ], [ %9, %13 ]
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 2
  %15 = icmp ult i64 %indvars.iv38, 100004
  br i1 %15, label %.preheader27, label %.preheader25, !llvm.loop !12

.loopexit:                                        ; preds = %.lr.ph35, %.preheader
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not = icmp eq i32 %16, -1
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !13

.preheader:                                       ; preds = %.preheader25, %.loopexit
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %.not2233 = icmp slt i32 %17, 2
  br i1 %.not2233, label %.loopexit, label %.lr.ph35

.lr.ph35:                                         ; preds = %.preheader, %.lr.ph35
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %.lr.ph35 ], [ 2, %.preheader ]
  %18 = getelementptr inbounds [100005 x i32], ptr @arr, i64 0, i64 %indvars.iv44
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %19)
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = zext i32 %21 to i64
  %23 = icmp eq i64 %indvars.iv44, %22
  %.str.2..str.3 = select i1 %23, ptr @.str.2, ptr @.str.3
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2..str.3)
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %.not22.not = icmp slt i64 %indvars.iv44, %26
  br i1 %.not22.not, label %.lr.ph35, label %.loopexit, !llvm.loop !14

._crit_edge:                                      ; preds = %.loopexit, %.preheader25
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 0
}

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

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

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass