; LLVM IR from tangjz/acm-icpc :: uvalive/7558.ll (Z4pathi)

; 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
@match = external dso_local global [201 x i32], align 16
@lim = external dso_local global i64, align 8
@dis = external dso_local global [201 x [201 x i64]], align 16
@vis = external dso_local global [201 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z4pathi(i32 noundef %0) #0 {
  %2 = alloca i1, align 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %49, %1
  %7 = load i32, ptr %4, 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
  store i32 2, ptr %5, align 4
  br label %52

11:                                               ; preds = %6
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [201 x [201 x i64]], ptr @dis, i64 0, i64 %13
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [201 x i64], ptr %14, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = load i64, ptr @lim, align 8, !tbaa !9
  %20 = icmp sgt i64 %18, %19
  br i1 %20, label %21, label %48

21:                                               ; preds = %11
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [201 x i8], ptr @vis, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11, !range !13, !noundef !14
  %26 = trunc i8 %25 to i1
  br i1 %26, label %48, label %27

27:                                               ; preds = %21
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [201 x i8], ptr @vis, i64 0, i64 %29
  store i8 1, ptr %30, align 1, !tbaa !11
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [201 x i32], ptr @match, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = icmp eq i32 %34, -1
  br i1 %35, label %42, label %36

36:                                               ; preds = %27
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [201 x i32], ptr @match, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = call noundef zeroext i1 @_Z4pathi(i32 noundef %40)
  br i1 %41, label %42, label %47

42:                                               ; preds = %36, %27
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [201 x i32], ptr @match, i64 0, i64 %45
  store i32 %43, ptr %46, align 4, !tbaa !5
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %52

47:                                               ; preds = %36
  br label %48

48:                                               ; preds = %47, %21, %11
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %4, align 4, !tbaa !5
  br label %6, !llvm.loop !15

52:                                               ; preds = %42, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %53 = load i32, ptr %5, align 4
  switch i32 %53, label %57 [
    i32 2, label %54
    i32 1, label %55
  ]

54:                                               ; preds = %52
  store i1 false, ptr %2, align 1
  br label %55

55:                                               ; preds = %54, %52
  %56 = load i1, ptr %2, align 1
  ret i1 %56

57:                                               ; preds = %52
  unreachable
}

; 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 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"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
@match = external dso_local local_unnamed_addr global [201 x i32], align 16
@lim = external dso_local local_unnamed_addr global i64, align 8
@dis = external dso_local local_unnamed_addr global [201 x [201 x i64]], align 16
@vis = external dso_local local_unnamed_addr global [201 x i8], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z4pathi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not17 = icmp sgt i32 %2, 0
  br i1 %.not17, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %1
  %3 = sext i32 %0 to i64
  %.pre22 = load i64, ptr @lim, align 8, !tbaa !9
  br label %4

4:                                                ; preds = %.lr.ph, %22
  %5 = phi i32 [ %2, %.lr.ph ], [ %23, %22 ]
  %6 = phi i64 [ %.pre22, %.lr.ph ], [ %24, %22 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %7 = getelementptr inbounds [201 x [201 x i64]], ptr @dis, i64 0, i64 %3, i64 %indvars.iv
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = icmp sgt i64 %8, %6
  br i1 %9, label %10, label %22

10:                                               ; preds = %4
  %11 = getelementptr inbounds [201 x i8], ptr @vis, i64 0, i64 %indvars.iv
  %12 = load i8, ptr %11, align 1, !tbaa !11, !range !13, !noundef !14
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %22, label %14

14:                                               ; preds = %10
  store i8 1, ptr %11, align 1, !tbaa !11
  %15 = getelementptr inbounds [201 x i32], ptr @match, i64 0, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %20, label %18

18:                                               ; preds = %14
  %19 = tail call noundef zeroext i1 @_Z4pathi(i32 noundef %16)
  br i1 %19, label %20, label %._crit_edge

._crit_edge:                                      ; preds = %18
  %.pre = load i64, ptr @lim, align 8, !tbaa !9
  %.pre23 = load i32, ptr @n, align 4, !tbaa !5
  br label %22

20:                                               ; preds = %18, %14
  %21 = getelementptr inbounds [201 x i32], ptr @match, i64 0, i64 %indvars.iv
  store i32 %0, ptr %21, align 4, !tbaa !5
  br label %.loopexit

22:                                               ; preds = %._crit_edge, %4, %10
  %23 = phi i32 [ %5, %4 ], [ %5, %10 ], [ %.pre23, %._crit_edge ]
  %24 = phi i64 [ %6, %4 ], [ %6, %10 ], [ %.pre, %._crit_edge ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = sext i32 %23 to i64
  %.not = icmp slt i64 %indvars.iv.next, %25
  br i1 %.not, label %4, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %22, %1, %20
  %.not15 = phi i1 [ true, %20 ], [ false, %1 ], [ false, %22 ]
  ret i1 %.not15
}

attributes #0 = { mustprogress nofree 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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