; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-11-15/H - Those are not the droids you're looking for - tjz.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 [1010 x [1010 x i32]], align 16
@match = external dso_local global [1010 x i32], align 16
@vis = external dso_local global [1010 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 [1010 x [1010 x i32]], ptr @e, i64 0, i64 %10
  %12 = getelementptr inbounds [1010 x i32], ptr %11, i64 0, i64 0
  %13 = load i32, ptr %12, align 8, !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 [1010 x [1010 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 [1010 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 [1010 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 %29, label %30

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

30:                                               ; preds = %16
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1010 x i8], ptr @vis, i64 0, i64 %33
  store i8 1, ptr %34, align 1, !tbaa !11
  %35 = load ptr, ptr %6, align 8, !tbaa !9
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1010 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 %48, label %41

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

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

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

55:                                               ; preds = %54, %48, %29
  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
    i32 4, label %58
  ]

57:                                               ; preds = %55
  br label %58

58:                                               ; preds = %57, %55
  %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 [1010 x [1010 x i32]], align 16
@match = external dso_local local_unnamed_addr global [1010 x i32], align 16
@vis = external dso_local local_unnamed_addr global [1010 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 [1010 x [1010 x i32]], ptr @e, i64 0, i64 %2
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not20 = icmp sgt i32 %4, 0
  br i1 %.not20, 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 [1010 x [1010 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 [1010 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 [1010 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 %._crit_edge25

._crit_edge25:                                    ; preds = %16
  %.pre26 = load i32, ptr %3, align 8, !tbaa !5
  br label %19

._crit_edge:                                      ; preds = %16
  %.pre = load i32, ptr %6, align 4, !tbaa !5
  %.pre27 = sext i32 %.pre to i64
  br label %split

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

19:                                               ; preds = %._crit_edge25, %.lr.ph
  %20 = phi i32 [ %.pre26, %._crit_edge25 ], [ %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, %split
  %.not19 = phi i1 [ true, %split ], [ false, %1 ], [ false, %19 ]
  ret i1 %.not19
}

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