; LLVM IR from eyangch/competitive-programming :: USACOcontests/gold/2021.03/permutations.ll (Z5v_trixxxx)

; 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 { i64, i64 }

@pt = external dso_local global [40 x %"struct.std::pair"], align 16

; 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) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z6in_triSt4pairIxxES0_S0_S0_(i64, i64, i64, i64, i64, i64, ptr noundef byval(%"struct.std::pair") align 8) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5v_trixxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca %"struct.std::pair", align 8
  %11 = alloca %"struct.std::pair", align 8
  %12 = alloca %"struct.std::pair", align 8
  %13 = alloca %"struct.std::pair", align 8
  %14 = alloca %"struct.std::pair", align 8
  %15 = alloca %"struct.std::pair", align 8
  %16 = alloca %"struct.std::pair", align 8
  %17 = alloca %"struct.std::pair", align 8
  %18 = alloca %"struct.std::pair", align 8
  %19 = alloca %"struct.std::pair", align 8
  %20 = alloca %"struct.std::pair", align 8
  %21 = alloca %"struct.std::pair", align 8
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !5
  %22 = load i64, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %22
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 16 %23, i64 16, i1 false)
  %24 = load i64, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %24
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 16 %25, i64 16, i1 false)
  %26 = load i64, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %26
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 16 %27, i64 16, i1 false)
  %28 = load i64, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %28
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %13, ptr align 16 %29, i64 16, i1 false)
  %30 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 0
  %31 = load i64, ptr %30, align 8
  %32 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 1
  %33 = load i64, ptr %32, align 8
  %34 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %35 = load i64, ptr %34, align 8
  %36 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %37 = load i64, ptr %36, align 8
  %38 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 0
  %39 = load i64, ptr %38, align 8
  %40 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 1
  %41 = load i64, ptr %40, align 8
  %42 = call noundef zeroext i1 @_Z6in_triSt4pairIxxES0_S0_S0_(i64 %31, i64 %33, i64 %35, i64 %37, i64 %39, i64 %41, ptr noundef byval(%"struct.std::pair") align 8 %13)
  br i1 %42, label %43, label %44

43:                                               ; preds = %4
  store i64 0, ptr %5, align 8
  br label %91

44:                                               ; preds = %4
  %45 = load i64, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %45
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %14, ptr align 16 %46, i64 16, i1 false)
  %47 = load i64, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %47
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %15, ptr align 16 %48, i64 16, i1 false)
  %49 = load i64, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %49
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %16, ptr align 16 %50, i64 16, i1 false)
  %51 = load i64, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %51
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %17, ptr align 16 %52, i64 16, i1 false)
  %53 = getelementptr inbounds { i64, i64 }, ptr %14, i32 0, i32 0
  %54 = load i64, ptr %53, align 8
  %55 = getelementptr inbounds { i64, i64 }, ptr %14, i32 0, i32 1
  %56 = load i64, ptr %55, align 8
  %57 = getelementptr inbounds { i64, i64 }, ptr %15, i32 0, i32 0
  %58 = load i64, ptr %57, align 8
  %59 = getelementptr inbounds { i64, i64 }, ptr %15, i32 0, i32 1
  %60 = load i64, ptr %59, align 8
  %61 = getelementptr inbounds { i64, i64 }, ptr %16, i32 0, i32 0
  %62 = load i64, ptr %61, align 8
  %63 = getelementptr inbounds { i64, i64 }, ptr %16, i32 0, i32 1
  %64 = load i64, ptr %63, align 8
  %65 = call noundef zeroext i1 @_Z6in_triSt4pairIxxES0_S0_S0_(i64 %54, i64 %56, i64 %58, i64 %60, i64 %62, i64 %64, ptr noundef byval(%"struct.std::pair") align 8 %17)
  br i1 %65, label %66, label %67

66:                                               ; preds = %44
  store i64 1, ptr %5, align 8
  br label %91

67:                                               ; preds = %44
  %68 = load i64, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %68
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %18, ptr align 16 %69, i64 16, i1 false)
  %70 = load i64, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %70
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %19, ptr align 16 %71, i64 16, i1 false)
  %72 = load i64, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %72
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %20, ptr align 16 %73, i64 16, i1 false)
  %74 = load i64, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %74
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %21, ptr align 16 %75, i64 16, i1 false)
  %76 = getelementptr inbounds { i64, i64 }, ptr %18, i32 0, i32 0
  %77 = load i64, ptr %76, align 8
  %78 = getelementptr inbounds { i64, i64 }, ptr %18, i32 0, i32 1
  %79 = load i64, ptr %78, align 8
  %80 = getelementptr inbounds { i64, i64 }, ptr %19, i32 0, i32 0
  %81 = load i64, ptr %80, align 8
  %82 = getelementptr inbounds { i64, i64 }, ptr %19, i32 0, i32 1
  %83 = load i64, ptr %82, align 8
  %84 = getelementptr inbounds { i64, i64 }, ptr %20, i32 0, i32 0
  %85 = load i64, ptr %84, align 8
  %86 = getelementptr inbounds { i64, i64 }, ptr %20, i32 0, i32 1
  %87 = load i64, ptr %86, align 8
  %88 = call noundef zeroext i1 @_Z6in_triSt4pairIxxES0_S0_S0_(i64 %77, i64 %79, i64 %81, i64 %83, i64 %85, i64 %87, ptr noundef byval(%"struct.std::pair") align 8 %21)
  br i1 %88, label %89, label %90

89:                                               ; preds = %67
  store i64 2, ptr %5, align 8
  br label %91

90:                                               ; preds = %67
  store i64 -1, ptr %5, align 8
  br label %91

91:                                               ; preds = %90, %89, %66, %43
  %92 = load i64, ptr %5, align 8
  ret i64 %92
}

attributes #0 = { nocallback nofree 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" }

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

%"struct.std::pair" = type { i64, i64 }

@pt = external dso_local local_unnamed_addr global [40 x %"struct.std::pair"], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z6in_triSt4pairIxxES0_S0_S0_(i64, i64, i64, i64, i64, i64, ptr noundef byval(%"struct.std::pair") align 8) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i64 -1, 3) i64 @_Z5v_trixxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %1
  %.sroa.015.0.copyload = load i64, ptr %5, align 16
  %.sroa.216.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 8
  %.sroa.216.0.copyload = load i64, ptr %.sroa.216.0..sroa_idx, align 8
  %6 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %0
  %.sroa.013.0.copyload = load i64, ptr %6, align 16
  %.sroa.214.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 8
  %.sroa.214.0.copyload = load i64, ptr %.sroa.214.0..sroa_idx, align 8
  %7 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %2
  %.sroa.011.0.copyload = load i64, ptr %7, align 16
  %.sroa.212.0..sroa_idx = getelementptr inbounds i8, ptr %7, i64 8
  %.sroa.212.0.copyload = load i64, ptr %.sroa.212.0..sroa_idx, align 8
  %8 = getelementptr inbounds [40 x %"struct.std::pair"], ptr @pt, i64 0, i64 %3
  %9 = tail call noundef zeroext i1 @_Z6in_triSt4pairIxxES0_S0_S0_(i64 %.sroa.015.0.copyload, i64 %.sroa.216.0.copyload, i64 %.sroa.013.0.copyload, i64 %.sroa.214.0.copyload, i64 %.sroa.011.0.copyload, i64 %.sroa.212.0.copyload, ptr noundef nonnull byval(%"struct.std::pair") align 8 %8)
  br i1 %9, label %14, label %10

10:                                               ; preds = %4
  %.sroa.09.0.copyload = load i64, ptr %7, align 16
  %.sroa.210.0.copyload = load i64, ptr %.sroa.212.0..sroa_idx, align 8
  %.sroa.07.0.copyload = load i64, ptr %5, align 16
  %.sroa.28.0.copyload = load i64, ptr %.sroa.216.0..sroa_idx, align 8
  %.sroa.05.0.copyload = load i64, ptr %6, align 16
  %.sroa.26.0.copyload = load i64, ptr %.sroa.214.0..sroa_idx, align 8
  %11 = tail call noundef zeroext i1 @_Z6in_triSt4pairIxxES0_S0_S0_(i64 %.sroa.09.0.copyload, i64 %.sroa.210.0.copyload, i64 %.sroa.07.0.copyload, i64 %.sroa.28.0.copyload, i64 %.sroa.05.0.copyload, i64 %.sroa.26.0.copyload, ptr noundef nonnull byval(%"struct.std::pair") align 8 %8)
  br i1 %11, label %14, label %12

12:                                               ; preds = %10
  %.sroa.03.0.copyload = load i64, ptr %8, align 16
  %.sroa.24.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 8
  %.sroa.24.0.copyload = load i64, ptr %.sroa.24.0..sroa_idx, align 8
  %.sroa.01.0.copyload = load i64, ptr %5, align 16
  %.sroa.22.0.copyload = load i64, ptr %.sroa.216.0..sroa_idx, align 8
  %.sroa.0.0.copyload = load i64, ptr %7, align 16
  %.sroa.2.0.copyload = load i64, ptr %.sroa.212.0..sroa_idx, align 8
  %13 = tail call noundef zeroext i1 @_Z6in_triSt4pairIxxES0_S0_S0_(i64 %.sroa.03.0.copyload, i64 %.sroa.24.0.copyload, i64 %.sroa.01.0.copyload, i64 %.sroa.22.0.copyload, i64 %.sroa.0.0.copyload, i64 %.sroa.2.0.copyload, ptr noundef nonnull byval(%"struct.std::pair") align 8 %6)
  %. = select i1 %13, i64 2, i64 -1
  br label %14

14:                                               ; preds = %12, %10, %4
  %.0 = phi i64 [ 0, %4 ], [ 1, %10 ], [ %., %12 ]
  ret i64 %.0
}

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass