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

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

@fa = external dso_local global [50001 x i32], align 16
@dep = external dso_local global ptr, align 8
@top = external dso_local global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3lcaii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %39, %2
  %6 = load ptr, ptr @top, align 8, !tbaa !9
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds i32, ptr %6, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = load ptr, ptr @top, align 8, !tbaa !9
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i32, ptr %11, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp ne i32 %10, %15
  br i1 %16, label %17, label %48

17:                                               ; preds = %5
  %18 = load ptr, ptr @dep, align 8, !tbaa !9
  %19 = load ptr, ptr @top, align 8, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr %19, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i32, ptr %18, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = load ptr, ptr @dep, align 8, !tbaa !9
  %28 = load ptr, ptr @top, align 8, !tbaa !9
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %28, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr %27, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp slt i32 %26, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %17
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4) #2
  br label %38

38:                                               ; preds = %37, %17
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr @top, align 8, !tbaa !9
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %40, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [50001 x i32], ptr @fa, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  store i32 %47, ptr %3, align 4, !tbaa !5
  br label %5, !llvm.loop !11

48:                                               ; preds = %5
  %49 = load ptr, ptr @dep, align 8, !tbaa !9
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %49, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = load ptr, ptr @dep, align 8, !tbaa !9
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = icmp slt i32 %53, %58
  br i1 %59, label %60, label %62

60:                                               ; preds = %48
  %61 = load i32, ptr %3, align 4, !tbaa !5
  br label %64

62:                                               ; preds = %48
  %63 = load i32, ptr %4, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %62, %60
  %65 = phi i32 [ %61, %60 ], [ %63, %62 ]
  ret i32 %65
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

attributes #0 = { 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 #1 = { inlinehint 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@fa = external dso_local local_unnamed_addr global [50001 x i32], align 16
@dep = external dso_local local_unnamed_addr global ptr, align 8
@top = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3lcaii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = load ptr, ptr @top, align 8, !tbaa !9
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds i32, ptr %5, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = sext i32 %1 to i64
  %10 = getelementptr inbounds i32, ptr %5, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %.not5 = icmp eq i32 %8, %11
  %.pre17 = load ptr, ptr @dep, align 8, !tbaa !9
  br i1 %.not5, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %26
  %12 = phi i32 [ %27, %26 ], [ %1, %2 ]
  %13 = phi ptr [ %28, %26 ], [ %5, %2 ]
  %14 = phi i32 [ %36, %26 ], [ %0, %2 ]
  %15 = phi ptr [ %30, %26 ], [ %.pre17, %2 ]
  %16 = phi i32 [ %42, %26 ], [ %11, %2 ]
  %17 = phi i32 [ %39, %26 ], [ %8, %2 ]
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i32, ptr %15, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sext i32 %16 to i64
  %22 = getelementptr inbounds i32, ptr %15, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp slt i32 %20, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %.lr.ph
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4) #2
  %.pre = load ptr, ptr @dep, align 8, !tbaa !9
  %.pre14 = load ptr, ptr @top, align 8, !tbaa !9
  %.pre15 = load i32, ptr %3, align 4, !tbaa !5
  %.pre16 = load i32, ptr %4, align 4
  br label %26

26:                                               ; preds = %.lr.ph, %25
  %27 = phi i32 [ %12, %.lr.ph ], [ %.pre16, %25 ]
  %28 = phi ptr [ %13, %.lr.ph ], [ %.pre14, %25 ]
  %29 = phi i32 [ %14, %.lr.ph ], [ %.pre15, %25 ]
  %30 = phi ptr [ %15, %.lr.ph ], [ %.pre, %25 ]
  %31 = sext i32 %29 to i64
  %32 = getelementptr inbounds i32, ptr %28, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [50001 x i32], ptr @fa, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  store i32 %36, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %28, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sext i32 %27 to i64
  %41 = getelementptr inbounds i32, ptr %28, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %.not = icmp eq i32 %39, %42
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %26, %2
  %43 = phi ptr [ %.pre17, %2 ], [ %30, %26 ]
  %.lcssa4 = phi i32 [ %0, %2 ], [ %36, %26 ]
  %.lcssa3 = phi i64 [ %6, %2 ], [ %37, %26 ]
  %.lcssa2 = phi i32 [ %1, %2 ], [ %27, %26 ]
  %.lcssa = phi i64 [ %9, %2 ], [ %40, %26 ]
  %44 = getelementptr inbounds i32, ptr %43, i64 %.lcssa3
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = getelementptr inbounds i32, ptr %43, i64 %.lcssa
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = icmp slt i32 %45, %47
  %49 = select i1 %48, i32 %.lcssa4, i32 %.lcssa2
  ret i32 %49
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SimplifyCFGPass