; LLVM IR from tangjz/acm-icpc :: 51nod/1386.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"

%struct.Edge = type { i32, i32 }

@pre = external dso_local global [1001 x i32], align 16
@match = external dso_local global [1001 x i32], align 16
@vis = external dso_local global [1001 x i8], align 16
@e = external dso_local global [2002 x %struct.Edge], 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
define dso_local noundef zeroext i1 @_Z4pathi(i32 noundef %0) #1 {
  %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
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [1001 x i32], ptr @pre, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %9, ptr %4, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %62, %1
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp ne i32 %11, -1
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  store i32 2, ptr %5, align 4
  br label %68

14:                                               ; preds = %10
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [2002 x %struct.Edge], ptr @e, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.Edge, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1001 x i8], ptr @vis, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11, !range !13, !noundef !14
  %23 = trunc i8 %22 to i1
  br i1 %23, label %61, label %24

24:                                               ; preds = %14
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [2002 x %struct.Edge], ptr @e, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.Edge, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1001 x i8], ptr @vis, i64 0, i64 %30
  store i8 1, ptr %31, align 1, !tbaa !11
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [2002 x %struct.Edge], ptr @e, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.Edge, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1001 x i32], ptr @match, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = icmp eq i32 %39, -1
  br i1 %40, label %51, label %41

41:                                               ; preds = %24
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [2002 x %struct.Edge], ptr @e, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.Edge, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1001 x i32], ptr @match, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = call noundef zeroext i1 @_Z4pathi(i32 noundef %49)
  br i1 %50, label %51, label %60

51:                                               ; preds = %41, %24
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [2002 x %struct.Edge], ptr @e, i64 0, i64 %54
  %56 = getelementptr inbounds %struct.Edge, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [1001 x i32], ptr @match, i64 0, i64 %58
  store i32 %52, ptr %59, align 4, !tbaa !5
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %68

60:                                               ; preds = %41
  br label %61

61:                                               ; preds = %60, %14
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [2002 x %struct.Edge], ptr @e, i64 0, i64 %64
  %66 = getelementptr inbounds %struct.Edge, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !15
  store i32 %67, ptr %4, align 4, !tbaa !5
  br label %10, !llvm.loop !16

68:                                               ; preds = %51, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %69 = load i32, ptr %5, align 4
  switch i32 %69, label %73 [
    i32 2, label %70
    i32 1, label %71
  ]

70:                                               ; preds = %68
  store i1 false, ptr %2, align 1
  br label %71

71:                                               ; preds = %70, %68
  %72 = load i1, ptr %2, align 1
  ret i1 %72

73:                                               ; preds = %68
  unreachable
}

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, !6, i64 4}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!10, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%struct.Edge = type { i32, i32 }

@pre = external dso_local local_unnamed_addr global [1001 x i32], align 16
@match = external dso_local local_unnamed_addr global [1001 x i32], align 16
@vis = external dso_local local_unnamed_addr global [1001 x i8], align 16
@e = external dso_local local_unnamed_addr global [2002 x %struct.Edge], 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 [1001 x i32], ptr @pre, i64 0, i64 %2
  %.01016 = load i32, ptr %3, align 4, !tbaa !5
  %.not17.not = icmp eq i32 %.01016, -1
  br i1 %.not17.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %1, %20
  %.01018 = phi i32 [ %.010, %20 ], [ %.01016, %1 ]
  %4 = sext i32 %.01018 to i64
  %5 = getelementptr inbounds [2002 x %struct.Edge], ptr @e, i64 0, i64 %4
  %6 = getelementptr inbounds i8, ptr %5, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !9
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [1001 x i8], ptr @vis, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !11, !range !13, !noundef !14
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %20, label %12

12:                                               ; preds = %.lr.ph
  store i8 1, ptr %9, align 1, !tbaa !11
  %13 = getelementptr inbounds [1001 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 %split, label %16

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

._crit_edge:                                      ; preds = %16
  %18 = getelementptr inbounds i8, ptr %5, i64 4
  %.pre = load i32, ptr %18, align 4, !tbaa !9
  %.pre22 = sext i32 %.pre to i64
  br label %split

split:                                            ; preds = %12, %._crit_edge
  %.pre-phi = phi i64 [ %.pre22, %._crit_edge ], [ %8, %12 ]
  %19 = getelementptr inbounds [1001 x i32], ptr @match, i64 0, i64 %.pre-phi
  store i32 %0, ptr %19, align 4, !tbaa !5
  br label %.loopexit

20:                                               ; preds = %.lr.ph, %16
  %.010 = load i32, ptr %5, align 8, !tbaa !5
  %.not.not = icmp eq i32 %.010, -1
  br i1 %.not.not, label %.loopexit, label %.lr.ph, !llvm.loop !15

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

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, !6, i64 4}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!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: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass