; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/250 Division 1/Problem C/C2.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::complex" = type { i64, i64 }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@n = external dso_local global i32, align 4
@f = external dso_local global [200 x [200 x i32]], align 16
@p = external dso_local global [200 x %"class.std::complex"], align 16
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; 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 uwtable
declare dso_local noundef i64 @_Z3ccwRKSt7complexIxES2_S2_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1

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

6:                                                ; preds = %96, %0
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %12 = load i32, ptr %1, align 4, !tbaa !5
  store i32 %12, ptr %4, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %90, %11
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %13
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %28

21:                                               ; preds = %18
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [200 x [200 x i32]], ptr @f, i64 0, i64 %23
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [200 x i32], ptr %24, i64 0, i64 %26
  store i32 1, ptr %27, align 4, !tbaa !5
  br label %89

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

31:                                               ; preds = %85, %28
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

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

36:                                               ; preds = %31
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [200 x %"class.std::complex"], ptr @p, i64 0, i64 %38
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [200 x %"class.std::complex"], ptr @p, i64 0, i64 %41
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [200 x %"class.std::complex"], ptr @p, i64 0, i64 %44
  %46 = call noundef i64 @_Z3ccwRKSt7complexIxES2_S2_(ptr noundef nonnull align 8 dereferenceable(16) %39, ptr noundef nonnull align 8 dereferenceable(16) %42, ptr noundef nonnull align 8 dereferenceable(16) %45)
  %47 = icmp slt i64 %46, 0
  br i1 %47, label %48, label %84

48:                                               ; preds = %36
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [200 x [200 x i32]], ptr @f, i64 0, i64 %50
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [200 x i32], ptr %51, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [200 x [200 x i32]], ptr @f, i64 0, i64 %58
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [200 x i32], ptr %59, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = mul nsw i64 1, %64
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [200 x [200 x i32]], ptr @f, i64 0, i64 %67
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [200 x i32], ptr %68, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = mul nsw i64 %65, %73
  %75 = add nsw i64 %56, %74
  %76 = srem i64 %75, 1000000007
  %77 = trunc i64 %76 to i32
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [200 x [200 x i32]], ptr @f, i64 0, i64 %79
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [200 x i32], ptr %80, i64 0, i64 %82
  store i32 %77, ptr %83, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %48, %36
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %5, align 4, !tbaa !5
  br label %31, !llvm.loop !9

88:                                               ; preds = %35
  br label %89

89:                                               ; preds = %88, %21
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %3, align 4, !tbaa !5
  %93 = load i32, ptr %4, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %4, align 4, !tbaa !5
  br label %13, !llvm.loop !11

95:                                               ; preds = %17
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %1, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !12

99:                                               ; preds = %10
  %100 = load i32, ptr @n, align 4, !tbaa !5
  %101 = sub nsw i32 %100, 1
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [200 x i32], ptr @f, i64 0, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %104)
  ret void
}

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #2

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


; 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::complex" = type { i64, i64 }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@n = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [200 x [200 x i32]], align 16
@p = external dso_local global [200 x %"class.std::complex"], align 16
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3ccwRKSt7complexIxES2_S2_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 1
  br i1 %2, label %.preheader28, label %._crit_edge38

.preheader28:                                     ; preds = %0, %._crit_edge
  %3 = phi i32 [ %15, %._crit_edge ], [ %1, %0 ]
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %._crit_edge ], [ 1, %0 ]
  %indvars60 = trunc i64 %indvars.iv44 to i32
  %4 = icmp sgt i32 %3, %indvars60
  br i1 %4, label %.lr.ph35, label %._crit_edge

.lr.ph35:                                         ; preds = %.preheader28
  %5 = icmp eq i32 %indvars60, 1
  br i1 %5, label %.lr.ph35.split.us, label %.preheader

.lr.ph35.split.us:                                ; preds = %.lr.ph35
  %6 = sext i32 %3 to i64
  br label %7

7:                                                ; preds = %7, %.lr.ph35.split.us
  %indvars.iv55 = phi i64 [ %indvars.iv.next56, %7 ], [ 0, %.lr.ph35.split.us ]
  %indvars.iv53 = phi i64 [ %indvars.iv.next54, %7 ], [ %indvars.iv44, %.lr.ph35.split.us ]
  %8 = getelementptr inbounds [200 x [200 x i32]], ptr @f, i64 0, i64 %indvars.iv55, i64 %indvars.iv53
  store i32 1, ptr %8, align 4, !tbaa !5
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %9 = icmp slt i64 %indvars.iv.next54, %6
  br i1 %9, label %7, label %._crit_edge, !llvm.loop !9

._crit_edge38:                                    ; preds = %._crit_edge, %0
  %.lcssa = phi i32 [ %1, %0 ], [ %15, %._crit_edge ]
  %10 = add nsw i32 %.lcssa, -1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [200 x i32], ptr @f, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %13)
  ret void

._crit_edge:                                      ; preds = %.loopexit, %7, %.preheader28
  %15 = phi i32 [ %3, %.preheader28 ], [ %3, %7 ], [ %41, %.loopexit ]
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %indvars = trunc i64 %indvars.iv.next45 to i32
  %16 = icmp sgt i32 %15, %indvars
  br i1 %16, label %.preheader28, label %._crit_edge38, !llvm.loop !11

.preheader:                                       ; preds = %.lr.ph35, %.loopexit
  %17 = phi i32 [ %41, %.loopexit ], [ %3, %.lr.ph35 ]
  %18 = phi i32 [ %42, %.loopexit ], [ %3, %.lr.ph35 ]
  %indvars.iv48 = phi i64 [ %indvars.iv.next49, %.loopexit ], [ 0, %.lr.ph35 ]
  %indvars.iv46 = phi i64 [ %indvars.iv.next47, %.loopexit ], [ %indvars.iv44, %.lr.ph35 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.loopexit ], [ 1, %.lr.ph35 ]
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %19 = icmp ult i64 %indvars.iv.next49, %indvars.iv46
  br i1 %19, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %20 = getelementptr inbounds [200 x %"class.std::complex"], ptr @p, i64 0, i64 %indvars.iv48
  %21 = getelementptr inbounds [200 x %"class.std::complex"], ptr @p, i64 0, i64 %indvars.iv46
  %22 = getelementptr inbounds [200 x [200 x i32]], ptr @f, i64 0, i64 %indvars.iv48, i64 %indvars.iv46
  br label %23

23:                                               ; preds = %.lr.ph, %40
  %indvars.iv41 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next42, %40 ]
  %24 = getelementptr inbounds [200 x %"class.std::complex"], ptr @p, i64 0, i64 %indvars.iv41
  %25 = tail call noundef i64 @_Z3ccwRKSt7complexIxES2_S2_(ptr noundef nonnull align 8 dereferenceable(16) %20, ptr noundef nonnull align 8 dereferenceable(16) %21, ptr noundef nonnull align 8 dereferenceable(16) %24)
  %26 = icmp slt i64 %25, 0
  br i1 %26, label %27, label %40

27:                                               ; preds = %23
  %28 = load i32, ptr %22, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [200 x [200 x i32]], ptr @f, i64 0, i64 %indvars.iv48, i64 %indvars.iv41
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [200 x [200 x i32]], ptr @f, i64 0, i64 %indvars.iv41, i64 %indvars.iv46
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = mul nsw i64 %35, %32
  %37 = add nsw i64 %36, %29
  %38 = srem i64 %37, 1000000007
  %39 = trunc nsw i64 %38 to i32
  store i32 %39, ptr %22, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %23, %27
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next42, %indvars.iv46
  br i1 %exitcond.not, label %.loopexit.loopexit, label %23, !llvm.loop !12

.loopexit.loopexit:                               ; preds = %40
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.preheader
  %41 = phi i32 [ %.pre, %.loopexit.loopexit ], [ %17, %.preheader ]
  %42 = phi i32 [ %.pre, %.loopexit.loopexit ], [ %18, %.preheader ]
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %43 = trunc nuw i64 %indvars.iv.next47 to i32
  %44 = icmp sgt i32 %42, %43
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %44, label %.preheader, label %._crit_edge, !llvm.loop !9
}

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #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 = { "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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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