; LLVM IR from kazunetakahashi/atcoder :: 2019/0915_ABC141/past/E.ll (Z4calcii)

; 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] }

@N = external dso_local global i32, align 4
@_Z1SB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@dp = external dso_local global [5010 x [5010 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4calcii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [5010 x [5010 x i32]], ptr @dp, i64 0, i64 %7
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [5010 x i32], ptr %8, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp sge i32 %12, 0
  br i1 %13, label %14, label %22

14:                                               ; preds = %2
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [5010 x [5010 x i32]], ptr @dp, i64 0, i64 %16
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [5010 x i32], ptr %17, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  store i32 %21, ptr %3, align 4
  br label %84

22:                                               ; preds = %2
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp sle i32 0, %23
  br i1 %24, label %25, label %36

25:                                               ; preds = %22
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr @N, align 4, !tbaa !5
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %29, label %36

29:                                               ; preds = %25
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = icmp sle i32 0, %30
  br i1 %31, label %32, label %36

32:                                               ; preds = %29
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = load i32, ptr @N, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %43, label %36

36:                                               ; preds = %32, %29, %25, %22
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [5010 x [5010 x i32]], ptr @dp, i64 0, i64 %38
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [5010 x i32], ptr %39, i64 0, i64 %41
  store i32 0, ptr %42, align 4, !tbaa !5
  br label %76

43:                                               ; preds = %32
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1SB5cxx11, i64 noundef %45)
  %47 = load i8, ptr %46, align 1, !tbaa !9
  %48 = sext i8 %47 to i32
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1SB5cxx11, i64 noundef %50)
  %52 = load i8, ptr %51, align 1, !tbaa !9
  %53 = sext i8 %52 to i32
  %54 = icmp ne i32 %48, %53
  br i1 %54, label %55, label %62

55:                                               ; preds = %43
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [5010 x [5010 x i32]], ptr @dp, i64 0, i64 %57
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [5010 x i32], ptr %58, i64 0, i64 %60
  store i32 0, ptr %61, align 4, !tbaa !5
  br label %75

62:                                               ; preds = %43
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [5010 x [5010 x i32]], ptr @dp, i64 0, i64 %64
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [5010 x i32], ptr %65, i64 0, i64 %67
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  %73 = call noundef i32 @_Z4calcii(i32 noundef %70, i32 noundef %72)
  %74 = add nsw i32 %73, 1
  call void @_Z6ch_maxIiEvRT_S0_(ptr noundef nonnull align 4 dereferenceable(4) %68, i32 noundef %74)
  br label %75

75:                                               ; preds = %62, %55
  br label %76

76:                                               ; preds = %75, %36
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [5010 x [5010 x i32]], ptr @dp, i64 0, i64 %78
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [5010 x i32], ptr %79, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !5
  store i32 %83, ptr %3, align 4
  br label %84

84:                                               ; preds = %76, %14
  %85 = load i32, ptr %3, align 4
  ret i32 %85
}

; 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) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6ch_maxIiEvRT_S0_(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #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 = { 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 = !{!"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] }

@N = external dso_local local_unnamed_addr global i32, align 4
@_Z1SB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@dp = external dso_local global [5010 x [5010 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z4calcii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = sext i32 %1 to i64
  %5 = getelementptr inbounds [5010 x [5010 x i32]], ptr @dp, i64 0, i64 %3, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, -1
  br i1 %7, label %common.ret, label %8

8:                                                ; preds = %2
  %9 = icmp sgt i32 %0, -1
  br i1 %9, label %10, label %15

10:                                               ; preds = %8
  %11 = load i32, ptr @N, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, %0
  %13 = icmp sgt i32 %1, -1
  %or.cond = and i1 %13, %12
  %14 = icmp sgt i32 %11, %1
  %or.cond26 = and i1 %14, %or.cond
  br i1 %or.cond26, label %16, label %15

15:                                               ; preds = %10, %8
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %common.ret

16:                                               ; preds = %10
  %17 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1SB5cxx11, i64 noundef %3)
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1SB5cxx11, i64 noundef %4)
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %.not = icmp eq i8 %18, %20
  br i1 %.not, label %22, label %21

21:                                               ; preds = %16
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %common.ret

common.ret:                                       ; preds = %2, %21, %15, %22
  %common.ret.op = phi i32 [ %.pre, %22 ], [ %6, %2 ], [ 0, %21 ], [ 0, %15 ]
  ret i32 %common.ret.op

22:                                               ; preds = %16
  %23 = add nuw nsw i32 %0, 1
  %24 = add nuw nsw i32 %1, 1
  %25 = tail call noundef i32 @_Z4calcii(i32 noundef %23, i32 noundef %24)
  %26 = add nsw i32 %25, 1
  tail call void @_Z6ch_maxIiEvRT_S0_(ptr noundef nonnull align 4 dereferenceable(4) %5, i32 noundef %26)
  %.pre = load i32, ptr %5, align 4, !tbaa !5
  br label %common.ret
}

; 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6ch_maxIiEvRT_S0_(ptr noundef nonnull align 4 dereferenceable(4), i32 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" }

!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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass