; LLVM IR from DionysiosB/CodeForces :: 0001-0099/2B-TheLeastRoundWay.ll (Z8bestPairSt4pairIiiES0_)

; 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.std::pair" = type { i32, i32 }

; 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 i64 @_Z8bestPairSt4pairIiiES0_(i64 %0, i64 %1) #1 {
  %3 = alloca %"struct.std::pair", align 4
  %4 = alloca %"struct.std::pair", align 4
  %5 = alloca %"struct.std::pair", align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i64 %0, ptr %4, align 4
  store i64 %1, ptr %5, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %11 = getelementptr inbounds %"struct.std::pair", ptr %4, i32 0, i32 0
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = getelementptr inbounds %"struct.std::pair", ptr %4, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !10
  %15 = icmp slt i32 %12, %14
  br i1 %15, label %16, label %19

16:                                               ; preds = %2
  %17 = getelementptr inbounds %"struct.std::pair", ptr %4, i32 0, i32 0
  %18 = load i32, ptr %17, align 4, !tbaa !5
  br label %22

19:                                               ; preds = %2
  %20 = getelementptr inbounds %"struct.std::pair", ptr %4, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !10
  br label %22

22:                                               ; preds = %19, %16
  %23 = phi i32 [ %18, %16 ], [ %21, %19 ]
  store i32 %23, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %24 = getelementptr inbounds %"struct.std::pair", ptr %4, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = getelementptr inbounds %"struct.std::pair", ptr %4, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !10
  %28 = icmp slt i32 %25, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %22
  %30 = getelementptr inbounds %"struct.std::pair", ptr %4, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !10
  br label %35

32:                                               ; preds = %22
  %33 = getelementptr inbounds %"struct.std::pair", ptr %4, i32 0, i32 0
  %34 = load i32, ptr %33, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %32, %29
  %36 = phi i32 [ %31, %29 ], [ %34, %32 ]
  store i32 %36, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %37 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 0
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !10
  %41 = icmp slt i32 %38, %40
  br i1 %41, label %42, label %45

42:                                               ; preds = %35
  %43 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !5
  br label %48

45:                                               ; preds = %35
  %46 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !10
  br label %48

48:                                               ; preds = %45, %42
  %49 = phi i32 [ %44, %42 ], [ %47, %45 ]
  store i32 %49, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %50 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 0
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !10
  %54 = icmp slt i32 %51, %53
  br i1 %54, label %55, label %58

55:                                               ; preds = %48
  %56 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !10
  br label %61

58:                                               ; preds = %48
  %59 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 0
  %60 = load i32, ptr %59, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %58, %55
  %62 = phi i32 [ %57, %55 ], [ %60, %58 ]
  store i32 %62, ptr %9, align 4, !tbaa !11
  %63 = load i32, ptr %6, align 4, !tbaa !11
  %64 = load i32, ptr %8, align 4, !tbaa !11
  %65 = icmp slt i32 %63, %64
  br i1 %65, label %74, label %66

66:                                               ; preds = %61
  %67 = load i32, ptr %6, align 4, !tbaa !11
  %68 = load i32, ptr %8, align 4, !tbaa !11
  %69 = icmp eq i32 %67, %68
  br i1 %69, label %70, label %75

70:                                               ; preds = %66
  %71 = load i32, ptr %7, align 4, !tbaa !11
  %72 = load i32, ptr %9, align 4, !tbaa !11
  %73 = icmp slt i32 %71, %72
  br i1 %73, label %74, label %75

74:                                               ; preds = %70, %61
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %4, i64 8, i1 false)
  store i32 1, ptr %10, align 4
  br label %76

75:                                               ; preds = %70, %66
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %5, i64 8, i1 false)
  store i32 1, ptr %10, align 4
  br label %76

76:                                               ; preds = %75, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %77 = load i64, ptr %3, align 4
  ret i64 %77
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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, !7, i64 0}
!6 = !{!"_ZTSSt4pairIiiE", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!7, !7, i64 0}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local i64 @_Z8bestPairSt4pairIiiES0_(i64 %0, i64 %1) local_unnamed_addr #0 {
  %.sroa.012.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.616.0.extract.shift = lshr i64 %0, 32
  %.sroa.616.0.extract.trunc = trunc nuw i64 %.sroa.616.0.extract.shift to i32
  %.sroa.0.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.6.0.extract.shift = lshr i64 %1, 32
  %.sroa.6.0.extract.trunc = trunc nuw i64 %.sroa.6.0.extract.shift to i32
  %3 = tail call i32 @llvm.smin.i32(i32 %.sroa.012.0.extract.trunc, i32 %.sroa.616.0.extract.trunc)
  %4 = tail call i32 @llvm.smin.i32(i32 %.sroa.0.0.extract.trunc, i32 %.sroa.6.0.extract.trunc)
  %5 = icmp slt i32 %3, %4
  br i1 %5, label %11, label %6

6:                                                ; preds = %2
  %7 = tail call i32 @llvm.smax.i32(i32 %.sroa.0.0.extract.trunc, i32 %.sroa.6.0.extract.trunc)
  %8 = tail call i32 @llvm.smax.i32(i32 %.sroa.012.0.extract.trunc, i32 %.sroa.616.0.extract.trunc)
  %9 = icmp eq i32 %3, %4
  %10 = icmp slt i32 %8, %7
  %or.cond = and i1 %9, %10
  %spec.select = select i1 %or.cond, i64 %0, i64 %1
  %spec.select22 = select i1 %or.cond, i64 %.sroa.616.0.extract.shift, i64 %.sroa.6.0.extract.shift
  br label %11

11:                                               ; preds = %6, %2
  %.sroa.020.0 = phi i64 [ %0, %2 ], [ %spec.select, %6 ]
  %.sroa.3.0 = phi i64 [ %.sroa.616.0.extract.shift, %2 ], [ %spec.select22, %6 ]
  %.sroa.3.0.insert.shift = shl nuw i64 %.sroa.3.0, 32
  %.sroa.020.0.insert.ext = and i64 %.sroa.020.0, 4294967295
  %.sroa.020.0.insert.insert = or disjoint i64 %.sroa.3.0.insert.shift, %.sroa.020.0.insert.ext
  ret i64 %.sroa.020.0.insert.insert
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass