; LLVM IR from tangjz/acm-icpc :: uvalive/5874.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"

@e = external dso_local global [404 x [404 x i32]], align 16
@match = external dso_local global [404 x i32], align 16
@vis = external dso_local global [404 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
  %6 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %58, %1
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [404 x [404 x i32]], ptr @e, i64 0, i64 %10
  %12 = getelementptr inbounds [404 x i32], ptr %11, i64 0, i64 0
  %13 = load i32, ptr %12, align 16, !tbaa !5
  %14 = icmp sle i32 %8, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %7
  store i32 2, ptr %5, align 4
  br label %61

16:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [404 x [404 x i32]], ptr @e, i64 0, i64 %18
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [404 x i32], ptr %19, i64 0, i64 %21
  store ptr %22, ptr %6, align 8, !tbaa !9
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [404 x i8], ptr @vis, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !11, !range !13, !noundef !14
  %28 = trunc i8 %27 to i1
  br i1 %28, label %54, label %29

29:                                               ; preds = %16
  %30 = load ptr, ptr %6, align 8, !tbaa !9
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [404 x i8], ptr @vis, i64 0, i64 %32
  store i8 1, ptr %33, align 1, !tbaa !11
  %34 = load ptr, ptr %6, align 8, !tbaa !9
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [404 x i32], ptr @match, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp eq i32 %38, -1
  br i1 %39, label %47, label %40

40:                                               ; preds = %29
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [404 x i32], ptr @match, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = call noundef zeroext i1 @_Z4pathi(i32 noundef %45)
  br i1 %46, label %47, label %53

47:                                               ; preds = %40, %29
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !9
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [404 x i32], ptr @match, i64 0, i64 %51
  store i32 %48, ptr %52, align 4, !tbaa !5
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %55

53:                                               ; preds = %40
  br label %54

54:                                               ; preds = %53, %16
  store i32 0, ptr %5, align 4
  br label %55

55:                                               ; preds = %54, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %56 = load i32, ptr %5, align 4
  switch i32 %56, label %61 [
    i32 0, label %57
  ]

57:                                               ; preds = %55
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %4, align 4, !tbaa !5
  br label %7, !llvm.loop !15

61:                                               ; preds = %55, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %62 = load i32, ptr %5, align 4
  switch i32 %62, label %66 [
    i32 2, label %63
    i32 1, label %64
  ]

63:                                               ; preds = %61
  store i1 false, ptr %2, align 1
  br label %64

64:                                               ; preds = %63, %61
  %65 = load i1, ptr %2, align 1
  ret i1 %65

66:                                               ; preds = %61
  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 = !{!"any pointer", !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"

@e = external dso_local local_unnamed_addr global [404 x [404 x i32]], align 16
@match = external dso_local local_unnamed_addr global [404 x i32], align 16
@vis = external dso_local local_unnamed_addr global [404 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 = sext i32 %0 to i64
  %3 = getelementptr inbounds [404 x [404 x i32]], ptr @e, i64 0, i64 %2
  %4 = load i32, ptr %3, align 16, !tbaa !5
  %.not19 = icmp sgt i32 %4, 0
  br i1 %.not19, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %1, %19
  %5 = phi i32 [ %20, %19 ], [ %4, %1 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %19 ], [ 1, %1 ]
  %6 = getelementptr inbounds [404 x [404 x i32]], ptr @e, i64 0, i64 %2, i64 %indvars.iv
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [404 x i8], ptr @vis, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !9, !range !11, !noundef !12
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %19, label %12

12:                                               ; preds = %.lr.ph
  store i8 1, ptr %9, align 1, !tbaa !9
  %13 = getelementptr inbounds [404 x i32], ptr @match, i64 0, i64 %8
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp eq i32 %14, -1
  br i1 %15, label %.critedge, label %16

16:                                               ; preds = %12
  %17 = tail call noundef zeroext i1 @_Z4pathi(i32 noundef %14)
  br i1 %17, label %..critedge_crit_edge, label %._crit_edge

._crit_edge:                                      ; preds = %16
  %.pre24 = load i32, ptr %3, align 16, !tbaa !5
  br label %19

..critedge_crit_edge:                             ; preds = %16
  %.pre = load i32, ptr %6, align 4, !tbaa !5
  %.pre25 = sext i32 %.pre to i64
  br label %.critedge

.critedge:                                        ; preds = %12, %..critedge_crit_edge
  %.pre-phi = phi i64 [ %.pre25, %..critedge_crit_edge ], [ %8, %12 ]
  %18 = getelementptr inbounds [404 x i32], ptr @match, i64 0, i64 %.pre-phi
  store i32 %0, ptr %18, align 4, !tbaa !5
  br label %.loopexit

19:                                               ; preds = %._crit_edge, %.lr.ph
  %20 = phi i32 [ %.pre24, %._crit_edge ], [ %5, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = sext i32 %20 to i64
  %.not = icmp slt i64 %indvars.iv, %21
  br i1 %.not, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %19, %1, %.critedge
  %.not18 = phi i1 [ true, %.critedge ], [ false, %1 ], [ false, %19 ]
  ret i1 %.not18
}

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


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