; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/ASC/1/Problem F/test.ll (Z7getPathii)

; 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
@c = external dso_local global [333 x i32], align 16
@used = external dso_local global [333 x i8], align 16
@m = external dso_local global i32, align 4
@p = external dso_local global [333 x i32], 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 uwtable
declare dso_local void @_Z3dfsi(i32 noundef) #1

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

6:                                                ; preds = %18, %2
  %7 = load i32, ptr %5, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %6
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [333 x i8], ptr @used, i64 0, i64 %13
  store i8 0, ptr %14, align 1, !tbaa !9
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [333 x i32], ptr @p, i64 0, i64 %16
  store i32 -1, ptr %17, align 4, !tbaa !5
  br label %18

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

21:                                               ; preds = %10
  %22 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3dfsi(i32 noundef %22)
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [333 x i32], ptr @p, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp eq i32 %26, -1
  br i1 %27, label %28, label %29

28:                                               ; preds = %21
  br label %50

29:                                               ; preds = %21
  store i32 0, ptr @m, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %34, %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = icmp ne i32 %31, %32
  br i1 %33, label %34, label %44

34:                                               ; preds = %30
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = load i32, ptr @m, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr @m, align 4, !tbaa !5
  %38 = sext i32 %36 to i64
  %39 = getelementptr inbounds [333 x i32], ptr @c, i64 0, i64 %38
  store i32 %35, ptr %39, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [333 x i32], ptr @p, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  store i32 %43, ptr %4, align 4, !tbaa !5
  br label %30, !llvm.loop !13

44:                                               ; preds = %30
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = load i32, ptr @m, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr @m, align 4, !tbaa !5
  %48 = sext i32 %46 to i64
  %49 = getelementptr inbounds [333 x i32], ptr @c, i64 0, i64 %48
  store i32 %45, ptr %49, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %44, %28
  ret void
}

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


; 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
@c = external dso_local local_unnamed_addr global [333 x i32], align 16
@used = external dso_local local_unnamed_addr global [333 x i8], align 16
@m = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global [333 x i32], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7getPathii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %8

.lr.ph:                                           ; preds = %2
  %5 = sext i32 %0 to i64
  %6 = zext nneg i32 %3 to i64
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @used, i8 0, i64 %6, i1 false), !tbaa !9
  %7 = getelementptr inbounds [333 x i32], ptr @p, i64 0, i64 %5
  store i32 -1, ptr %7, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %.lr.ph, %2
  tail call void @_Z3dfsi(i32 noundef %0)
  %9 = sext i32 %1 to i64
  %10 = getelementptr inbounds [333 x i32], ptr @p, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp eq i32 %11, -1
  br i1 %12, label %24, label %13

13:                                               ; preds = %8
  %.not14 = icmp eq i32 %1, %0
  br i1 %.not14, label %19, label %.lr.ph17

.lr.ph17:                                         ; preds = %13, %.lr.ph17
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph17 ], [ 0, %13 ]
  %.01115 = phi i32 [ %17, %.lr.ph17 ], [ %1, %13 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = getelementptr inbounds [333 x i32], ptr @c, i64 0, i64 %indvars.iv
  store i32 %.01115, ptr %14, align 4, !tbaa !5
  %15 = sext i32 %.01115 to i64
  %16 = getelementptr inbounds [333 x i32], ptr @p, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %.not = icmp eq i32 %17, %0
  br i1 %.not, label %._crit_edge18, label %.lr.ph17, !llvm.loop !11

._crit_edge18:                                    ; preds = %.lr.ph17
  %18 = trunc nuw i64 %indvars.iv.next to i32
  br label %19

19:                                               ; preds = %._crit_edge18, %13
  %20 = phi i32 [ %18, %._crit_edge18 ], [ 0, %13 ]
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @m, align 4, !tbaa !5
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [333 x i32], ptr @c, i64 0, i64 %22
  store i32 %0, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %8, %19
  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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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