; LLVM IR from kazunetakahashi/atcoder :: 2018/1027_tenka1-2018/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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@N = external dso_local global i32, align 4
@A = external dso_local global %"class.std::vector", align 8
@start = external dso_local global i64, align 8
@B = external dso_local global [100010 x i64], align 16
@ans = external dso_local global i64, align 8

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

4:                                                ; preds = %37, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = load i32, ptr @N, align 4, !tbaa !5
  %7 = sub nsw i32 %6, 1
  %8 = icmp slt i32 %5, %7
  br i1 %8, label %10, label %9

9:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %40

10:                                               ; preds = %4
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = srem i32 %11, 2
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %23

14:                                               ; preds = %10
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sdiv i32 %15, 2
  %17 = sext i32 %16 to i64
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @A, i64 noundef %17) #4
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = load i32, ptr %1, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100010 x i64], ptr @B, i64 0, i64 %21
  store i64 %19, ptr %22, align 8, !tbaa !9
  br label %36

23:                                               ; preds = %10
  %24 = load i32, ptr @N, align 4, !tbaa !5
  %25 = sub nsw i32 %24, 1
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = sdiv i32 %26, 2
  %28 = sub nsw i32 %25, %27
  %29 = sub nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @A, i64 noundef %30) #4
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100010 x i64], ptr @B, i64 0, i64 %34
  store i64 %32, ptr %35, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %23, %14
  br label %37

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

40:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %41 = load i64, ptr @start, align 8, !tbaa !9
  %42 = load i64, ptr @B, align 16, !tbaa !9
  %43 = sub nsw i64 %41, %42
  %44 = call noundef i64 @_ZSt3absx(i64 noundef %43)
  store i64 %44, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %65, %40
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = load i32, ptr @N, align 4, !tbaa !5
  %48 = sub nsw i32 %47, 2
  %49 = icmp slt i32 %46, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %68

51:                                               ; preds = %45
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100010 x i64], ptr @B, i64 0, i64 %53
  %55 = load i64, ptr %54, align 8, !tbaa !9
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [100010 x i64], ptr @B, i64 0, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !9
  %61 = sub nsw i64 %55, %60
  %62 = call noundef i64 @_ZSt3absx(i64 noundef %61)
  %63 = load i64, ptr %2, align 8, !tbaa !9
  %64 = add nsw i64 %63, %62
  store i64 %64, ptr %2, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %51
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %3, align 4, !tbaa !5
  br label %45, !llvm.loop !13

68:                                               ; preds = %50
  %69 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %70 = load i64, ptr %69, align 8, !tbaa !9
  store i64 %70, ptr @ans, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  ret void
}

; 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 nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

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 = { 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 = { 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 #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 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@N = external dso_local local_unnamed_addr global i32, align 4
@A = external dso_local global %"class.std::vector", align 8
@start = external dso_local local_unnamed_addr global i64, align 8
@B = external dso_local local_unnamed_addr global [100010 x i64], align 16
@ans = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = load i32, ptr @N, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 1
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %4 = add nsw i32 %2, -1
  br label %.lr.ph

._crit_edge:                                      ; preds = %23, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  %5 = load i64, ptr @start, align 8, !tbaa !9
  %6 = load i64, ptr @B, align 16, !tbaa !9
  %7 = sub nsw i64 %5, %6
  %8 = tail call noundef i64 @_ZSt3absx(i64 noundef %7)
  %9 = load i32, ptr @N, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 2
  br i1 %10, label %.lr.ph17, label %._crit_edge18

.lr.ph:                                           ; preds = %.lr.ph.preheader, %23
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %23 ]
  %11 = phi i32 [ %4, %.lr.ph.preheader ], [ %27, %23 ]
  %12 = trunc nuw nsw i64 %indvars.iv to i32
  %13 = and i32 %12, 1
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %18

15:                                               ; preds = %.lr.ph
  %16 = lshr i64 %indvars.iv, 1
  %17 = and i64 %16, 2147483647
  br label %23

18:                                               ; preds = %.lr.ph
  %19 = lshr i32 %12, 1
  %20 = xor i32 %19, -1
  %21 = add i32 %11, %20
  %22 = sext i32 %21 to i64
  br label %23

23:                                               ; preds = %15, %18
  %.sink23 = phi i64 [ %17, %15 ], [ %22, %18 ]
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @A, i64 noundef %.sink23) #3
  %.sink = load i64, ptr %24, align 8, !tbaa !9
  %25 = getelementptr inbounds [100010 x i64], ptr @B, i64 0, i64 %indvars.iv
  store i64 %.sink, ptr %25, align 8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr @N, align 4, !tbaa !5
  %27 = add nsw i32 %26, -1
  %28 = sext i32 %27 to i64
  %29 = icmp slt i64 %indvars.iv.next, %28
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge18:                                    ; preds = %.lr.ph17, %._crit_edge
  %storemerge.lcssa = phi i64 [ %8, %._crit_edge ], [ %38, %.lr.ph17 ]
  store i64 %storemerge.lcssa, ptr %1, align 8, !tbaa !9
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %31 = load i64, ptr %30, align 8, !tbaa !9
  store i64 %31, ptr @ans, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret void

.lr.ph17:                                         ; preds = %._crit_edge, %.lr.ph17
  %indvars.iv20 = phi i64 [ %indvars.iv.next21, %.lr.ph17 ], [ 0, %._crit_edge ]
  %storemerge14 = phi i64 [ %38, %.lr.ph17 ], [ %8, %._crit_edge ]
  %32 = getelementptr inbounds [100010 x i64], ptr @B, i64 0, i64 %indvars.iv20
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %34 = getelementptr inbounds [100010 x i64], ptr @B, i64 0, i64 %indvars.iv.next21
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = sub nsw i64 %33, %35
  %37 = tail call noundef i64 @_ZSt3absx(i64 noundef %36)
  %38 = add nsw i64 %storemerge14, %37
  %39 = load i32, ptr @N, align 4, !tbaa !5
  %40 = add nsw i32 %39, -2
  %41 = sext i32 %40 to i64
  %42 = icmp slt i64 %indvars.iv.next21, %41
  br i1 %42, label %.lr.ph17, label %._crit_edge18, !llvm.loop !13
}

; Function Attrs: mustprogress 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 nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

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 = { mustprogress 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 = !{!"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"}
!13 = distinct !{!13, !12}


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