; LLVM IR from lzyrapx/Competitive-Programming :: LibreOJ/6084（dfs）.ll (Z5printi)

; 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
@Next = external dso_local global [100010 x [2 x i32]], align 16
@vis = external dso_local global [100010 x i32], align 16
@check = external dso_local global [100010 x i32], align 16
@ch = external dso_local global [100010 x i8], align 16
@tot = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [10 x i8], align 1

; 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
define dso_local void @_Z5printi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp eq i32 %6, %7
  br i1 %8, label %9, label %11

9:                                                ; preds = %1
  %10 = call i32 @puts(ptr noundef getelementptr inbounds (i8, ptr @ch, i64 1))
  call void @exit(i32 noundef 0) #4
  unreachable

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

17:                                               ; preds = %11
  %18 = call i32 @puts(ptr noundef @.str)
  call void @exit(i32 noundef 0) #4
  unreachable

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

20:                                               ; preds = %60, %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = icmp sle i32 %21, 1
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100010 x [2 x i32]], ptr @Next, i64 0, i64 %27
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [2 x i32], ptr %28, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %25, %32
  store i32 %33, ptr %5, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = icmp slt i32 %34, 1
  br i1 %35, label %40, label %36

36:                                               ; preds = %24
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %36, %24
  store i32 4, ptr %4, align 4
  br label %57

41:                                               ; preds = %36
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100010 x i32], ptr @check, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %56

47:                                               ; preds = %41
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = add nsw i32 %48, 97
  %50 = trunc i32 %49 to i8
  %51 = load i32, ptr @tot, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr @tot, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100010 x i8], ptr @ch, i64 0, i64 %53
  store i8 %50, ptr %54, align 1, !tbaa !9
  %55 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z5printi(i32 noundef %55)
  br label %56

56:                                               ; preds = %47, %41
  store i32 0, ptr %4, align 4
  br label %57

57:                                               ; preds = %56, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  %58 = load i32, ptr %4, align 4
  switch i32 %58, label %64 [
    i32 0, label %59
    i32 4, label %60
  ]

59:                                               ; preds = %57
  br label %60

60:                                               ; preds = %59, %57
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %3, align 4, !tbaa !5
  br label %20, !llvm.loop !10

63:                                               ; preds = %23
  ret void

64:                                               ; preds = %57
  unreachable
}

declare i32 @puts(ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

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 = { noreturn nounwind "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 #4 = { noreturn nounwind }
attributes #5 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; 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
@Next = external dso_local local_unnamed_addr global [100010 x [2 x i32]], align 16
@vis = external dso_local local_unnamed_addr global [100010 x i32], align 16
@check = external dso_local local_unnamed_addr global [100010 x i32], align 16
@ch = external dso_local global [100010 x i8], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5printi(i32 noundef %0) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %36, %1
  %.tr = phi i32 [ %0, %1 ], [ %29, %36 ]
  %2 = load i32, ptr @n, align 4
  %3 = icmp eq i32 %2, %.tr
  br i1 %3, label %4, label %6

4:                                                ; preds = %tailrecurse
  %5 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @ch, i64 1))
  tail call void @exit(i32 noundef 0) #3
  unreachable

6:                                                ; preds = %tailrecurse
  %7 = sext i32 %.tr to i64
  %8 = getelementptr inbounds [100010 x i32], ptr @vis, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %.preheader.preheader, label %15

.preheader.preheader:                             ; preds = %6
  %10 = getelementptr inbounds [100010 x [2 x i32]], ptr @Next, i64 0, i64 %7, i64 0
  %11 = load i32, ptr %10, align 8, !tbaa !5
  %12 = add nsw i32 %11, %.tr
  %13 = icmp slt i32 %12, 1
  %14 = icmp slt i32 %2, %12
  %or.cond = or i1 %13, %14
  br i1 %or.cond, label %.preheader.1, label %17

15:                                               ; preds = %6
  %16 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str)
  tail call void @exit(i32 noundef 0) #3
  unreachable

17:                                               ; preds = %.preheader.preheader
  %18 = zext nneg i32 %12 to i64
  %19 = getelementptr inbounds [100010 x i32], ptr @check, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %.not14 = icmp eq i32 %20, 0
  br i1 %.not14, label %.preheader.1, label %21

21:                                               ; preds = %17
  %22 = load i32, ptr @tot, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @tot, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100010 x i8], ptr @ch, i64 0, i64 %24
  store i8 97, ptr %25, align 1, !tbaa !9
  tail call void @_Z5printi(i32 noundef %12)
  %.pre = load i32, ptr @n, align 4
  br label %.preheader.1

.preheader.1:                                     ; preds = %17, %21, %.preheader.preheader
  %26 = phi i32 [ %2, %17 ], [ %.pre, %21 ], [ %2, %.preheader.preheader ]
  %27 = getelementptr inbounds [100010 x [2 x i32]], ptr @Next, i64 0, i64 %7, i64 1
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add nsw i32 %28, %.tr
  %30 = icmp slt i32 %29, 1
  %31 = icmp slt i32 %26, %29
  %or.cond.1 = select i1 %30, i1 true, i1 %31
  br i1 %or.cond.1, label %41, label %32

32:                                               ; preds = %.preheader.1
  %33 = zext nneg i32 %29 to i64
  %34 = getelementptr inbounds [100010 x i32], ptr @check, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %.not14.1 = icmp eq i32 %35, 0
  br i1 %.not14.1, label %41, label %36

36:                                               ; preds = %32
  %37 = load i32, ptr @tot, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr @tot, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100010 x i8], ptr @ch, i64 0, i64 %39
  store i8 98, ptr %40, align 1, !tbaa !9
  br label %tailrecurse

41:                                               ; preds = %32, %.preheader.1
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

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 = { nofree nounwind "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 = { noreturn nounwind "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 = { noreturn 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 = !{!7, !7, i64 0}


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