; LLVM IR from tangjz/acm-icpc :: hdu/5539.ll (Z6color2v)

; 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
@col = external dso_local global [1002001 x i32], align 16

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3idxii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z3pfsi(i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z6color2v() #2 {
  %1 = alloca i1, align 1
  %2 = alloca i8, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #3
  store i8 1, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %50, %0
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = load i32, ptr @n, align 4, !tbaa !9
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %15

12:                                               ; preds = %8
  %13 = load i8, ptr %2, align 1, !tbaa !5, !range !11, !noundef !12
  %14 = trunc i8 %13 to i1
  br label %15

15:                                               ; preds = %12, %8
  %16 = phi i1 [ false, %8 ], [ %14, %12 ]
  br i1 %16, label %18, label %17

17:                                               ; preds = %15
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %53

18:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %5, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %46, %18
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = load i32, ptr @n, align 4, !tbaa !9
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %21
  %26 = load i8, ptr %2, align 1, !tbaa !5, !range !11, !noundef !12
  %27 = trunc i8 %26 to i1
  br label %28

28:                                               ; preds = %25, %21
  %29 = phi i1 [ false, %21 ], [ %27, %25 ]
  br i1 %29, label %31, label %30

30:                                               ; preds = %28
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %49

31:                                               ; preds = %28
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = call noundef i32 @_Z3idxii(i32 noundef %32, i32 noundef %33)
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [1002001 x i32], ptr @col, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %45, label %39

39:                                               ; preds = %31
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = call noundef i32 @_Z3idxii(i32 noundef %40, i32 noundef %41)
  %43 = call noundef zeroext i1 @_Z3pfsi(i32 noundef %42)
  br i1 %43, label %45, label %44

44:                                               ; preds = %39
  store i8 0, ptr %2, align 1, !tbaa !5
  br label %45

45:                                               ; preds = %44, %39, %31
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %5, align 4, !tbaa !9
  br label %21, !llvm.loop !13

49:                                               ; preds = %30
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %3, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %3, align 4, !tbaa !9
  br label %8, !llvm.loop !15

53:                                               ; preds = %17
  %54 = load i8, ptr %2, align 1, !tbaa !5, !range !11, !noundef !12
  %55 = trunc i8 %54 to i1
  br i1 %55, label %56, label %57

56:                                               ; preds = %53
  store i1 true, ptr %1, align 1
  store i32 1, ptr %4, align 4
  br label %94

57:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %90, %57
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = load i32, ptr @n, align 4, !tbaa !9
  %61 = icmp slt i32 %59, %60
  br i1 %61, label %63, label %62

62:                                               ; preds = %58
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %93

63:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %7, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %86, %63
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = load i32, ptr @n, align 4, !tbaa !9
  %69 = icmp slt i32 %67, %68
  br i1 %69, label %71, label %70

70:                                               ; preds = %66
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %89

71:                                               ; preds = %66
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = load i32, ptr %7, align 4, !tbaa !9
  %74 = call noundef i32 @_Z3idxii(i32 noundef %72, i32 noundef %73)
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [1002001 x i32], ptr @col, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !9
  %78 = icmp ne i32 %77, -1
  br i1 %78, label %79, label %85

79:                                               ; preds = %71
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = call noundef i32 @_Z3idxii(i32 noundef %80, i32 noundef %81)
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [1002001 x i32], ptr @col, i64 0, i64 %83
  store i32 0, ptr %84, align 4, !tbaa !9
  br label %85

85:                                               ; preds = %79, %71
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %7, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %7, align 4, !tbaa !9
  br label %66, !llvm.loop !16

89:                                               ; preds = %70
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %6, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %6, align 4, !tbaa !9
  br label %58, !llvm.loop !17

93:                                               ; preds = %62
  store i1 false, ptr %1, align 1
  store i32 1, ptr %4, align 4
  br label %94

94:                                               ; preds = %93, %56
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #3
  %95 = load i1, ptr %1, align 1
  ret i1 %95
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 #2 = { mustprogress 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 #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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


; 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 local_unnamed_addr global i32, align 4
@col = external dso_local local_unnamed_addr global [1002001 x i32], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3idxii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z3pfsi(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z6color2v() local_unnamed_addr #1 {
  %1 = load i32, ptr @n, align 4
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph33, label %.loopexit27

.loopexit28:                                      ; preds = %19, %.lr.ph33
  %.pre-phi = phi i1 [ %10, %.lr.ph33 ], [ %23, %19 ]
  %3 = phi i32 [ %7, %.lr.ph33 ], [ %21, %19 ]
  %.1.lcssa = phi i8 [ %.02431, %.lr.ph33 ], [ %.2, %19 ]
  %4 = icmp slt i32 %8, %3
  %5 = select i1 %4, i1 %.pre-phi, i1 false
  br i1 %5, label %.lr.ph33, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.loopexit28
  %6 = icmp slt i32 %3, 1
  %or.cond.not = or i1 %.pre-phi, %6
  br i1 %or.cond.not, label %.loopexit27, label %.lr.ph39

.lr.ph33:                                         ; preds = %0, %.loopexit28
  %7 = phi i32 [ %3, %.loopexit28 ], [ %1, %0 ]
  %.02332 = phi i32 [ %8, %.loopexit28 ], [ 0, %0 ]
  %.02431 = phi i8 [ %.1.lcssa, %.loopexit28 ], [ 1, %0 ]
  %8 = add nuw nsw i32 %.02332, 1
  %9 = icmp slt i32 %8, %7
  %10 = trunc nuw i8 %.02431 to i1
  %11 = select i1 %9, i1 %10, i1 false
  br i1 %11, label %.lr.ph, label %.loopexit28

.lr.ph:                                           ; preds = %.lr.ph33, %19
  %.02230 = phi i32 [ %20, %19 ], [ %8, %.lr.ph33 ]
  %.129 = phi i8 [ %.2, %19 ], [ %.02431, %.lr.ph33 ]
  %12 = tail call noundef i32 @_Z3idxii(i32 noundef %.02332, i32 noundef %.02230)
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [1002001 x i32], ptr @col, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !7
  %.not26 = icmp eq i32 %15, 0
  br i1 %.not26, label %16, label %19

16:                                               ; preds = %.lr.ph
  %17 = tail call noundef i32 @_Z3idxii(i32 noundef %.02332, i32 noundef %.02230)
  %18 = tail call noundef zeroext i1 @_Z3pfsi(i32 noundef %17)
  %spec.select = select i1 %18, i8 %.129, i8 0
  br label %19

19:                                               ; preds = %16, %.lr.ph
  %.2 = phi i8 [ %.129, %.lr.ph ], [ %spec.select, %16 ]
  %20 = add nuw nsw i32 %.02230, 1
  %21 = load i32, ptr @n, align 4
  %22 = icmp slt i32 %20, %21
  %23 = trunc nuw i8 %.2 to i1
  %24 = select i1 %22, i1 %23, i1 false
  br i1 %24, label %.lr.ph, label %.loopexit28, !llvm.loop !11

.loopexit:                                        ; preds = %38, %.lr.ph39
  %25 = phi i32 [ %27, %.lr.ph39 ], [ %40, %38 ]
  %26 = icmp slt i32 %28, %25
  br i1 %26, label %.lr.ph39, label %.loopexit27, !llvm.loop !12

.lr.ph39:                                         ; preds = %._crit_edge, %.loopexit
  %27 = phi i32 [ %25, %.loopexit ], [ %3, %._crit_edge ]
  %.02138 = phi i32 [ %28, %.loopexit ], [ 0, %._crit_edge ]
  %28 = add nuw nsw i32 %.02138, 1
  %29 = icmp slt i32 %28, %27
  br i1 %29, label %.lr.ph37, label %.loopexit

.lr.ph37:                                         ; preds = %.lr.ph39, %38
  %.035 = phi i32 [ %39, %38 ], [ %28, %.lr.ph39 ]
  %30 = tail call noundef i32 @_Z3idxii(i32 noundef %.02138, i32 noundef %.035)
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1002001 x i32], ptr @col, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !7
  %.not = icmp eq i32 %33, -1
  br i1 %.not, label %38, label %34

34:                                               ; preds = %.lr.ph37
  %35 = tail call noundef i32 @_Z3idxii(i32 noundef %.02138, i32 noundef %.035)
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1002001 x i32], ptr @col, i64 0, i64 %36
  store i32 0, ptr %37, align 4, !tbaa !7
  br label %38

38:                                               ; preds = %.lr.ph37, %34
  %39 = add nuw nsw i32 %.035, 1
  %40 = load i32, ptr @n, align 4, !tbaa !7
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %.lr.ph37, label %.loopexit, !llvm.loop !13

.loopexit27:                                      ; preds = %.loopexit, %0, %._crit_edge
  %.lcssa45 = phi i1 [ %.pre-phi, %._crit_edge ], [ true, %0 ], [ %.pre-phi, %.loopexit ]
  ret i1 %.lcssa45
}

attributes #0 = { inlinehint mustprogress 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 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}
!12 = distinct !{!12, !6}
!13 = distinct !{!13, !6}


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