; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/VK Cup 2016 Round 1 /Problem B/B.ll (Z7computev)

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

@a = external dso_local global [200101 x i64], align 16
@b = external dso_local global [200101 x i64], align 16

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

3:                                                ; preds = %36, %0
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = icmp slt i32 %4, 200100
  br i1 %5, label %7, label %6

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

7:                                                ; preds = %3
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [200101 x i64], ptr @a, i64 0, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = srem i64 %11, 2
  %13 = icmp ne i64 %12, 0
  %14 = zext i1 %13 to i64
  %15 = select i1 %13, i32 1, i32 0
  %16 = sext i32 %15 to i64
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [200101 x i64], ptr @b, i64 0, i64 %18
  store i64 %16, ptr %19, align 8, !tbaa !9
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [200101 x i64], ptr @a, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [200101 x i64], ptr @b, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = sub nsw i64 %23, %27
  %29 = sdiv i64 %28, 2
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [200101 x i64], ptr @a, i64 0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %35 = add nsw i64 %34, %29
  store i64 %35, ptr %33, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %7
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %2, align 4, !tbaa !5
  br label %3, !llvm.loop !11

39:                                               ; preds = %6
  %40 = load i64, ptr getelementptr inbounds ([200101 x i64], ptr @a, i64 0, i64 200100), align 16, !tbaa !9
  store i64 %40, ptr getelementptr inbounds ([200101 x i64], ptr @b, i64 0, i64 200100), align 16, !tbaa !9
  %41 = load i64, ptr getelementptr inbounds ([200101 x i64], ptr @b, i64 0, i64 200100), align 16, !tbaa !9
  %42 = icmp slt i64 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %39
  store i1 false, ptr %1, align 1
  br label %45

44:                                               ; preds = %39
  store i1 true, ptr %1, align 1
  br label %45

45:                                               ; preds = %44, %43
  %46 = load i1, ptr %1, align 1
  ret i1 %46
}

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

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

@a = external dso_local local_unnamed_addr global [200101 x i64], align 16
@b = external dso_local local_unnamed_addr global [200101 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z7computev() local_unnamed_addr #0 {
  %.pre = load i64, ptr @a, align 16, !tbaa !5
  br label %4

1:                                                ; preds = %4
  %2 = load i64, ptr getelementptr inbounds (i8, ptr @a, i64 1600800), align 16, !tbaa !5
  store i64 %2, ptr getelementptr inbounds (i8, ptr @b, i64 1600800), align 16, !tbaa !5
  %3 = icmp sgt i64 %2, -1
  ret i1 %3

4:                                                ; preds = %4, %0
  %5 = phi i64 [ %.pre, %0 ], [ %17, %4 ]
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next.1, %4 ]
  %6 = and i64 %5, 1
  %7 = getelementptr inbounds [200101 x i64], ptr @b, i64 0, i64 %indvars.iv
  store i64 %6, ptr %7, align 16, !tbaa !5
  %8 = ashr i64 %5, 1
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %9 = getelementptr inbounds [200101 x i64], ptr @a, i64 0, i64 %indvars.iv.next
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = add nsw i64 %10, %8
  store i64 %11, ptr %9, align 8, !tbaa !5
  %12 = and i64 %11, 1
  %13 = getelementptr inbounds [200101 x i64], ptr @b, i64 0, i64 %indvars.iv.next
  store i64 %12, ptr %13, align 8, !tbaa !5
  %14 = ashr i64 %11, 1
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %15 = getelementptr inbounds [200101 x i64], ptr @a, i64 0, i64 %indvars.iv.next.1
  %16 = load i64, ptr %15, align 16, !tbaa !5
  %17 = add nsw i64 %16, %14
  store i64 %17, ptr %15, align 16, !tbaa !5
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 200100
  br i1 %exitcond.not.1, label %1, label %4, !llvm.loop !9
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass