; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Codesprints 2017/Codesprint 9/Problem F/brute.ll (Z4calcv)

; 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"

@lg = external dso_local global [300005 x i32], align 16
@st = external dso_local global [18 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4calcv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 1, ptr @st, align 16, !tbaa !5
  store i32 0, ptr getelementptr inbounds ([300005 x i32], ptr @lg, i64 0, i64 1), 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 %3

3:                                                ; preds = %24, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp slt i32 %4, 18
  br i1 %5, label %7, label %6

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

7:                                                ; preds = %3
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = sub nsw i32 %8, 1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [18 x i32], ptr @st, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = mul nsw i32 %12, 2
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [18 x i32], ptr @st, i64 0, i64 %15
  store i32 %13, ptr %16, align 4, !tbaa !5
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [18 x i32], ptr @st, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [300005 x i32], ptr @lg, i64 0, i64 %22
  store i32 %17, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %7
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !9

27:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %48, %27
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = icmp sle i32 %29, 300005
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %51

32:                                               ; preds = %28
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [300005 x i32], ptr @lg, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %47, label %38

38:                                               ; preds = %32
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [300005 x i32], ptr @lg, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [300005 x i32], ptr @lg, i64 0, i64 %45
  store i32 %43, ptr %46, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %38, %32
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %2, align 4, !tbaa !5
  br label %28, !llvm.loop !11

51:                                               ; preds = %31
  ret void
}

; 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

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


; 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"

@lg = external dso_local local_unnamed_addr global [300005 x i32], align 16
@st = external dso_local local_unnamed_addr global [18 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4calcv() local_unnamed_addr #0 {
.preheader.preheader:
  store i32 0, ptr getelementptr inbounds (i8, ptr @lg, i64 4), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @lg, i64 8), align 8, !tbaa !5
  store i32 2, ptr getelementptr inbounds (i8, ptr @lg, i64 16), align 16, !tbaa !5
  store <4 x i32> <i32 1, i32 2, i32 4, i32 8>, ptr @st, align 16, !tbaa !5
  store i32 3, ptr getelementptr inbounds (i8, ptr @lg, i64 32), align 16, !tbaa !5
  store i32 4, ptr getelementptr inbounds (i8, ptr @lg, i64 64), align 16, !tbaa !5
  store i32 5, ptr getelementptr inbounds (i8, ptr @lg, i64 128), align 16, !tbaa !5
  store i32 6, ptr getelementptr inbounds (i8, ptr @lg, i64 256), align 16, !tbaa !5
  store <4 x i32> <i32 16, i32 32, i32 64, i32 128>, ptr getelementptr inbounds (i8, ptr @st, i64 16), align 16, !tbaa !5
  store i32 7, ptr getelementptr inbounds (i8, ptr @lg, i64 512), align 16, !tbaa !5
  store i32 8, ptr getelementptr inbounds (i8, ptr @lg, i64 1024), align 16, !tbaa !5
  store i32 9, ptr getelementptr inbounds (i8, ptr @lg, i64 2048), align 16, !tbaa !5
  store i32 10, ptr getelementptr inbounds (i8, ptr @lg, i64 4096), align 16, !tbaa !5
  store <4 x i32> <i32 256, i32 512, i32 1024, i32 2048>, ptr getelementptr inbounds (i8, ptr @st, i64 32), align 16, !tbaa !5
  store i32 11, ptr getelementptr inbounds (i8, ptr @lg, i64 8192), align 16, !tbaa !5
  store i32 12, ptr getelementptr inbounds (i8, ptr @lg, i64 16384), align 16, !tbaa !5
  store i32 13, ptr getelementptr inbounds (i8, ptr @lg, i64 32768), align 16, !tbaa !5
  store i32 14, ptr getelementptr inbounds (i8, ptr @lg, i64 65536), align 16, !tbaa !5
  store <4 x i32> <i32 4096, i32 8192, i32 16384, i32 32768>, ptr getelementptr inbounds (i8, ptr @st, i64 48), align 16, !tbaa !5
  store i32 15, ptr getelementptr inbounds (i8, ptr @lg, i64 131072), align 16, !tbaa !5
  store i32 65536, ptr getelementptr inbounds (i8, ptr @st, i64 64), align 16, !tbaa !5
  store i32 16, ptr getelementptr inbounds (i8, ptr @lg, i64 262144), align 16, !tbaa !5
  store i32 131072, ptr getelementptr inbounds (i8, ptr @st, i64 68), align 4, !tbaa !5
  store i32 17, ptr getelementptr inbounds (i8, ptr @lg, i64 524288), align 16, !tbaa !5
  br label %.preheader

0:                                                ; preds = %12
  ret void

.preheader:                                       ; preds = %12, %.preheader.preheader
  %indvars.iv = phi i64 [ 2, %.preheader.preheader ], [ %indvars.iv.next.1, %12 ]
  %1 = getelementptr inbounds [300005 x i32], ptr @lg, i64 0, i64 %indvars.iv
  %2 = load i32, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %3, label %.preheader.1

3:                                                ; preds = %.preheader
  %4 = add nsw i64 %indvars.iv, -1
  %5 = getelementptr inbounds [300005 x i32], ptr @lg, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %6, ptr %1, align 8, !tbaa !5
  br label %.preheader.1

.preheader.1:                                     ; preds = %.preheader, %3
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %7 = getelementptr inbounds [300005 x i32], ptr @lg, i64 0, i64 %indvars.iv.next
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %8, 0
  br i1 %.not.1, label %9, label %12

9:                                                ; preds = %.preheader.1
  %10 = getelementptr inbounds [300005 x i32], ptr @lg, i64 0, i64 %indvars.iv
  %11 = load i32, ptr %10, align 8, !tbaa !5
  store i32 %11, ptr %7, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %9, %.preheader.1
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 300006
  br i1 %exitcond.not.1, label %0, label %.preheader, !llvm.loop !9
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass