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

@n = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@c = external dso_local global [20 x i32], align 16
@t = external dso_local global [20 x i32], 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
declare dso_local void @_Z5printv() #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4findi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp eq i32 %5, %6
  br i1 %7, label %8, label %28

8:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %24, %8
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr @b, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %27

14:                                               ; preds = %9
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [20 x i32], ptr @t, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = add nsw i32 %22, %18
  store i32 %23, ptr %21, align 4, !tbaa !5
  call void @_Z5printv()
  br label %24

24:                                               ; preds = %14
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %3, align 4, !tbaa !5
  br label %9, !llvm.loop !9

27:                                               ; preds = %13
  br label %67

28:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %63, %28
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr @b, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %66

34:                                               ; preds = %29
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  call void @_Z4findi(i32 noundef %36)
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [20 x i32], ptr @t, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = add nsw i32 %44, %40
  store i32 %45, ptr %43, align 4, !tbaa !5
  call void @_Z5printv()
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %59

51:                                               ; preds = %34
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = load i32, ptr @b, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 1
  %58 = icmp eq i32 %55, %57
  br i1 %58, label %59, label %62

59:                                               ; preds = %51, %34
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  call void @_Z4findi(i32 noundef %61)
  br label %62

62:                                               ; preds = %59, %51
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %4, align 4, !tbaa !5
  br label %29, !llvm.loop !11

66:                                               ; preds = %33
  br label %67

67:                                               ; preds = %66, %27
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [20 x i32], ptr @t, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = mul nsw i32 %71, -1
  store i32 %72, ptr %70, align 4, !tbaa !5
  ret void
}

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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@b = external dso_local local_unnamed_addr global i32, align 4
@c = external dso_local local_unnamed_addr global [20 x i32], align 16
@t = external dso_local local_unnamed_addr global [20 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5printv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4findi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp eq i32 %2, %0
  %4 = load i32, ptr @b, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 1
  br i1 %3, label %.preheader, label %.preheader15

.preheader15:                                     ; preds = %1
  br i1 %5, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader15
  %6 = add nsw i32 %0, 1
  %7 = sext i32 %0 to i64
  %8 = getelementptr inbounds [20 x i32], ptr @t, i64 0, i64 %7
  %9 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %7
  br label %20

.preheader:                                       ; preds = %1
  br i1 %5, label %.lr.ph19, label %.loopexit

.lr.ph19:                                         ; preds = %.preheader, %.lr.ph19
  %.01218 = phi i32 [ %17, %.lr.ph19 ], [ 1, %.preheader ]
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [20 x i32], ptr @t, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %11
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %15, %13
  store i32 %16, ptr %14, align 4, !tbaa !5
  tail call void @_Z5printv()
  %17 = add nuw nsw i32 %.01218, 1
  %18 = load i32, ptr @b, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %.lr.ph19, label %.loopexit, !llvm.loop !9

20:                                               ; preds = %.lr.ph, %30
  %.017 = phi i32 [ 1, %.lr.ph ], [ %32, %30 ]
  tail call void @_Z4findi(i32 noundef %6)
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = load i32, ptr %9, align 4, !tbaa !5
  %23 = add nsw i32 %22, %21
  store i32 %23, ptr %9, align 4, !tbaa !5
  tail call void @_Z5printv()
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %29, label %25

25:                                               ; preds = %20
  %26 = load i32, ptr @b, align 4, !tbaa !5
  %27 = add nsw i32 %26, -1
  %28 = icmp eq i32 %24, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %25, %20
  tail call void @_Z4findi(i32 noundef %6)
  %.pre = load i32, ptr @b, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %25, %29
  %31 = phi i32 [ %26, %25 ], [ %.pre, %29 ]
  %32 = add nuw nsw i32 %.017, 1
  %33 = icmp slt i32 %32, %31
  br i1 %33, label %20, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %30, %.lr.ph19, %.preheader15, %.preheader
  %34 = sext i32 %0 to i64
  %35 = getelementptr inbounds [20 x i32], ptr @t, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sub nsw i32 0, %36
  store i32 %37, ptr %35, align 4, !tbaa !5
  ret void
}

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass