; LLVM IR from eyangch/competitive-programming :: Codeforces/1530/c.ll (Z5worksx)

; 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 i64, align 8
@a = external dso_local global [100000 x i64], align 16
@b = external dso_local global [100000 x i64], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5worksx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %7 = load i64, ptr @N, align 8, !tbaa !5
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = add nsw i64 %7, %8
  store i64 %9, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = sdiv i64 %10, 4
  store i64 %11, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = mul nsw i64 100, %12
  %14 = load i64, ptr @N, align 8, !tbaa !5
  %15 = getelementptr inbounds i64, ptr @a, i64 %14
  %16 = call noundef i32 @_ZSt10accumulateIPxiET0_T_S2_S1_(ptr noundef @a, ptr noundef %15, i32 noundef 0)
  %17 = sext i32 %16 to i64
  %18 = add nsw i64 %13, %17
  store i64 %18, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %19 = load i64, ptr @N, align 8, !tbaa !5
  %20 = getelementptr inbounds i64, ptr @b, i64 %19
  %21 = call noundef i32 @_ZSt10accumulateIPxiET0_T_S2_S1_(ptr noundef @b, ptr noundef %20, i32 noundef 0)
  %22 = sext i32 %21 to i64
  store i64 %22, ptr %6, align 8, !tbaa !5
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = load i64, ptr @N, align 8, !tbaa !5
  %25 = icmp sge i64 %23, %24
  br i1 %25, label %26, label %31

26:                                               ; preds = %1
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = sub nsw i64 %27, %28
  %30 = mul nsw i64 100, %29
  store i64 %30, ptr %5, align 8, !tbaa !5
  br label %38

31:                                               ; preds = %1
  %32 = load i64, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds i64, ptr @a, i64 %32
  %34 = call noundef i32 @_ZSt10accumulateIPxiET0_T_S2_S1_(ptr noundef @a, ptr noundef %33, i32 noundef 0)
  %35 = sext i32 %34 to i64
  %36 = load i64, ptr %5, align 8, !tbaa !5
  %37 = sub nsw i64 %36, %35
  store i64 %37, ptr %5, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %31, %26
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = load i64, ptr %2, align 8, !tbaa !5
  %41 = icmp sge i64 %39, %40
  br i1 %41, label %42, label %52

42:                                               ; preds = %38
  %43 = load i64, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds i64, ptr @b, i64 %43
  %45 = load i64, ptr %2, align 8, !tbaa !5
  %46 = sub i64 0, %45
  %47 = getelementptr inbounds i64, ptr %44, i64 %46
  %48 = call noundef i32 @_ZSt10accumulateIPxiET0_T_S2_S1_(ptr noundef @b, ptr noundef %47, i32 noundef 0)
  %49 = sext i32 %48 to i64
  %50 = load i64, ptr %6, align 8, !tbaa !5
  %51 = sub nsw i64 %50, %49
  store i64 %51, ptr %6, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %42, %38
  %53 = load i64, ptr %5, align 8, !tbaa !5
  %54 = load i64, ptr %6, align 8, !tbaa !5
  %55 = icmp sge i64 %53, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i1 %55
}

; 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 i32 @_ZSt10accumulateIPxiET0_T_S2_S1_(ptr noundef, ptr noundef, i32 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"}


; 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 i64, align 8
@a = external dso_local global [100000 x i64], align 16
@b = external dso_local global [100000 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z5worksx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = load i64, ptr @N, align 8, !tbaa !5
  %3 = add nsw i64 %2, %0
  %4 = sdiv i64 %3, 4
  %5 = getelementptr inbounds i64, ptr @a, i64 %2
  %6 = tail call noundef i32 @_ZSt10accumulateIPxiET0_T_S2_S1_(ptr noundef nonnull @a, ptr noundef nonnull %5, i32 noundef 0)
  %7 = load i64, ptr @N, align 8, !tbaa !5
  %8 = getelementptr inbounds i64, ptr @b, i64 %7
  %9 = tail call noundef i32 @_ZSt10accumulateIPxiET0_T_S2_S1_(ptr noundef nonnull @b, ptr noundef nonnull %8, i32 noundef 0)
  %10 = sext i32 %9 to i64
  %11 = load i64, ptr @N, align 8, !tbaa !5
  %.not = icmp slt i64 %4, %11
  br i1 %.not, label %15, label %12

12:                                               ; preds = %1
  %13 = sub nsw i64 %3, %4
  %14 = mul nsw i64 %13, 100
  br label %23

15:                                               ; preds = %1
  %16 = mul nsw i64 %0, 100
  %17 = sext i32 %6 to i64
  %18 = add nsw i64 %16, %17
  %19 = getelementptr inbounds i64, ptr @a, i64 %4
  %20 = tail call noundef i32 @_ZSt10accumulateIPxiET0_T_S2_S1_(ptr noundef nonnull @a, ptr noundef nonnull %19, i32 noundef 0)
  %21 = sext i32 %20 to i64
  %22 = sub i64 %18, %21
  br label %23

23:                                               ; preds = %15, %12
  %.015 = phi i64 [ %14, %12 ], [ %22, %15 ]
  %.not18 = icmp slt i64 %4, %0
  br i1 %.not18, label %31, label %24

24:                                               ; preds = %23
  %25 = getelementptr inbounds i64, ptr @b, i64 %4
  %26 = sub i64 0, %0
  %27 = getelementptr inbounds i64, ptr %25, i64 %26
  %28 = tail call noundef i32 @_ZSt10accumulateIPxiET0_T_S2_S1_(ptr noundef nonnull @b, ptr noundef nonnull %27, i32 noundef 0)
  %29 = sext i32 %28 to i64
  %30 = sub nsw i64 %10, %29
  br label %31

31:                                               ; preds = %24, %23
  %.0 = phi i64 [ %30, %24 ], [ %10, %23 ]
  %32 = icmp sge i64 %.015, %.0
  ret i1 %32
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt10accumulateIPxiET0_T_S2_S1_(ptr noundef, ptr noundef, i32 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, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass