; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1112（SG函数）.ll (Z2SGv)

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

@sg = external dso_local global [100 x i32], align 16
@vis = external dso_local global [100 x i8], 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
define dso_local void @_Z2SGv() #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
  store i32 0, ptr @sg, align 16, !tbaa !5
  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 = %66, %0
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 100
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %6
  call void @llvm.memset.p0.i64(ptr align 16 @vis, i8 0, i64 100, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %23, %10
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %11
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100 x i8], ptr @vis, i64 0, i64 %21
  store i8 1, ptr %22, align 1, !tbaa !9
  br label %23

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

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

27:                                               ; preds = %46, %26
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = load i32, ptr %1, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

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

32:                                               ; preds = %27
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = load i32, ptr %1, align 4, !tbaa !5
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sub nsw i32 %37, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = xor i32 %36, %42
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100 x i8], ptr @vis, i64 0, i64 %44
  store i8 1, ptr %45, align 1, !tbaa !9
  br label %46

46:                                               ; preds = %32
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %4, align 4, !tbaa !5
  br label %27, !llvm.loop !13

49:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %62, %49
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100 x i8], ptr @vis, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !9, !range !14, !noundef !15
  %55 = trunc i8 %54 to i1
  br i1 %55, label %61, label %56

56:                                               ; preds = %50
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = load i32, ptr %1, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %59
  store i32 %57, ptr %60, align 4, !tbaa !5
  store i32 11, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %65

61:                                               ; preds = %50
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %5, align 4, !tbaa !5
  br label %50, !llvm.loop !16

65:                                               ; preds = %56
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %1, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !17

69:                                               ; preds = %9
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


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

@sg = external dso_local local_unnamed_addr global [100 x i32], align 16
@vis = external dso_local local_unnamed_addr global [100 x i8], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z2SGv() local_unnamed_addr #0 {
  store i32 0, ptr @sg, align 16, !tbaa !5
  br label %2

1:                                                ; preds = %54
  ret void

2:                                                ; preds = %0, %54
  %indvar = phi i64 [ 0, %0 ], [ %indvar.next, %54 ]
  %indvars.iv32 = phi i64 [ 1, %0 ], [ %indvars.iv.next33, %54 ]
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(100) @vis, i8 0, i64 100, i1 false)
  %xtraiter = and i64 %indvars.iv32, 3
  %3 = icmp ult i64 %indvar, 3
  br i1 %3, label %.preheader19.unr-lcssa, label %.new

.new:                                             ; preds = %2
  %unroll_iter = and i64 %indvars.iv32, 9223372036854775804
  br label %10

.preheader19.unr-lcssa:                           ; preds = %10, %2
  %indvars.iv.unr = phi i64 [ 0, %2 ], [ %indvars.iv.next.3, %10 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader19, label %.epil.preheader

.epil.preheader:                                  ; preds = %.preheader19.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %.preheader19.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.preheader19.unr-lcssa ]
  %4 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %indvars.iv.epil
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [100 x i8], ptr @vis, i64 0, i64 %6
  store i8 1, ptr %7, align 1, !tbaa !9
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader19, label %.epil.preheader, !llvm.loop !11

.preheader19:                                     ; preds = %.epil.preheader, %.preheader19.unr-lcssa
  %8 = icmp ugt i64 %indvars.iv32, 1
  br i1 %8, label %.lr.ph.preheader, label %.preheader.preheader

.lr.ph.preheader:                                 ; preds = %.preheader19
  %xtraiter36 = and i64 %indvar, 1
  %9 = icmp eq i64 %indvar, 1
  br i1 %9, label %.preheader.preheader.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter39 = and i64 %indvar, -2
  br label %.lr.ph

10:                                               ; preds = %10, %.new
  %indvars.iv = phi i64 [ 0, %.new ], [ %indvars.iv.next.3, %10 ]
  %niter = phi i64 [ 0, %.new ], [ %niter.next.3, %10 ]
  %11 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %indvars.iv
  %12 = load i32, ptr %11, align 16, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100 x i8], ptr @vis, i64 0, i64 %13
  store i8 1, ptr %14, align 1, !tbaa !9
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %15 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %indvars.iv.next
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100 x i8], ptr @vis, i64 0, i64 %17
  store i8 1, ptr %18, align 1, !tbaa !9
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %19 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %indvars.iv.next.1
  %20 = load i32, ptr %19, align 8, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100 x i8], ptr @vis, i64 0, i64 %21
  store i8 1, ptr %22, align 1, !tbaa !9
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %23 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %indvars.iv.next.2
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100 x i8], ptr @vis, i64 0, i64 %25
  store i8 1, ptr %26, align 1, !tbaa !9
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader19.unr-lcssa, label %10, !llvm.loop !13

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv24 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next25.1, %.lr.ph ]
  %niter40 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter40.next.1, %.lr.ph ]
  %27 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %indvars.iv24
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sub nsw i64 %indvars.iv32, %indvars.iv24
  %30 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = xor i32 %31, %28
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [100 x i8], ptr @vis, i64 0, i64 %33
  store i8 1, ptr %34, align 1, !tbaa !9
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %35 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %indvars.iv.next25
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sub nsw i64 %indvars.iv32, %indvars.iv.next25
  %38 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = xor i32 %39, %36
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100 x i8], ptr @vis, i64 0, i64 %41
  store i8 1, ptr %42, align 1, !tbaa !9
  %indvars.iv.next25.1 = add nuw nsw i64 %indvars.iv24, 2
  %niter40.next.1 = add i64 %niter40, 2
  %niter40.ncmp.1 = icmp eq i64 %niter40.next.1, %unroll_iter39
  br i1 %niter40.ncmp.1, label %.preheader.preheader.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !15

.preheader.preheader.loopexit.unr-lcssa:          ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv24.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next25.1, %.lr.ph ]
  %lcmp.mod38.not = icmp eq i64 %xtraiter36, 0
  br i1 %lcmp.mod38.not, label %.preheader.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader.preheader.loopexit.unr-lcssa
  %43 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %indvars.iv24.unr
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = sub nsw i64 %indvars.iv32, %indvars.iv24.unr
  %46 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = xor i32 %47, %44
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100 x i8], ptr @vis, i64 0, i64 %49
  store i8 1, ptr %50, align 1, !tbaa !9
  br label %.preheader.preheader

.preheader.preheader:                             ; preds = %.lr.ph.epil, %.preheader.preheader.loopexit.unr-lcssa, %.preheader19
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %.preheader ], [ 0, %.preheader.preheader ]
  %51 = getelementptr inbounds [100 x i8], ptr @vis, i64 0, i64 %indvars.iv29
  %52 = load i8, ptr %51, align 1, !tbaa !9, !range !16, !noundef !17
  %53 = trunc nuw i8 %52 to i1
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  br i1 %53, label %.preheader, label %54, !llvm.loop !18

54:                                               ; preds = %.preheader
  %55 = trunc nuw nsw i64 %indvars.iv29 to i32
  %56 = getelementptr inbounds [100 x i32], ptr @sg, i64 0, i64 %indvars.iv32
  store i32 %55, ptr %56, align 4, !tbaa !5
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond35.not = icmp eq i64 %indvars.iv.next33, 100
  %indvar.next = add i64 %indvar, 1
  br i1 %exitcond35.not, label %1, label %2, !llvm.loop !19
}

; Function Attrs: mustprogress 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(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" }
attributes #1 = { mustprogress 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass