; LLVM IR from abeaumont/competitive-programming :: aceptaelreto/104.ll (Z5checkv)

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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5checkv() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %10 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %23, label %13

13:                                               ; preds = %0
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %23, label %16

16:                                               ; preds = %13
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %23, label %19

19:                                               ; preds = %16
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  store i64 -2, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %53

23:                                               ; preds = %19, %16, %13, %0
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %28, label %26

26:                                               ; preds = %23
  %27 = call noundef i64 @_Z5checkv()
  store i64 %27, ptr %2, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %26, %23
  %29 = load i64, ptr %4, align 8, !tbaa !5
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %33, label %31

31:                                               ; preds = %28
  %32 = call noundef i64 @_Z5checkv()
  store i64 %32, ptr %4, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %31, %28
  %34 = load i64, ptr %2, align 8, !tbaa !5
  %35 = icmp slt i64 %34, 0
  br i1 %35, label %39, label %36

36:                                               ; preds = %33
  %37 = load i64, ptr %4, align 8, !tbaa !5
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %36, %33
  store i64 -1, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %53

40:                                               ; preds = %36
  %41 = load i64, ptr %2, align 8, !tbaa !5
  %42 = load i64, ptr %3, align 8, !tbaa !5
  %43 = mul nsw i64 %41, %42
  %44 = load i64, ptr %4, align 8, !tbaa !5
  %45 = load i64, ptr %5, align 8, !tbaa !5
  %46 = mul nsw i64 %44, %45
  %47 = icmp ne i64 %43, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %40
  store i64 -1, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %53

49:                                               ; preds = %40
  %50 = load i64, ptr %2, align 8, !tbaa !5
  %51 = load i64, ptr %4, align 8, !tbaa !5
  %52 = add nsw i64 %50, %51
  store i64 %52, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %53

53:                                               ; preds = %49, %48, %39, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  %54 = load i64, ptr %1, align 8
  ret i64 %54
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; 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 = !{!"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"

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i64 -2, -9223372036854775808) i64 @_Z5checkv() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  %5 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %9 = load i64, ptr %1, align 8, !tbaa !5
  %10 = icmp ne i64 %9, 0
  %11 = load i64, ptr %2, align 8
  %12 = icmp ne i64 %11, 0
  %or.cond = select i1 %10, i1 true, i1 %12
  %13 = load i64, ptr %3, align 8
  %14 = icmp ne i64 %13, 0
  %or.cond3 = select i1 %or.cond, i1 true, i1 %14
  %15 = load i64, ptr %4, align 8
  %16 = icmp ne i64 %15, 0
  %or.cond5 = select i1 %or.cond3, i1 true, i1 %16
  br i1 %or.cond5, label %17, label %35

17:                                               ; preds = %0
  br i1 %10, label %20, label %18

18:                                               ; preds = %17
  %19 = call noundef i64 @_Z5checkv()
  store i64 %19, ptr %1, align 8, !tbaa !5
  %.pre = load i64, ptr %3, align 8
  br label %20

20:                                               ; preds = %18, %17
  %21 = phi i64 [ %19, %18 ], [ %9, %17 ]
  %22 = phi i64 [ %.pre, %18 ], [ %13, %17 ]
  %.not = icmp eq i64 %22, 0
  br i1 %.not, label %23, label %25

23:                                               ; preds = %20
  %24 = call noundef i64 @_Z5checkv()
  %.pre11 = load i64, ptr %1, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %23, %20
  %26 = phi i64 [ %24, %23 ], [ %22, %20 ]
  %27 = phi i64 [ %.pre11, %23 ], [ %21, %20 ]
  %28 = or i64 %27, %26
  %or.cond7.not = icmp sgt i64 %28, -1
  br i1 %or.cond7.not, label %29, label %35

29:                                               ; preds = %25
  %30 = load i64, ptr %2, align 8, !tbaa !5
  %31 = mul nsw i64 %30, %27
  %32 = load i64, ptr %4, align 8, !tbaa !5
  %33 = mul nsw i64 %32, %26
  %.not10 = icmp eq i64 %31, %33
  %34 = add nuw nsw i64 %26, %27
  %spec.select = select i1 %.not10, i64 %34, i64 -1
  br label %35

35:                                               ; preds = %29, %25, %0
  %.0 = phi i64 [ -2, %0 ], [ -1, %25 ], [ %spec.select, %29 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #2
  ret i64 %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress 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 = { mustprogress 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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