; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2015-16/Jan 2016/Gold/lightsout.ll (Z3sgnSt4pairIiiES0_S0_)

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

@.str.3 = external hidden unnamed_addr constant [113 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [7 x i8], align 1
@__PRETTY_FUNCTION__._Z3sgnSt4pairIiiES0_S0_ = external hidden unnamed_addr constant [20 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3sgnSt4pairIiiES0_S0_(i64 %0, i64 %1, i64 %2) #2 {
  %4 = alloca %"struct.std::pair", align 4
  %5 = alloca %"struct.std::pair", align 4
  %6 = alloca %"struct.std::pair", align 4
  %7 = alloca i64, align 8
  store i64 %0, ptr %4, align 4
  store i64 %1, ptr %5, align 4
  store i64 %2, ptr %6, align 4
  %8 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 0
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = getelementptr inbounds %"struct.std::pair", ptr %4, i32 0, i32 0
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sub nsw i32 %11, %9
  store i32 %12, ptr %10, align 4, !tbaa !5
  %13 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !10
  %15 = getelementptr inbounds %"struct.std::pair", ptr %4, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !10
  %17 = sub nsw i32 %16, %14
  store i32 %17, ptr %15, align 4, !tbaa !10
  %18 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 0
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds %"struct.std::pair", ptr %6, i32 0, i32 0
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sub nsw i32 %21, %19
  store i32 %22, ptr %20, align 4, !tbaa !5
  %23 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !10
  %25 = getelementptr inbounds %"struct.std::pair", ptr %6, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !10
  %27 = sub nsw i32 %26, %24
  store i32 %27, ptr %25, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %28 = getelementptr inbounds %"struct.std::pair", ptr %4, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %"struct.std::pair", ptr %6, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !10
  %33 = sext i32 %32 to i64
  %34 = mul nsw i64 %30, %33
  %35 = getelementptr inbounds %"struct.std::pair", ptr %4, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !10
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds %"struct.std::pair", ptr %6, i32 0, i32 0
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = mul nsw i64 %37, %40
  %42 = sub nsw i64 %34, %41
  store i64 %42, ptr %7, align 8, !tbaa !11
  %43 = load i64, ptr %7, align 8, !tbaa !11
  %44 = icmp ne i64 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %3
  br label %48

46:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.18, ptr noundef @.str.3, i32 noundef 150, ptr noundef @__PRETTY_FUNCTION__._Z3sgnSt4pairIiiES0_S0_) #4
  unreachable

47:                                               ; No predecessors!
  br label %48

48:                                               ; preds = %47, %45
  %49 = load i64, ptr %7, align 8, !tbaa !11
  %50 = icmp sgt i64 %49, 0
  %51 = zext i1 %50 to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i32 %51
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 = { 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 #3 = { nounwind }
attributes #4 = { noreturn 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 = !{!12, !12, i64 0}
!12 = !{!"long long", !8, 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"

@.str.3 = external hidden unnamed_addr constant [113 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [7 x i8], align 1
@__PRETTY_FUNCTION__._Z3sgnSt4pairIiiES0_S0_ = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z3sgnSt4pairIiiES0_S0_(i64 %0, i64 %1, i64 %2) local_unnamed_addr #1 {
  %.sroa.3.0.extract.shift = and i64 %1, -4294967296
  %4 = sub i64 %0, %1
  %5 = sub i64 %2, %1
  %sext = shl i64 %4, 32
  %6 = ashr exact i64 %sext, 32
  %.sroa.4.0.extract.shift12 = sub i64 %2, %.sroa.3.0.extract.shift
  %7 = ashr i64 %.sroa.4.0.extract.shift12, 32
  %8 = mul nsw i64 %6, %7
  %.sroa.49.0.extract.shift14 = sub i64 %0, %.sroa.3.0.extract.shift
  %9 = ashr i64 %.sroa.49.0.extract.shift14, 32
  %sext15 = shl i64 %5, 32
  %10 = ashr exact i64 %sext15, 32
  %11 = mul nsw i64 %10, %9
  %.not = icmp eq i64 %8, %11
  br i1 %.not, label %12, label %13

12:                                               ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.3, i32 noundef 150, ptr noundef nonnull @__PRETTY_FUNCTION__._Z3sgnSt4pairIiiES0_S0_) #2
  unreachable

13:                                               ; preds = %3
  %14 = icmp sgt i64 %8, %11
  %15 = zext i1 %14 to i32
  ret i32 %15
}

attributes #0 = { noreturn nounwind "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 = { 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 = { noreturn 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)"}


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