; LLVM IR from eyangch/competitive-programming :: AtCoder/arc152/c.ll (Z5solvev)

; 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 [200000 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z5solvev() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  %5 = load i64, ptr getelementptr inbounds ([200000 x i64], ptr @A, i64 0, i64 1), align 8, !tbaa !5
  %6 = load i64, ptr @A, align 16, !tbaa !5
  %7 = sub nsw i64 %5, %6
  store i64 %7, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  store i64 2, ptr %2, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %24, %0
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = load i64, ptr @N, align 8, !tbaa !5
  %11 = icmp slt i64 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  br label %27

13:                                               ; preds = %8
  %14 = load i64, ptr %1, align 8, !tbaa !5
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds [200000 x i64], ptr @A, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = load i64, ptr %2, align 8, !tbaa !5
  %19 = sub nsw i64 %18, 1
  %20 = getelementptr inbounds [200000 x i64], ptr @A, i64 0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = sub nsw i64 %17, %21
  %23 = call noundef i64 @_ZSt3gcdIxxENSt11common_typeIJT_T0_EE4typeES1_S2_(i64 noundef %14, i64 noundef %22) #2
  store i64 %23, ptr %1, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %13
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %26 = add nsw i64 %25, 1
  store i64 %26, ptr %2, align 8, !tbaa !5
  br label %8, !llvm.loop !9

27:                                               ; preds = %12
  %28 = load i64, ptr %1, align 8, !tbaa !5
  %29 = mul nsw i64 %28, 2
  store i64 %29, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %30 = load i64, ptr @N, align 8, !tbaa !5
  %31 = sub nsw i64 %30, 1
  %32 = getelementptr inbounds [200000 x i64], ptr @A, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = load i64, ptr @A, align 16, !tbaa !5
  %35 = sub nsw i64 %33, %34
  store i64 %35, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %36 = load i64, ptr @A, align 16, !tbaa !5
  %37 = load i64, ptr %1, align 8, !tbaa !5
  %38 = srem i64 %36, %37
  store i64 %38, ptr %4, align 8, !tbaa !5
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = add nsw i64 %39, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret i64 %41
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3gcdIxxENSt11common_typeIJT_T0_EE4typeES1_S2_(i64 noundef, i64 noundef) #0

; 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@N = external dso_local local_unnamed_addr global i64, align 8
@A = external dso_local local_unnamed_addr global [200000 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z5solvev() local_unnamed_addr #0 {
  %1 = load i64, ptr getelementptr inbounds (i8, ptr @A, i64 8), align 8, !tbaa !5
  %2 = load i64, ptr @A, align 16, !tbaa !5
  %3 = sub nsw i64 %1, %2
  %4 = load i64, ptr @N, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, 2
  br i1 %5, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i64, ptr @A, align 16, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %6 = phi i64 [ %2, %0 ], [ %.pre, %._crit_edge.loopexit ]
  %.0.lcssa = phi i64 [ %3, %0 ], [ %20, %._crit_edge.loopexit ]
  %.lcssa = phi i64 [ %4, %0 ], [ %22, %._crit_edge.loopexit ]
  %7 = shl nsw i64 %.0.lcssa, 1
  %8 = add nsw i64 %.lcssa, -1
  %9 = getelementptr inbounds [200000 x i64], ptr @A, i64 0, i64 %8
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = sub i64 %10, %6
  %12 = srem i64 %6, %7
  %13 = add nsw i64 %11, %12
  ret i64 %13

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.012 = phi i64 [ %20, %.lr.ph ], [ %3, %0 ]
  %.0911 = phi i64 [ %21, %.lr.ph ], [ 2, %0 ]
  %14 = getelementptr inbounds [200000 x i64], ptr @A, i64 0, i64 %.0911
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = add nsw i64 %.0911, -1
  %17 = getelementptr inbounds [200000 x i64], ptr @A, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = sub nsw i64 %15, %18
  %20 = tail call noundef i64 @_ZSt3gcdIxxENSt11common_typeIJT_T0_EE4typeES1_S2_(i64 noundef %.012, i64 noundef %19) #1
  %21 = add nuw nsw i64 %.0911, 1
  %22 = load i64, ptr @N, align 8, !tbaa !5
  %23 = icmp slt i64 %21, %22
  br i1 %23, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3gcdIxxENSt11common_typeIJT_T0_EE4typeES1_S2_(i64 noundef, i64 noundef) local_unnamed_addr #0

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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