; LLVM IR from kazunetakahashi/atcoder :: 2017/1107_ARC076/E.ll (Z5scoreii)

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

@R = external dso_local global i32, align 4
@C = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__PRETTY_FUNCTION__._Z5scoreii = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6onedgeii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5scoreii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = load i32, ptr %5, align 4, !tbaa !5
  %8 = call noundef zeroext i1 @_Z6onedgeii(i32 noundef %6, i32 noundef %7)
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  br label %12

10:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 43, ptr noundef @__PRETTY_FUNCTION__._Z5scoreii) #2
  unreachable

11:                                               ; No predecessors!
  br label %12

12:                                               ; preds = %11, %9
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %12
  %16 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %16, ptr %3, align 4
  br label %47

17:                                               ; preds = %12
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = load i32, ptr @R, align 4, !tbaa !5
  %20 = icmp eq i32 %18, %19
  br i1 %20, label %21, label %25

21:                                               ; preds = %17
  %22 = load i32, ptr @R, align 4, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = add nsw i32 %22, %23
  store i32 %24, ptr %3, align 4
  br label %47

25:                                               ; preds = %17
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = load i32, ptr @C, align 4, !tbaa !5
  %28 = icmp eq i32 %26, %27
  br i1 %28, label %29, label %37

29:                                               ; preds = %25
  %30 = load i32, ptr @R, align 4, !tbaa !5
  %31 = load i32, ptr @C, align 4, !tbaa !5
  %32 = add nsw i32 %30, %31
  %33 = load i32, ptr @R, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sub nsw i32 %33, %34
  %36 = add nsw i32 %32, %35
  store i32 %36, ptr %3, align 4
  br label %47

37:                                               ; preds = %25
  %38 = load i32, ptr @R, align 4, !tbaa !5
  %39 = load i32, ptr @C, align 4, !tbaa !5
  %40 = add nsw i32 %38, %39
  %41 = load i32, ptr @R, align 4, !tbaa !5
  %42 = add nsw i32 %40, %41
  %43 = load i32, ptr @C, align 4, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sub nsw i32 %43, %44
  %46 = add nsw i32 %42, %45
  store i32 %46, ptr %3, align 4
  br label %47

47:                                               ; preds = %37, %29, %21, %15
  %48 = load i32, ptr %3, align 4
  ret i32 %48
}

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

attributes #0 = { 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 #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 = { 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, !6, i64 0}
!6 = !{!"int", !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"

@R = external dso_local local_unnamed_addr global i32, align 4
@C = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__PRETTY_FUNCTION__._Z5scoreii = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6onedgeii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5scoreii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef zeroext i1 @_Z6onedgeii(i32 noundef %0, i32 noundef %1)
  br i1 %3, label %5, label %4

4:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 43, ptr noundef nonnull @__PRETTY_FUNCTION__._Z5scoreii) #2
  unreachable

5:                                                ; preds = %2
  %6 = icmp eq i32 %1, 0
  br i1 %6, label %20, label %7

7:                                                ; preds = %5
  %8 = load i32, ptr @R, align 4, !tbaa !5
  %9 = icmp eq i32 %8, %0
  br i1 %9, label %10, label %12

10:                                               ; preds = %7
  %11 = add nsw i32 %0, %1
  br label %20

12:                                               ; preds = %7
  %13 = load i32, ptr @C, align 4, !tbaa !5
  %14 = icmp eq i32 %13, %1
  br i1 %14, label %15, label %18

15:                                               ; preds = %12
  %factor = shl i32 %8, 1
  %16 = sub i32 %factor, %0
  %17 = add i32 %16, %1
  br label %20

18:                                               ; preds = %12
  %reass.add15 = add i32 %13, %8
  %reass.mul = shl i32 %reass.add15, 1
  %19 = sub i32 %reass.mul, %1
  br label %20

20:                                               ; preds = %5, %18, %15, %10
  %.0 = phi i32 [ %11, %10 ], [ %17, %15 ], [ %19, %18 ], [ %0, %5 ]
  ret i32 %.0
}

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

attributes #0 = { 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 #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 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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