; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Company Contests/Sears 2016/Problem F/F.ll (Z5mergeiii)

; 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 [200100 x [50 x i32]], align 16
@rnk = external dso_local global [200100 x [50 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4findii(i32 noundef, i32 noundef) #0

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

19:                                               ; preds = %3
  store i32 1, ptr %9, align 4
  br label %84

20:                                               ; preds = %3
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [200100 x [50 x i32]], ptr @rnk, i64 0, i64 %22
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [50 x i32], ptr %23, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [200100 x [50 x i32]], ptr @rnk, i64 0, i64 %29
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [50 x i32], ptr %30, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = icmp sgt i32 %27, %34
  br i1 %35, label %36, label %44

36:                                               ; preds = %20
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [200100 x [50 x i32]], ptr @p, i64 0, i64 %39
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [50 x i32], ptr %40, i64 0, i64 %42
  store i32 %37, ptr %43, align 4, !tbaa !5
  br label %52

44:                                               ; preds = %20
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [200100 x [50 x i32]], ptr @p, i64 0, i64 %47
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [50 x i32], ptr %48, i64 0, i64 %50
  store i32 %45, ptr %51, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %44, %36
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [200100 x [50 x i32]], ptr @rnk, i64 0, i64 %54
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [50 x i32], ptr %55, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [200100 x [50 x i32]], ptr @rnk, i64 0, i64 %61
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [50 x i32], ptr %62, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = icmp eq i32 %59, %66
  br i1 %67, label %68, label %83

68:                                               ; preds = %52
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [200100 x [50 x i32]], ptr @rnk, i64 0, i64 %70
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [50 x i32], ptr %71, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [200100 x [50 x i32]], ptr @rnk, i64 0, i64 %78
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [50 x i32], ptr %79, i64 0, i64 %81
  store i32 %76, ptr %82, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %68, %52
  store i32 1, ptr %9, align 4
  br label %84

84:                                               ; preds = %83, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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


; 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 [200100 x [50 x i32]], align 16
@rnk = external dso_local local_unnamed_addr global [200100 x [50 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4findii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5mergeiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call noundef i32 @_Z4findii(i32 noundef %0, i32 noundef %2)
  %5 = tail call noundef i32 @_Z4findii(i32 noundef %1, i32 noundef %2)
  %6 = icmp eq i32 %4, %5
  br i1 %6, label %20, label %7

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

18:                                               ; preds = %7
  %19 = add nsw i32 %11, 1
  store i32 %19, ptr %13, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %7, %18, %3
  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"}


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