; LLVM IR from kazunetakahashi/atcoder :: 2019/0323_AGC032/E.ll (Z5solvei)

; 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 i32, align 4
@M = external dso_local global i64, align 8
@a = external dso_local global [200010 x i64], align 16
@ans = external dso_local global i64, align 8

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

11:                                               ; preds = %32, %1
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %35

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = mul nsw i32 2, %21
  %23 = sub nsw i32 %22, 1
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sub nsw i32 %23, %24
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = add nsw i64 %20, %28
  store i64 %29, ptr %6, align 8, !tbaa !9
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %31 = load i64, ptr %30, align 8, !tbaa !9
  store i64 %31, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %32

32:                                               ; preds = %16
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %5, align 4, !tbaa !5
  br label %11, !llvm.loop !11

35:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %74, %35
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = load i32, ptr @N, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sub nsw i32 %38, %39
  %41 = icmp slt i32 %37, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %36
  store i32 5, ptr %8, align 4
  br label %77

43:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = mul nsw i32 2, %44
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = add nsw i32 %45, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = load i32, ptr @N, align 4, !tbaa !5
  %52 = mul nsw i32 2, %51
  %53 = sub nsw i32 %52, 1
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = sub nsw i32 %53, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = add nsw i64 %50, %58
  store i64 %59, ptr %9, align 8, !tbaa !9
  %60 = load i64, ptr %9, align 8, !tbaa !9
  %61 = load i64, ptr @M, align 8, !tbaa !9
  %62 = icmp slt i64 %60, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %43
  store i1 false, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %71

64:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %65 = load i64, ptr %9, align 8, !tbaa !9
  %66 = load i64, ptr @M, align 8, !tbaa !9
  %67 = sub nsw i64 %65, %66
  store i64 %67, ptr %10, align 8, !tbaa !9
  %68 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %69 = load i64, ptr %68, align 8, !tbaa !9
  store i64 %69, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %70

70:                                               ; preds = %64
  store i32 0, ptr %8, align 4
  br label %71

71:                                               ; preds = %70, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %72 = load i32, ptr %8, align 4
  switch i32 %72, label %77 [
    i32 0, label %73
  ]

73:                                               ; preds = %71
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %7, align 4, !tbaa !5
  br label %36, !llvm.loop !13

77:                                               ; preds = %71, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %78 = load i32, ptr %8, align 4
  switch i32 %78, label %82 [
    i32 5, label %79
  ]

79:                                               ; preds = %77
  %80 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %81 = load i64, ptr %80, align 8, !tbaa !9
  store i64 %81, ptr @ans, align 8, !tbaa !9
  store i1 true, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %82

82:                                               ; preds = %79, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %83 = load i1, ptr %2, align 1
  ret i1 %83
}

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

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 = !{!"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"

@N = external dso_local local_unnamed_addr global i32, align 4
@M = external dso_local local_unnamed_addr global i64, align 8
@a = external dso_local local_unnamed_addr global [200010 x i64], align 16
@ans = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z5solvei(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  store i64 0, ptr %2, align 8, !tbaa !5
  %5 = icmp sgt i32 %0, 0
  br i1 %5, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %1
  %6 = shl nuw nsw i32 %0, 1
  %7 = zext nneg i32 %6 to i64
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %11

.preheader:                                       ; preds = %11, %1
  %8 = load i32, ptr @N, align 4, !tbaa !9
  %.not2429.not = icmp sgt i32 %8, %0
  br i1 %.not2429.not, label %.lr.ph32, label %.critedge25

.lr.ph32:                                         ; preds = %.preheader
  %9 = shl nsw i32 %0, 1
  %10 = sext i32 %9 to i64
  br label %21

11:                                               ; preds = %.lr.ph, %11
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %11 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %12 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %indvars.iv
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = xor i64 %indvars.iv, -1
  %15 = add nsw i64 %7, %14
  %16 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = add nsw i64 %17, %13
  store i64 %18, ptr %3, align 8, !tbaa !5
  %19 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %20 = load i64, ptr %19, align 8, !tbaa !5
  store i64 %20, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %11, !llvm.loop !11

21:                                               ; preds = %.lr.ph32, %35
  %indvars.iv36 = phi i64 [ 0, %.lr.ph32 ], [ %indvars.iv.next37, %35 ]
  %22 = phi i32 [ %8, %.lr.ph32 ], [ %39, %35 ]
  %23 = add nsw i64 %indvars.iv36, %10
  %24 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = shl nsw i32 %22, 1
  %27 = trunc i64 %indvars.iv36 to i32
  %28 = xor i32 %27, -1
  %29 = add i32 %26, %28
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200010 x i64], ptr @a, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = add nsw i64 %32, %25
  %34 = load i64, ptr @M, align 8, !tbaa !5
  %.not = icmp slt i64 %33, %34
  br i1 %.not, label %.critedge, label %35

35:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %36 = sub nsw i64 %33, %34
  store i64 %36, ptr %4, align 8, !tbaa !5
  %37 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %38 = load i64, ptr %37, align 8, !tbaa !5
  store i64 %38, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %39 = load i32, ptr @N, align 4, !tbaa !9
  %40 = sub nsw i32 %39, %0
  %41 = sext i32 %40 to i64
  %.not24.not = icmp slt i64 %indvars.iv.next37, %41
  br i1 %.not24.not, label %21, label %.critedge25, !llvm.loop !13

.critedge25:                                      ; preds = %35, %.preheader
  %42 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %43 = load i64, ptr %42, align 8, !tbaa !5
  store i64 %43, ptr @ans, align 8, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %21, %.critedge25
  %.not2427 = phi i1 [ true, %.critedge25 ], [ false, %21 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret i1 %.not2427
}

; Function Attrs: mustprogress 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 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

; 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 nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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