; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/1671.ll (Z4Initv)

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

%struct.node = type { i8, [10 x i32] }

@x = external dso_local global i8, align 1
@ptr = external dso_local global i32, align 4
@list = external dso_local global [100000 x %struct.node], align 16

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

4:                                                ; preds = %29, %0
  %5 = load i32, ptr %1, align 4, !tbaa !9
  %6 = icmp slt i32 %5, 100000
  br i1 %6, label %8, label %7

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

8:                                                ; preds = %4
  %9 = load i32, ptr %1, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %10
  %12 = getelementptr inbounds %struct.node, ptr %11, i32 0, i32 0
  store i8 0, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %25, %8
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 10
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %13
  %18 = load i32, ptr %1, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.node, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10 x i32], ptr %21, i64 0, i64 %23
  store i32 -1, ptr %24, align 4, !tbaa !9
  br label %25

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

28:                                               ; preds = %16
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %1, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %1, align 4, !tbaa !9
  br label %4, !llvm.loop !15

32:                                               ; preds = %7
  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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4node", !6, i64 0, !7, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

%struct.node = type { i8, [10 x i32] }

@x = external dso_local local_unnamed_addr global i8, align 1
@ptr = external dso_local local_unnamed_addr global i32, align 4
@list = external dso_local local_unnamed_addr global [100000 x %struct.node], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4Initv() local_unnamed_addr #0 {
  store i8 1, ptr @x, align 1, !tbaa !5
  store i32 0, ptr @ptr, align 4, !tbaa !9
  br label %2

1:                                                ; preds = %2
  ret void

2:                                                ; preds = %2, %0
  %indvar = phi i64 [ 0, %0 ], [ %indvar.next.3, %2 ]
  %3 = mul nuw nsw i64 %indvar, 44
  %gep = getelementptr i8, ptr getelementptr inbounds (i8, ptr @list, i64 4), i64 %3
  %4 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %indvar
  store i8 0, ptr %4, align 16, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(40) %gep, i8 -1, i64 40, i1 false), !tbaa !9
  %indvar.next = or disjoint i64 %indvar, 1
  %5 = mul nuw nsw i64 %indvar.next, 44
  %gep.1 = getelementptr i8, ptr getelementptr inbounds (i8, ptr @list, i64 4), i64 %5
  %6 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %indvar.next
  store i8 0, ptr %6, align 4, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %gep.1, i8 -1, i64 40, i1 false), !tbaa !9
  %indvar.next.1 = or disjoint i64 %indvar, 2
  %7 = mul nuw nsw i64 %indvar.next.1, 44
  %gep.2 = getelementptr i8, ptr getelementptr inbounds (i8, ptr @list, i64 4), i64 %7
  %8 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %indvar.next.1
  store i8 0, ptr %8, align 8, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(40) %gep.2, i8 -1, i64 40, i1 false), !tbaa !9
  %indvar.next.2 = or disjoint i64 %indvar, 3
  %9 = mul nuw nsw i64 %indvar.next.2, 44
  %gep.3 = getelementptr i8, ptr getelementptr inbounds (i8, ptr @list, i64 4), i64 %9
  %10 = getelementptr inbounds [100000 x %struct.node], ptr @list, i64 0, i64 %indvar.next.2
  store i8 0, ptr %10, align 4, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %gep.3, i8 -1, i64 40, i1 false), !tbaa !9
  %indvar.next.3 = add nuw nsw i64 %indvar, 4
  %exitcond.not.3 = icmp eq i64 %indvar.next.3, 100000
  br i1 %exitcond.not.3, label %1, label %2, !llvm.loop !13
}

; 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 nofree norecurse nosync nounwind memory(write, 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" }
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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4node", !6, i64 0, !7, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass