; LLVM IR from kazunetakahashi/atcoder :: 201510_201609/0621_ARC047/B.ll (Z2okxx)

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

%"struct.std::pair" = type { i64, i64 }

@N = external dso_local global i32, align 4
@p = external dso_local global [100010 x %"struct.std::pair"], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z2okxx(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  %11 = load i64, ptr %4, align 8, !tbaa !5
  %12 = load i64, ptr %5, align 8, !tbaa !5
  %13 = add nsw i64 %11, %12
  %14 = srem i64 %13, 2
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %22, label %16

16:                                               ; preds = %2
  %17 = load i64, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = sub nsw i64 %17, %18
  %20 = srem i64 %19, 2
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %16, %2
  store i1 false, ptr %3, align 1
  br label %75

23:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = add nsw i64 %24, %25
  %27 = sdiv i64 %26, 2
  store i64 %27, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr %5, align 8, !tbaa !5
  %30 = sub nsw i64 %28, %29
  %31 = sdiv i64 %30, 2
  store i64 %31, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %32 = load i64, ptr @p, align 16, !tbaa !9
  %33 = load i64, ptr %6, align 8, !tbaa !5
  %34 = sub nsw i64 %32, %33
  %35 = call noundef i64 @_ZSt3absx(i64 noundef %34)
  %36 = load i64, ptr getelementptr inbounds (%"struct.std::pair", ptr @p, i32 0, i32 1), align 8, !tbaa !11
  %37 = load i64, ptr %7, align 8, !tbaa !5
  %38 = sub nsw i64 %36, %37
  %39 = call noundef i64 @_ZSt3absx(i64 noundef %38)
  %40 = add nsw i64 %35, %39
  store i64 %40, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !12
  br label %41

41:                                               ; preds = %68, %23
  %42 = load i32, ptr %9, align 4, !tbaa !12
  %43 = load i32, ptr @N, align 4, !tbaa !12
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  store i32 2, ptr %10, align 4
  br label %71

46:                                               ; preds = %41
  %47 = load i64, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %9, align 4, !tbaa !12
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @p, i64 0, i64 %49
  %51 = getelementptr inbounds %"struct.std::pair", ptr %50, i32 0, i32 0
  %52 = load i64, ptr %51, align 16, !tbaa !9
  %53 = load i64, ptr %6, align 8, !tbaa !5
  %54 = sub nsw i64 %52, %53
  %55 = call noundef i64 @_ZSt3absx(i64 noundef %54)
  %56 = load i32, ptr %9, align 4, !tbaa !12
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @p, i64 0, i64 %57
  %59 = getelementptr inbounds %"struct.std::pair", ptr %58, i32 0, i32 1
  %60 = load i64, ptr %59, align 8, !tbaa !11
  %61 = load i64, ptr %7, align 8, !tbaa !5
  %62 = sub nsw i64 %60, %61
  %63 = call noundef i64 @_ZSt3absx(i64 noundef %62)
  %64 = add nsw i64 %55, %63
  %65 = icmp ne i64 %47, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %46
  store i1 false, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %71

67:                                               ; preds = %46
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %9, align 4, !tbaa !12
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %9, align 4, !tbaa !12
  br label %41, !llvm.loop !14

71:                                               ; preds = %66, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %72 = load i32, ptr %10, align 4
  switch i32 %72, label %74 [
    i32 2, label %73
  ]

73:                                               ; preds = %71
  store i1 true, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %74

74:                                               ; preds = %73, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %75

75:                                               ; preds = %74, %22
  %76 = load i1, ptr %3, align 1
  ret i1 %76
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 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 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 = { 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 #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, !6, i64 0}
!10 = !{!"_ZTSSt4pairIxxE", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

%"struct.std::pair" = type { i64, i64 }

@N = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global [100010 x %"struct.std::pair"], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z2okxx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = add nsw i64 %1, %0
  %4 = and i64 %3, 1
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %5, label %.critedge

5:                                                ; preds = %2
  %6 = sub nsw i64 %1, %0
  %7 = and i64 %6, 1
  %.not20 = icmp eq i64 %7, 0
  br i1 %.not20, label %8, label %.critedge

8:                                                ; preds = %5
  %9 = ashr exact i64 %3, 1
  %10 = sub nsw i64 %0, %1
  %11 = sdiv i64 %10, 2
  %12 = load i64, ptr @p, align 16, !tbaa !5
  %13 = sub nsw i64 %12, %9
  %14 = tail call noundef i64 @_ZSt3absx(i64 noundef %13)
  %15 = load i64, ptr getelementptr inbounds (i8, ptr @p, i64 8), align 8, !tbaa !10
  %16 = sub nsw i64 %15, %11
  %17 = tail call noundef i64 @_ZSt3absx(i64 noundef %16)
  %18 = add nsw i64 %17, %14
  %19 = load i32, ptr @N, align 4, !tbaa !11
  %.not22.not23 = icmp sgt i32 %19, 1
  br i1 %.not22.not23, label %.lr.ph, label %.critedge

20:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i32, ptr @N, align 4, !tbaa !11
  %22 = sext i32 %21 to i64
  %.not22.not = icmp slt i64 %indvars.iv.next, %22
  br i1 %.not22.not, label %.lr.ph, label %.critedge, !llvm.loop !13

.lr.ph:                                           ; preds = %8, %20
  %indvars.iv = phi i64 [ %indvars.iv.next, %20 ], [ 1, %8 ]
  %23 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @p, i64 0, i64 %indvars.iv
  %24 = load i64, ptr %23, align 16, !tbaa !5
  %25 = sub nsw i64 %24, %9
  %26 = tail call noundef i64 @_ZSt3absx(i64 noundef %25)
  %27 = getelementptr inbounds i8, ptr %23, i64 8
  %28 = load i64, ptr %27, align 8, !tbaa !10
  %29 = sub nsw i64 %28, %11
  %30 = tail call noundef i64 @_ZSt3absx(i64 noundef %29)
  %31 = add nsw i64 %30, %26
  %.not21 = icmp eq i64 %18, %31
  br i1 %.not21, label %20, label %.critedge

.critedge:                                        ; preds = %.lr.ph, %20, %8, %2, %5
  %.2 = phi i1 [ false, %5 ], [ false, %2 ], [ true, %8 ], [ %.not21, %20 ], [ %.not21, %.lr.ph ]
  ret i1 %.2
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) local_unnamed_addr #1

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

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


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