; LLVM IR from kazunetakahashi/atcoder :: 2019/0615_diverta2019-2/B.ll (Z5solvexx)

; 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
@x = external dso_local global [100 x i64], align 16
@y = external dso_local global [100 x i64], align 16
@visited = external dso_local global [100 x i8], 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: mustprogress uwtable
define dso_local noundef i64 @_Z5solvexx(i64 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  %11 = load i32, ptr @N, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr @visited, i64 %12
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  store i8 0, ptr %5, align 1, !tbaa !11
  call void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef @visited, ptr noundef %13, ptr noundef nonnull align 1 dereferenceable(1) %5)
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %64, %2
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = load i32, ptr @N, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %67

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %59, %19
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = load i32, ptr @N, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 5, ptr %7, align 4
  br label %62

25:                                               ; preds = %20
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp eq i32 %26, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  br label %59

30:                                               ; preds = %25
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100 x i64], ptr @x, i64 0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100 x i64], ptr @x, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = sub nsw i64 %34, %38
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = icmp eq i64 %39, %40
  br i1 %41, label %42, label %58

42:                                               ; preds = %30
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100 x i64], ptr @y, i64 0, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100 x i64], ptr @y, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = sub nsw i64 %46, %50
  %52 = load i64, ptr %4, align 8, !tbaa !5
  %53 = icmp eq i64 %51, %52
  br i1 %53, label %54, label %58

54:                                               ; preds = %42
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100 x i8], ptr @visited, i64 0, i64 %56
  store i8 1, ptr %57, align 1, !tbaa !11
  store i32 5, ptr %7, align 4
  br label %62

58:                                               ; preds = %42, %30
  br label %59

59:                                               ; preds = %58, %29
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %8, align 4, !tbaa !9
  br label %20, !llvm.loop !13

62:                                               ; preds = %54, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %6, align 4, !tbaa !9
  br label %14, !llvm.loop !15

67:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %68

68:                                               ; preds = %83, %67
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = load i32, ptr @N, align 4, !tbaa !9
  %71 = icmp slt i32 %69, %70
  br i1 %71, label %73, label %72

72:                                               ; preds = %68
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %86

73:                                               ; preds = %68
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [100 x i8], ptr @visited, i64 0, i64 %75
  %77 = load i8, ptr %76, align 1, !tbaa !11, !range !16, !noundef !17
  %78 = trunc i8 %77 to i1
  br i1 %78, label %82, label %79

79:                                               ; preds = %73
  %80 = load i64, ptr %9, align 8, !tbaa !5
  %81 = add nsw i64 %80, 1
  store i64 %81, ptr %9, align 8, !tbaa !5
  br label %82

82:                                               ; preds = %79, %73
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %10, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %10, align 4, !tbaa !9
  br label %68, !llvm.loop !18

86:                                               ; preds = %72
  %87 = load i64, ptr %9, align 8, !tbaa !5
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i64 %87
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 1 dereferenceable(1)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { inlinehint 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !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
@x = external dso_local local_unnamed_addr global [100 x i64], align 16
@y = external dso_local local_unnamed_addr global [100 x i64], align 16
@visited = external dso_local global [100 x i8], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solvexx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = alloca i8, align 1
  %4 = load i32, ptr @N, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds i8, ptr @visited, i64 %5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #4
  store i8 0, ptr %3, align 1, !tbaa !9
  call void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef nonnull @visited, ptr noundef nonnull %6, ptr noundef nonnull align 1 dereferenceable(1) %3)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #4
  %7 = load i32, ptr @N, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.preheader21.us.preheader, label %._crit_edge

.preheader21.us.preheader:                        ; preds = %2
  %wide.trip.count33 = zext nneg i32 %7 to i64
  br label %.preheader21.us

.preheader21.us:                                  ; preds = %.preheader21.us.preheader, %..loopexit_crit_edge.us
  %indvars.iv30 = phi i64 [ 0, %.preheader21.us.preheader ], [ %indvars.iv.next31, %..loopexit_crit_edge.us ]
  %9 = getelementptr inbounds [100 x i64], ptr @x, i64 0, i64 %indvars.iv30
  %10 = getelementptr inbounds [100 x i64], ptr @y, i64 0, i64 %indvars.iv30
  br label %11

11:                                               ; preds = %.preheader21.us, %27
  %indvars.iv = phi i64 [ 0, %.preheader21.us ], [ %indvars.iv.next, %27 ]
  %12 = icmp eq i64 %indvars.iv30, %indvars.iv
  br i1 %12, label %27, label %13

13:                                               ; preds = %11
  %14 = load i64, ptr %9, align 8, !tbaa !11
  %15 = getelementptr inbounds [100 x i64], ptr @x, i64 0, i64 %indvars.iv
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = sub nsw i64 %14, %16
  %18 = icmp eq i64 %17, %0
  br i1 %18, label %19, label %27

19:                                               ; preds = %13
  %20 = load i64, ptr %10, align 8, !tbaa !11
  %21 = getelementptr inbounds [100 x i64], ptr @y, i64 0, i64 %indvars.iv
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = sub nsw i64 %20, %22
  %24 = icmp eq i64 %23, %1
  br i1 %24, label %25, label %27

25:                                               ; preds = %19
  %26 = getelementptr inbounds [100 x i8], ptr @visited, i64 0, i64 %indvars.iv
  store i8 1, ptr %26, align 1, !tbaa !9
  br label %..loopexit_crit_edge.us

..loopexit_crit_edge.us:                          ; preds = %27, %25
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count33
  br i1 %exitcond34.not, label %.preheader, label %.preheader21.us, !llvm.loop !13

27:                                               ; preds = %19, %13, %11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count33
  br i1 %exitcond.not, label %..loopexit_crit_edge.us, label %11, !llvm.loop !15

.preheader:                                       ; preds = %..loopexit_crit_edge.us
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count38 = zext nneg i32 %7 to i64
  %min.iters.check = icmp ult i32 %7, 4
  br i1 %min.iters.check, label %.lr.ph.preheader44, label %vector.ph

.lr.ph.preheader44:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv35.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %.01826.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %37, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count33, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %34, %vector.body ]
  %vec.phi42 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %35, %vector.body ]
  %28 = getelementptr inbounds [100 x i8], ptr @visited, i64 0, i64 %index
  %29 = getelementptr inbounds i8, ptr %28, i64 2
  %wide.load = load <2 x i8>, ptr %28, align 4, !tbaa !9
  %wide.load43 = load <2 x i8>, ptr %29, align 2, !tbaa !9
  %30 = xor <2 x i8> %wide.load, <i8 1, i8 1>
  %31 = xor <2 x i8> %wide.load43, <i8 1, i8 1>
  %32 = zext <2 x i8> %30 to <2 x i64>
  %33 = zext <2 x i8> %31 to <2 x i64>
  %34 = add <2 x i64> %vec.phi, %32
  %35 = add <2 x i64> %vec.phi42, %33
  %index.next = add nuw i64 %index, 4
  %36 = icmp eq i64 %index.next, %n.vec
  br i1 %36, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %35, %34
  %37 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count33
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader44

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %2, %.preheader
  %.018.lcssa = phi i64 [ 0, %.preheader ], [ 0, %2 ], [ %37, %middle.block ], [ %spec.select, %.lr.ph ]
  ret i64 %.018.lcssa

.lr.ph:                                           ; preds = %.lr.ph.preheader44, %.lr.ph
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %.lr.ph ], [ %indvars.iv35.ph, %.lr.ph.preheader44 ]
  %.01826 = phi i64 [ %spec.select, %.lr.ph ], [ %.01826.ph, %.lr.ph.preheader44 ]
  %38 = getelementptr inbounds [100 x i8], ptr @visited, i64 0, i64 %indvars.iv35
  %39 = load i8, ptr %38, align 1, !tbaa !9, !range !19, !noundef !20
  %40 = xor i8 %39, 1
  %not. = zext nneg i8 %40 to i64
  %spec.select = add nuw nsw i64 %.01826, %not.
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count38
  br i1 %exitcond39.not, label %._crit_edge, label %.lr.ph, !llvm.loop !21
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { inlinehint 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14, !17, !18}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = distinct !{!21, !14, !18, !17}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass