; LLVM IR from eyangch/competitive-programming :: USACOcontests/platinum/2020.02/triangles.ll (Z4elimv)

; 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 i64, align 8
@ans = external dso_local global i64, align 8
@_Z1SB5cxx11 = external dso_local global [300 x %"class.std::__cxx11::basic_string"], align 16

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

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

; 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 uwtable
define dso_local void @_Z4elimv() #2 {
  %1 = alloca i64, align 8
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store i64 0, ptr %1, align 8, !tbaa !5
  br label %9

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

13:                                               ; preds = %9
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  br label %101

14:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %94, %14
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = load i64, ptr @N, align 8, !tbaa !5
  %18 = icmp slt i64 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %97

20:                                               ; preds = %15
  %21 = load i64, ptr %1, align 8, !tbaa !5
  %22 = getelementptr inbounds [300 x %"class.std::__cxx11::basic_string"], ptr @_Z1SB5cxx11, i64 0, i64 %21
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %22, i64 noundef %23)
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = sext i8 %25 to i32
  %27 = icmp ne i32 %26, 42
  br i1 %27, label %28, label %29

28:                                               ; preds = %20
  br label %94

29:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %30 = load i64, ptr %3, align 8, !tbaa !5
  %31 = add nsw i64 %30, 2
  store i64 %31, ptr %4, align 8, !tbaa !5
  br label %32

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

36:                                               ; preds = %32
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %93

37:                                               ; preds = %32
  %38 = load i64, ptr %1, align 8, !tbaa !5
  %39 = getelementptr inbounds [300 x %"class.std::__cxx11::basic_string"], ptr @_Z1SB5cxx11, i64 0, i64 %38
  %40 = load i64, ptr %4, align 8, !tbaa !5
  %41 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %39, i64 noundef %40)
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  %44 = icmp ne i32 %43, 42
  br i1 %44, label %45, label %46

45:                                               ; preds = %37
  br label %90

46:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = load i64, ptr %4, align 8, !tbaa !5
  %49 = add nsw i64 %47, %48
  %50 = sdiv i64 %49, 2
  store i64 %50, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %51 = load i64, ptr %4, align 8, !tbaa !5
  %52 = load i64, ptr %3, align 8, !tbaa !5
  %53 = sub nsw i64 %51, %52
  %54 = sdiv i64 %53, 2
  store i64 %54, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %55 = load i64, ptr %1, align 8, !tbaa !5
  %56 = load i64, ptr %6, align 8, !tbaa !5
  %57 = sub nsw i64 %55, %56
  store i64 %57, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %58 = load i64, ptr %1, align 8, !tbaa !5
  %59 = load i64, ptr %6, align 8, !tbaa !5
  %60 = add nsw i64 %58, %59
  store i64 %60, ptr %8, align 8, !tbaa !5
  %61 = load i64, ptr %7, align 8, !tbaa !5
  %62 = icmp sge i64 %61, 0
  br i1 %62, label %63, label %74

63:                                               ; preds = %46
  %64 = load i64, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds [300 x %"class.std::__cxx11::basic_string"], ptr @_Z1SB5cxx11, i64 0, i64 %64
  %66 = load i64, ptr %5, align 8, !tbaa !5
  %67 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %65, i64 noundef %66)
  %68 = load i8, ptr %67, align 1, !tbaa !9
  %69 = sext i8 %68 to i32
  %70 = icmp eq i32 %69, 42
  br i1 %70, label %71, label %74

71:                                               ; preds = %63
  %72 = load i64, ptr @ans, align 8, !tbaa !5
  %73 = add nsw i64 %72, -1
  store i64 %73, ptr @ans, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %71, %63, %46
  %75 = load i64, ptr %8, align 8, !tbaa !5
  %76 = load i64, ptr @N, align 8, !tbaa !5
  %77 = icmp slt i64 %75, %76
  br i1 %77, label %78, label %89

78:                                               ; preds = %74
  %79 = load i64, ptr %8, align 8, !tbaa !5
  %80 = getelementptr inbounds [300 x %"class.std::__cxx11::basic_string"], ptr @_Z1SB5cxx11, i64 0, i64 %79
  %81 = load i64, ptr %5, align 8, !tbaa !5
  %82 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %80, i64 noundef %81)
  %83 = load i8, ptr %82, align 1, !tbaa !9
  %84 = sext i8 %83 to i32
  %85 = icmp eq i32 %84, 42
  br i1 %85, label %86, label %89

86:                                               ; preds = %78
  %87 = load i64, ptr @ans, align 8, !tbaa !5
  %88 = add nsw i64 %87, -1
  store i64 %88, ptr @ans, align 8, !tbaa !5
  br label %89

89:                                               ; preds = %86, %78, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %90

90:                                               ; preds = %89, %45
  %91 = load i64, ptr %4, align 8, !tbaa !5
  %92 = add nsw i64 %91, 2
  store i64 %92, ptr %4, align 8, !tbaa !5
  br label %32, !llvm.loop !10

93:                                               ; preds = %36
  br label %94

94:                                               ; preds = %93, %28
  %95 = load i64, ptr %3, align 8, !tbaa !5
  %96 = add nsw i64 %95, 1
  store i64 %96, ptr %3, align 8, !tbaa !5
  br label %15, !llvm.loop !12

97:                                               ; preds = %19
  br label %98

98:                                               ; preds = %97
  %99 = load i64, ptr %1, align 8, !tbaa !5
  %100 = add nsw i64 %99, 1
  store i64 %100, ptr %1, align 8, !tbaa !5
  br label %9, !llvm.loop !13

101:                                              ; preds = %13
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}


; 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 i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@_Z1SB5cxx11 = external dso_local global [300 x %"class.std::__cxx11::basic_string"], align 16

; 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
define dso_local void @_Z4elimv() local_unnamed_addr #0 {
  %1 = load i64, ptr @N, align 8, !tbaa !5
  %2 = icmp sgt i64 %1, 0
  br i1 %2, label %.preheader30, label %._crit_edge36

.preheader30:                                     ; preds = %0, %._crit_edge
  %3 = phi i64 [ %6, %._crit_edge ], [ %1, %0 ]
  %.035 = phi i64 [ %7, %._crit_edge ], [ 0, %0 ]
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %.lr.ph34, label %._crit_edge

.lr.ph34:                                         ; preds = %.preheader30
  %5 = getelementptr inbounds [300 x %"class.std::__cxx11::basic_string"], ptr @_Z1SB5cxx11, i64 0, i64 %.035
  br label %9

._crit_edge36:                                    ; preds = %._crit_edge, %0
  ret void

._crit_edge:                                      ; preds = %.loopexit, %.preheader30
  %6 = phi i64 [ %3, %.preheader30 ], [ %45, %.loopexit ]
  %7 = add nuw nsw i64 %.035, 1
  %8 = icmp slt i64 %7, %6
  br i1 %8, label %.preheader30, label %._crit_edge36, !llvm.loop !9

9:                                                ; preds = %.lr.ph34, %.loopexit
  %.02533 = phi i64 [ 0, %.lr.ph34 ], [ %46, %.loopexit ]
  %10 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %5, i64 noundef %.02533)
  %11 = load i8, ptr %10, align 1, !tbaa !12
  %.not = icmp eq i8 %11, 42
  %.pre = load i64, ptr @N, align 8, !tbaa !5
  %.02631 = add nuw nsw i64 %.02533, 2
  %12 = icmp slt i64 %.02631, %.pre
  %or.cond = select i1 %.not, i1 %12, i1 false
  br i1 %or.cond, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %9, %42
  %.02632 = phi i64 [ %.026, %42 ], [ %.02631, %9 ]
  %13 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %5, i64 noundef %.02632)
  %14 = load i8, ptr %13, align 1, !tbaa !12
  %.not29 = icmp eq i8 %14, 42
  br i1 %.not29, label %15, label %42

15:                                               ; preds = %.lr.ph
  %16 = add nuw nsw i64 %.02632, %.02533
  %17 = lshr i64 %16, 1
  %18 = sub nsw i64 %.02632, %.02533
  %19 = sdiv i64 %18, 2
  %20 = sub nsw i64 %.035, %19
  %21 = add nsw i64 %19, %.035
  %22 = icmp sgt i64 %20, -1
  br i1 %22, label %23, label %31

23:                                               ; preds = %15
  %24 = getelementptr inbounds [300 x %"class.std::__cxx11::basic_string"], ptr @_Z1SB5cxx11, i64 0, i64 %20
  %25 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %24, i64 noundef %17)
  %26 = load i8, ptr %25, align 1, !tbaa !12
  %27 = icmp eq i8 %26, 42
  br i1 %27, label %28, label %31

28:                                               ; preds = %23
  %29 = load i64, ptr @ans, align 8, !tbaa !5
  %30 = add nsw i64 %29, -1
  store i64 %30, ptr @ans, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %28, %23, %15
  %32 = load i64, ptr @N, align 8, !tbaa !5
  %33 = icmp slt i64 %21, %32
  br i1 %33, label %34, label %42

34:                                               ; preds = %31
  %35 = getelementptr inbounds [300 x %"class.std::__cxx11::basic_string"], ptr @_Z1SB5cxx11, i64 0, i64 %21
  %36 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %35, i64 noundef %17)
  %37 = load i8, ptr %36, align 1, !tbaa !12
  %38 = icmp eq i8 %37, 42
  br i1 %38, label %39, label %42

39:                                               ; preds = %34
  %40 = load i64, ptr @ans, align 8, !tbaa !5
  %41 = add nsw i64 %40, -1
  store i64 %41, ptr @ans, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %31, %34, %39, %.lr.ph
  %.026 = add nuw nsw i64 %.02632, 2
  %43 = load i64, ptr @N, align 8, !tbaa !5
  %44 = icmp slt i64 %.026, %43
  br i1 %44, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %42, %9
  %45 = phi i64 [ %.pre, %9 ], [ %43, %42 ]
  %46 = add nuw nsw i64 %.02533, 1
  %47 = icmp slt i64 %46, %45
  br i1 %47, label %9, label %._crit_edge, !llvm.loop !14
}

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.unswitch.partial.disable"}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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