; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd/278.ll (Z4findi)

; 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.Hash = type { i32, i32 }

@t = external dso_local global i32, align 4
@pre = external dso_local global [2333333 x i32], align 16
@tm = external dso_local global [2333333 x i32], align 16
@e = external dso_local global [1000001 x %struct.Hash], 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 nounwind uwtable
define dso_local noundef zeroext i1 @_Z4findi(i32 noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = srem i32 %7, 2333333
  store i32 %8, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %1
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = add nsw i32 %12, 2333333
  store i32 %13, ptr %4, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %11, %1
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [2333333 x i32], ptr @tm, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = load i32, ptr @t, align 4, !tbaa !5
  %20 = icmp ne i32 %18, %19
  br i1 %20, label %21, label %29

21:                                               ; preds = %14
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [2333333 x i32], ptr @pre, i64 0, i64 %23
  store i32 0, ptr %24, align 4, !tbaa !5
  %25 = load i32, ptr @t, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [2333333 x i32], ptr @tm, i64 0, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %21, %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2333333 x i32], ptr @pre, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr %5, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %48, %29
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  store i32 2, ptr %6, align 4
  br label %54

38:                                               ; preds = %34
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [1000001 x %struct.Hash], ptr @e, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.Hash, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = icmp eq i32 %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %38
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %54

47:                                               ; preds = %38
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1000001 x %struct.Hash], ptr @e, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.Hash, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !11
  store i32 %53, ptr %5, align 4, !tbaa !5
  br label %34, !llvm.loop !12

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

56:                                               ; preds = %54
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %57

57:                                               ; preds = %56, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %58 = load i1, ptr %2, align 1
  ret i1 %58
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind 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 = !{!"_ZTS4Hash", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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.Hash = type { i32, i32 }

@t = external dso_local local_unnamed_addr global i32, align 4
@pre = external dso_local local_unnamed_addr global [2333333 x i32], align 16
@tm = external dso_local local_unnamed_addr global [2333333 x i32], align 16
@e = external dso_local local_unnamed_addr global [1000001 x %struct.Hash], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z4findi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = srem i32 %0, 2333333
  %3 = icmp slt i32 %2, 0
  %4 = add nsw i32 %2, 2333333
  %spec.select = select i1 %3, i32 %4, i32 %2
  %5 = zext nneg i32 %spec.select to i64
  %6 = getelementptr inbounds [2333333 x i32], ptr @tm, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %7, %8
  br i1 %.not, label %11, label %9

9:                                                ; preds = %1
  %10 = getelementptr inbounds [2333333 x i32], ptr @pre, i64 0, i64 %5
  store i32 0, ptr %10, align 4, !tbaa !5
  store i32 %8, ptr %6, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %9, %1
  %12 = getelementptr inbounds [2333333 x i32], ptr @pre, i64 0, i64 %5
  br label %13

13:                                               ; preds = %14, %11
  %.012.in = phi ptr [ %12, %11 ], [ %16, %14 ]
  %.012 = load i32, ptr %.012.in, align 4, !tbaa !5
  %.not17.not = icmp ne i32 %.012, 0
  br i1 %.not17.not, label %14, label %.critedge

14:                                               ; preds = %13
  %15 = sext i32 %.012 to i64
  %16 = getelementptr inbounds [1000001 x %struct.Hash], ptr @e, i64 0, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = icmp eq i32 %18, %0
  br i1 %19, label %.critedge, label %13, !llvm.loop !11

.critedge:                                        ; preds = %13, %14
  ret i1 %.not17.not
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, 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 = !{!"_ZTS4Hash", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass