; LLVM IR from tangjz/acm-icpc :: hdu/5259.ll (Z4costiii)

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

@pos = external dso_local global [24 x [4 x i32]], align 16
@seq = external dso_local global [5010 x [4 x [2 x i32]]], 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 nounwind uwtable
define dso_local noundef i32 @_Z4costiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %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
  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) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %79, %3
  %10 = load i32, ptr %8, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 4
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %82

13:                                               ; preds = %9
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [5010 x [4 x [2 x i32]]], ptr @seq, i64 0, i64 %15
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [24 x [4 x i32]], ptr @pos, i64 0, i64 %18
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [4 x i32], ptr %19, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [4 x [2 x i32]], ptr %16, i64 0, i64 %24
  %26 = getelementptr inbounds [2 x i32], ptr %25, i64 0, i64 0
  %27 = load i32, ptr %26, align 8, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sub nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [5010 x [4 x [2 x i32]]], ptr @seq, i64 0, i64 %30
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [24 x [4 x i32]], ptr @pos, i64 0, i64 %33
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [4 x i32], ptr %34, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [4 x [2 x i32]], ptr %31, i64 0, i64 %39
  %41 = getelementptr inbounds [2 x i32], ptr %40, i64 0, i64 0
  %42 = load i32, ptr %41, align 8, !tbaa !5
  %43 = sub nsw i32 %27, %42
  %44 = call i32 @llvm.abs.i32(i32 %43, i1 true)
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [5010 x [4 x [2 x i32]]], ptr @seq, i64 0, i64 %46
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [24 x [4 x i32]], ptr @pos, i64 0, i64 %49
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [4 x i32], ptr %50, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [4 x [2 x i32]], ptr %47, i64 0, i64 %55
  %57 = getelementptr inbounds [2 x i32], ptr %56, i64 0, i64 1
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = sub nsw i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [5010 x [4 x [2 x i32]]], ptr @seq, i64 0, i64 %61
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [24 x [4 x i32]], ptr @pos, i64 0, i64 %64
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [4 x i32], ptr %65, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [4 x [2 x i32]], ptr %62, i64 0, i64 %70
  %72 = getelementptr inbounds [2 x i32], ptr %71, i64 0, i64 1
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = sub nsw i32 %58, %73
  %75 = call i32 @llvm.abs.i32(i32 %74, i1 true)
  %76 = add nsw i32 %44, %75
  %77 = load i32, ptr %7, align 4, !tbaa !5
  %78 = add nsw i32 %77, %76
  store i32 %78, ptr %7, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %13
  %80 = load i32, ptr %8, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %8, align 4, !tbaa !5
  br label %9, !llvm.loop !9

82:                                               ; preds = %12
  %83 = load i32, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %83
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, 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 nosync nounwind speculatable willreturn memory(none) }
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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@pos = external dso_local local_unnamed_addr global [24 x [4 x i32]], align 16
@seq = external dso_local local_unnamed_addr global [5010 x [4 x [2 x i32]]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 0, -2147483648) i32 @_Z4costiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = sext i32 %1 to i64
  %6 = add nsw i32 %0, -1
  %7 = sext i32 %6 to i64
  %8 = sext i32 %2 to i64
  %9 = getelementptr inbounds [24 x [4 x i32]], ptr @pos, i64 0, i64 %5, i64 0
  %10 = load i32, ptr %9, align 16, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [5010 x [4 x [2 x i32]]], ptr @seq, i64 0, i64 %4, i64 %11
  %13 = getelementptr inbounds [24 x [4 x i32]], ptr @pos, i64 0, i64 %8, i64 0
  %14 = load i32, ptr %13, align 16, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [5010 x [4 x [2 x i32]]], ptr @seq, i64 0, i64 %7, i64 %15
  %17 = load <2 x i32>, ptr %12, align 8, !tbaa !5
  %18 = load <2 x i32>, ptr %16, align 8, !tbaa !5
  %19 = getelementptr inbounds [24 x [4 x i32]], ptr @pos, i64 0, i64 %5, i64 1
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [5010 x [4 x [2 x i32]]], ptr @seq, i64 0, i64 %4, i64 %21
  %23 = getelementptr inbounds [24 x [4 x i32]], ptr @pos, i64 0, i64 %8, i64 1
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [5010 x [4 x [2 x i32]]], ptr @seq, i64 0, i64 %7, i64 %25
  %27 = load <2 x i32>, ptr %22, align 8, !tbaa !5
  %28 = load <2 x i32>, ptr %26, align 8, !tbaa !5
  %29 = sub nsw <2 x i32> %17, %18
  %30 = sub nsw <2 x i32> %27, %28
  %31 = shufflevector <2 x i32> %29, <2 x i32> %30, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  %32 = tail call <4 x i32> @llvm.abs.v4i32(<4 x i32> %31, i1 true)
  %33 = getelementptr inbounds [24 x [4 x i32]], ptr @pos, i64 0, i64 %5, i64 2
  %34 = load i32, ptr %33, align 8, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [5010 x [4 x [2 x i32]]], ptr @seq, i64 0, i64 %4, i64 %35
  %37 = getelementptr inbounds [24 x [4 x i32]], ptr @pos, i64 0, i64 %8, i64 2
  %38 = load i32, ptr %37, align 8, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [5010 x [4 x [2 x i32]]], ptr @seq, i64 0, i64 %7, i64 %39
  %41 = load <2 x i32>, ptr %36, align 8, !tbaa !5
  %42 = load <2 x i32>, ptr %40, align 8, !tbaa !5
  %43 = getelementptr inbounds [24 x [4 x i32]], ptr @pos, i64 0, i64 %5, i64 3
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [5010 x [4 x [2 x i32]]], ptr @seq, i64 0, i64 %4, i64 %45
  %47 = getelementptr inbounds [24 x [4 x i32]], ptr @pos, i64 0, i64 %8, i64 3
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [5010 x [4 x [2 x i32]]], ptr @seq, i64 0, i64 %7, i64 %49
  %51 = load <2 x i32>, ptr %46, align 8, !tbaa !5
  %52 = load <2 x i32>, ptr %50, align 8, !tbaa !5
  %53 = sub nsw <2 x i32> %41, %42
  %54 = sub nsw <2 x i32> %51, %52
  %55 = shufflevector <2 x i32> %53, <2 x i32> %54, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  %56 = tail call <4 x i32> @llvm.abs.v4i32(<4 x i32> %55, i1 true)
  %57 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %32)
  %58 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %56)
  %op.rdx = add i32 %57, %58
  ret i32 %op.rdx
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.abs.v4i32(<4 x i32>, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: 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)"}
!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,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass