; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/World Cup 2016/World Cup Round 2/Problem C/C.ll (Z6sccompv)

; 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
@v = external dso_local global [100100 x i32], align 16
@comp = external dso_local global i32, align 4
@s = external dso_local global [100100 x i32], align 16
@ptr = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsi(i32 noundef) #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4dfs2ii(i32 noundef, i32 noundef) #0

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

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

8:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %21

9:                                                ; preds = %4
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [100100 x i32], ptr @v, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %17, label %15

15:                                               ; preds = %9
  %16 = load i32, ptr %1, align 4, !tbaa !5
  call void @_Z3dfsi(i32 noundef %16)
  br label %17

17:                                               ; preds = %15, %9
  br label %18

18:                                               ; preds = %17
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !9

21:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %31, %21
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %34

27:                                               ; preds = %22
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100100 x i32], ptr @v, i64 0, i64 %29
  store i32 0, ptr %30, align 4, !tbaa !5
  br label %31

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

34:                                               ; preds = %26
  br label %35

35:                                               ; preds = %51, %50, %34
  %36 = load i32, ptr @ptr, align 4, !tbaa !5
  %37 = sub nsw i32 %36, 1
  %38 = icmp sge i32 %37, 0
  br i1 %38, label %39, label %55

39:                                               ; preds = %35
  %40 = load i32, ptr @ptr, align 4, !tbaa !5
  %41 = add nsw i32 %40, -1
  store i32 %41, ptr @ptr, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100100 x i32], ptr @s, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  store i32 %44, ptr %2, align 4, !tbaa !5
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100100 x i32], ptr @v, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = icmp eq i32 %48, 1
  br i1 %49, label %50, label %51

50:                                               ; preds = %39
  br label %35, !llvm.loop !12

51:                                               ; preds = %39
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = load i32, ptr @comp, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr @comp, align 4, !tbaa !5
  call void @_Z4dfs2ii(i32 noundef %52, i32 noundef %53)
  br label %35, !llvm.loop !12

55:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  ret void
}

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

@n = external dso_local local_unnamed_addr global i32, align 4
@v = external dso_local local_unnamed_addr global [100100 x i32], align 16
@comp = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local local_unnamed_addr global [100100 x i32], align 16
@ptr = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4dfs2ii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6sccompv() local_unnamed_addr #0 {
  store i32 0, ptr @ptr, align 4, !tbaa !5
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %.not13 = icmp slt i32 %1, 1
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.preheader12:                                     ; preds = %9
  %.not1015 = icmp slt i32 %10, 1
  br i1 %.not1015, label %.preheader, label %.lr.ph17.preheader

.lr.ph17.preheader:                               ; preds = %.preheader12
  %2 = zext nneg i32 %10 to i64
  %3 = shl nuw nsw i64 %2, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @v, i64 4), i8 0, i64 %3, i1 false), !tbaa !5
  br label %.preheader

.lr.ph:                                           ; preds = %0, %9
  %4 = phi i32 [ %10, %9 ], [ %1, %0 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %9 ], [ 1, %0 ]
  %5 = getelementptr inbounds [100100 x i32], ptr @v, i64 0, i64 %indvars.iv
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not11 = icmp eq i32 %6, 0
  br i1 %.not11, label %7, label %9

7:                                                ; preds = %.lr.ph
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_Z3dfsi(i32 noundef %8)
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %.lr.ph, %7
  %10 = phi i32 [ %4, %.lr.ph ], [ %.pre, %7 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = sext i32 %10 to i64
  %.not.not = icmp slt i64 %indvars.iv, %11
  br i1 %.not.not, label %.lr.ph, label %.preheader12, !llvm.loop !9

.preheader:                                       ; preds = %.lr.ph17.preheader, %.preheader12
  %.pr = load i32, ptr @ptr, align 4, !tbaa !5
  %12 = icmp sgt i32 %.pr, 0
  br i1 %12, label %.lr.ph18, label %._crit_edge

.lr.ph18:                                         ; preds = %.preheader, %.backedge
  %13 = phi i32 [ %25, %.backedge ], [ %.pr, %.preheader ]
  %14 = add nsw i32 %13, -1
  store i32 %14, ptr @ptr, align 4, !tbaa !5
  %15 = zext nneg i32 %14 to i64
  %16 = getelementptr inbounds [100100 x i32], ptr @s, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100100 x i32], ptr @v, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %.backedge, label %22

22:                                               ; preds = %.lr.ph18
  %23 = load i32, ptr @comp, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr @comp, align 4, !tbaa !5
  tail call void @_Z4dfs2ii(i32 noundef %17, i32 noundef %23)
  %.pre24 = load i32, ptr @ptr, align 4, !tbaa !5
  br label %.backedge

.backedge:                                        ; preds = %22, %.lr.ph18
  %25 = phi i32 [ %.pre24, %22 ], [ %14, %.lr.ph18 ]
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph18, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.backedge, %0, %.preheader
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass