; LLVM IR from tangjz/acm-icpc :: 51nod/1164.ll (Z4findii)

; 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"

@r = external dso_local global [5001 x i32], align 16
@b = external dso_local global [5001 x i32], align 16
@match = external dso_local global [5001 x i32], align 16
@fail = external dso_local global [5001 x i8], align 16

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

9:                                                ; preds = %74, %2
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [5001 x i32], ptr @b, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [5001 x i32], ptr @r, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp sle i32 %13, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %9
  store i32 2, ptr %7, align 4
  br label %77

20:                                               ; preds = %9
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [5001 x i32], ptr @match, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp eq i32 %24, -1
  br i1 %25, label %26, label %31

26:                                               ; preds = %20
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [5001 x i32], ptr @match, i64 0, i64 %29
  store i32 %27, ptr %30, align 4, !tbaa !5
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %77

31:                                               ; preds = %20
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [5001 x i32], ptr @r, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [5001 x i32], ptr @match, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [5001 x i32], ptr @r, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = icmp slt i32 %35, %42
  br i1 %43, label %44, label %73

44:                                               ; preds = %31
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [5001 x i32], ptr @match, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [5001 x i8], ptr @fail, i64 0, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !9, !range !11, !noundef !12
  %52 = trunc i8 %51 to i1
  br i1 %52, label %73, label %53

53:                                               ; preds = %44
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [5001 x i32], ptr @match, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = call noundef zeroext i1 @_Z4findii(i32 noundef %57, i32 noundef %59)
  br i1 %60, label %61, label %66

61:                                               ; preds = %53
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [5001 x i32], ptr @match, i64 0, i64 %64
  store i32 %62, ptr %65, align 4, !tbaa !5
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %77

66:                                               ; preds = %53
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [5001 x i32], ptr @match, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [5001 x i8], ptr @fail, i64 0, i64 %71
  store i8 1, ptr %72, align 1, !tbaa !9
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %77

73:                                               ; preds = %44, %31
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %6, align 4, !tbaa !5
  br label %9, !llvm.loop !13

77:                                               ; preds = %66, %61, %26, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %78 = load i32, ptr %7, align 4
  switch i32 %78, label %82 [
    i32 2, label %79
    i32 1, label %80
  ]

79:                                               ; preds = %77
  store i1 false, ptr %3, align 1
  br label %80

80:                                               ; preds = %79, %77
  %81 = load i1, ptr %3, align 1
  ret i1 %81

82:                                               ; preds = %77
  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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@r = external dso_local local_unnamed_addr global [5001 x i32], align 16
@b = external dso_local local_unnamed_addr global [5001 x i32], align 16
@match = external dso_local local_unnamed_addr global [5001 x i32], align 16
@fail = external dso_local local_unnamed_addr global [5001 x i8], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z4findii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [5001 x i32], ptr @r, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds [5001 x i32], ptr @b, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not29.not = icmp sgt i32 %8, %5
  br i1 %.not29.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2, %33
  %indvars.iv = phi i64 [ %indvars.iv.next, %33 ], [ %6, %2 ]
  %9 = getelementptr inbounds [5001 x i32], ptr @match, i64 0, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp eq i32 %10, -1
  br i1 %11, label %12, label %14

12:                                               ; preds = %.lr.ph
  %13 = getelementptr inbounds [5001 x i32], ptr @match, i64 0, i64 %indvars.iv
  store i32 %0, ptr %13, align 4, !tbaa !5
  br label %.loopexit

14:                                               ; preds = %.lr.ph
  %15 = sext i32 %10 to i64
  %16 = getelementptr inbounds [5001 x i32], ptr @r, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp slt i32 %5, %17
  br i1 %18, label %19, label %33

19:                                               ; preds = %14
  %20 = getelementptr inbounds [5001 x i8], ptr @fail, i64 0, i64 %15
  %21 = load i8, ptr %20, align 1, !tbaa !9, !range !11, !noundef !12
  %22 = trunc nuw i8 %21 to i1
  br i1 %22, label %33, label %23

23:                                               ; preds = %19
  %24 = getelementptr inbounds [5001 x i32], ptr @match, i64 0, i64 %indvars.iv
  %25 = trunc nsw i64 %indvars.iv to i32
  %26 = add nsw i32 %25, 1
  %27 = tail call noundef zeroext i1 @_Z4findii(i32 noundef %10, i32 noundef %26)
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i32 %0, ptr %24, align 4, !tbaa !5
  br label %.loopexit

29:                                               ; preds = %23
  %30 = load i32, ptr %24, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [5001 x i8], ptr @fail, i64 0, i64 %31
  store i8 1, ptr %32, align 1, !tbaa !9
  br label %.loopexit

33:                                               ; preds = %14, %19
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %34 = getelementptr inbounds [5001 x i32], ptr @b, i64 0, i64 %indvars.iv.next
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %.not.not = icmp sgt i32 %35, %5
  br i1 %.not.not, label %.loopexit, label %.lr.ph, !llvm.loop !13

.loopexit:                                        ; preds = %33, %2, %29, %28, %12
  %.not22 = phi i1 [ true, %12 ], [ true, %28 ], [ true, %29 ], [ false, %2 ], [ false, %33 ]
  %.017 = phi i1 [ true, %12 ], [ true, %28 ], [ false, %29 ], [ undef, %2 ], [ undef, %33 ]
  %spec.select = and i1 %.not22, %.017
  ret i1 %spec.select
}

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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass