; LLVM IR from kazunetakahashi/atcoder :: 2018/0224_AGC021/D2.ll (Z4calciii)

; 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::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z1SB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@DP = external dso_local global [310 x [310 x [310 x i32]]], align 16
@DP2 = external dso_local global [310 x [26 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4calciii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %13 = load i32, ptr %6, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = sub nsw i32 %13, %14
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = mul nsw i32 2, %16
  %18 = add nsw i32 %17, 1
  %19 = icmp sle i32 %15, %18
  br i1 %19, label %20, label %24

20:                                               ; preds = %3
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sub nsw i32 %21, %22
  store i32 %23, ptr %4, align 4
  br label %121

24:                                               ; preds = %3
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [310 x [310 x [310 x i32]]], ptr @DP, i64 0, i64 %26
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [310 x [310 x i32]], ptr %27, i64 0, i64 %29
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [310 x i32], ptr %30, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = icmp ne i32 %34, -1
  br i1 %35, label %36, label %47

36:                                               ; preds = %24
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [310 x [310 x [310 x i32]]], ptr @DP, i64 0, i64 %38
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [310 x [310 x i32]], ptr %39, i64 0, i64 %41
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [310 x i32], ptr %42, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  store i32 %46, ptr %4, align 4
  br label %121

47:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = sub nsw i32 %50, 1
  %52 = icmp sle i32 %49, %51
  br i1 %52, label %53, label %68

53:                                               ; preds = %47
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = sub nsw i32 %54, 1
  %56 = icmp sge i32 %55, 0
  br i1 %56, label %57, label %68

57:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = sub nsw i32 %60, 1
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = sub nsw i32 %62, 1
  %64 = call noundef i32 @_Z4calciii(i32 noundef %59, i32 noundef %61, i32 noundef %63)
  %65 = add nsw i32 %64, 2
  store i32 %65, ptr %9, align 4, !tbaa !5
  %66 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %67 = load i32, ptr %66, align 4, !tbaa !5
  store i32 %67, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %68

68:                                               ; preds = %57, %53, %47
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = sub nsw i32 %70, 1
  %72 = icmp sle i32 %69, %71
  br i1 %72, label %73, label %81

73:                                               ; preds = %68
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = sub nsw i32 %75, 1
  %77 = load i32, ptr %7, align 4, !tbaa !5
  %78 = call noundef i32 @_Z4calciii(i32 noundef %74, i32 noundef %76, i32 noundef %77)
  store i32 %78, ptr %10, align 4, !tbaa !5
  %79 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %80 = load i32, ptr %79, align 4, !tbaa !5
  store i32 %80, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %81

81:                                               ; preds = %73, %68
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %82 = load i32, ptr %5, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [310 x [26 x i32]], ptr @DP2, i64 0, i64 %83
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = sub nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  %88 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1SB5cxx11, i64 noundef %87)
  %89 = load i8, ptr %88, align 1, !tbaa !9
  %90 = sext i8 %89 to i32
  %91 = sub nsw i32 %90, 97
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [26 x i32], ptr %84, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %11, align 4, !tbaa !5
  %96 = load i32, ptr %11, align 4, !tbaa !5
  %97 = load i32, ptr %6, align 4, !tbaa !5
  %98 = sub nsw i32 %97, 1
  %99 = icmp sle i32 %96, %98
  br i1 %99, label %100, label %109

100:                                              ; preds = %81
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %101 = load i32, ptr %11, align 4, !tbaa !5
  %102 = load i32, ptr %6, align 4, !tbaa !5
  %103 = sub nsw i32 %102, 1
  %104 = load i32, ptr %7, align 4, !tbaa !5
  %105 = call noundef i32 @_Z4calciii(i32 noundef %101, i32 noundef %103, i32 noundef %104)
  %106 = add nsw i32 %105, 2
  store i32 %106, ptr %12, align 4, !tbaa !5
  %107 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %108 = load i32, ptr %107, align 4, !tbaa !5
  store i32 %108, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %109

109:                                              ; preds = %100, %81
  %110 = load i32, ptr %8, align 4, !tbaa !5
  %111 = load i32, ptr %5, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [310 x [310 x [310 x i32]]], ptr @DP, i64 0, i64 %112
  %114 = load i32, ptr %6, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [310 x [310 x i32]], ptr %113, i64 0, i64 %115
  %117 = load i32, ptr %7, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [310 x i32], ptr %116, i64 0, i64 %118
  store i32 %110, ptr %119, align 4, !tbaa !5
  %120 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %120, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %121

121:                                              ; preds = %109, %36, %20
  %122 = load i32, ptr %4, align 4
  ret i32 %122
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #3 align 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 = { 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 = !{!7, !7, i64 0}


; 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::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z1SB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@DP = external dso_local local_unnamed_addr global [310 x [310 x [310 x i32]]], align 16
@DP2 = external dso_local local_unnamed_addr global [310 x [26 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z4calciii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = sub nsw i32 %1, %0
  %9 = shl nsw i32 %2, 1
  %10 = or disjoint i32 %9, 1
  %.not = icmp sgt i32 %8, %10
  br i1 %.not, label %11, label %48

11:                                               ; preds = %3
  %12 = sext i32 %0 to i64
  %13 = sext i32 %1 to i64
  %14 = sext i32 %2 to i64
  %15 = getelementptr inbounds [310 x [310 x [310 x i32]]], ptr @DP, i64 0, i64 %12, i64 %13, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %.not40 = icmp eq i32 %16, -1
  br i1 %.not40, label %17, label %48

17:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  %18 = add nsw i32 %1, -1
  %.not41.not = icmp sgt i32 %18, %0
  %19 = icmp sgt i32 %2, 0
  %or.cond = and i1 %.not41.not, %19
  br i1 %or.cond, label %20, label %27

20:                                               ; preds = %17
  %21 = add nsw i32 %0, 1
  %22 = add nsw i32 %2, -1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %23 = tail call noundef i32 @_Z4calciii(i32 noundef %21, i32 noundef %18, i32 noundef %22)
  %24 = add nsw i32 %23, 2
  store i32 %24, ptr %5, align 4, !tbaa !5
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %27

27:                                               ; preds = %20, %17
  %.not42.not = icmp sgt i32 %1, %0
  br i1 %.not42.not, label %28, label %32

28:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %29 = call noundef i32 @_Z4calciii(i32 noundef %0, i32 noundef %18, i32 noundef %2)
  store i32 %29, ptr %6, align 4, !tbaa !5
  %30 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %31 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %31, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  br label %32

32:                                               ; preds = %28, %27
  %33 = sext i32 %18 to i64
  %34 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1SB5cxx11, i64 noundef %33)
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = sext i8 %35 to i64
  %37 = add nsw i64 %36, -97
  %38 = getelementptr inbounds [310 x [26 x i32]], ptr @DP2, i64 0, i64 %12, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %.not43.not = icmp slt i32 %39, %18
  br i1 %.not43.not, label %40, label %._crit_edge

._crit_edge:                                      ; preds = %32
  %.pre = load i32, ptr %4, align 4, !tbaa !5
  br label %46

40:                                               ; preds = %32
  %41 = add nsw i32 %39, 1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  %42 = call noundef i32 @_Z4calciii(i32 noundef %41, i32 noundef %18, i32 noundef %2)
  %43 = add nsw i32 %42, 2
  store i32 %43, ptr %7, align 4, !tbaa !5
  %44 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %45 = load i32, ptr %44, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  br label %46

46:                                               ; preds = %._crit_edge, %40
  %47 = phi i32 [ %.pre, %._crit_edge ], [ %45, %40 ]
  store i32 %47, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %48

48:                                               ; preds = %11, %3, %46
  %.0 = phi i32 [ %47, %46 ], [ %8, %3 ], [ %16, %11 ]
  ret i32 %.0
}

; 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 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) 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: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #0 align 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 = !{!7, !7, i64 0}


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