; LLVM IR from pranjalwalia/Competitive-programming :: implementations/dsu/problems/CityAndFloods.ll (Z5mergexx)

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

@p = external dso_local global [100005 x i64], align 16
@rnk = external dso_local global [100005 x i64], 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 noundef i64 @_Z4findx(i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5mergexx(i64 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = call noundef i64 @_Z4findx(i64 noundef %8)
  store i64 %9, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = call noundef i64 @_Z4findx(i64 noundef %10)
  store i64 %11, ptr %6, align 8, !tbaa !5
  %12 = load i64, ptr %5, align 8, !tbaa !5
  %13 = load i64, ptr %6, align 8, !tbaa !5
  %14 = icmp eq i64 %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i32 1, ptr %7, align 4
  br label %50

16:                                               ; preds = %2
  %17 = load i64, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = load i64, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = icmp sgt i64 %19, %22
  br i1 %23, label %24, label %30

24:                                               ; preds = %16
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds [100005 x i64], ptr @p, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = load i64, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds [100005 x i64], ptr @p, i64 0, i64 %28
  store i64 %27, ptr %29, align 8, !tbaa !5
  br label %36

30:                                               ; preds = %16
  %31 = load i64, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds [100005 x i64], ptr @p, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds [100005 x i64], ptr @p, i64 0, i64 %34
  store i64 %33, ptr %35, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %30, %24
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !5
  %40 = load i64, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = icmp eq i64 %39, %42
  br i1 %43, label %44, label %49

44:                                               ; preds = %36
  %45 = load i64, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !5
  %48 = add nsw i64 %47, 1
  store i64 %48, ptr %46, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %44, %36
  store i32 1, ptr %7, align 4
  br label %50

50:                                               ; preds = %49, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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

@p = external dso_local local_unnamed_addr global [100005 x i64], align 16
@rnk = external dso_local local_unnamed_addr global [100005 x i64], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4findx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5mergexx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef i64 @_Z4findx(i64 noundef %0)
  %4 = tail call noundef i64 @_Z4findx(i64 noundef %1)
  %5 = icmp eq i64 %3, %4
  br i1 %5, label %18, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %3
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %4
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = icmp sgt i64 %8, %10
  %. = select i1 %11, i64 %3, i64 %4
  %.18 = select i1 %11, i64 %4, i64 %3
  %12 = getelementptr inbounds [100005 x i64], ptr @p, i64 0, i64 %.
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds [100005 x i64], ptr @p, i64 0, i64 %.18
  store i64 %13, ptr %14, align 8, !tbaa !5
  %15 = icmp eq i64 %8, %10
  br i1 %15, label %16, label %18

16:                                               ; preds = %6
  %17 = add nsw i64 %8, 1
  store i64 %17, ptr %9, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %6, %16, %2
  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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass