; LLVM IR from tangjz/acm-icpc :: 51nod/1399.ll (Z4calcxx)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z7sum_fibx(i64 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z8diff_fibx(i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4calcxx(i64 noundef %0, i64 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  %7 = load i64, ptr %4, align 8, !tbaa !5
  %8 = load i64, ptr %5, align 8, !tbaa !5
  %9 = icmp sle i64 %7, %8
  br i1 %9, label %10, label %20

10:                                               ; preds = %2
  %11 = load i64, ptr %4, align 8, !tbaa !5
  %12 = load i64, ptr %5, align 8, !tbaa !5
  %13 = icmp eq i64 %11, %12
  br i1 %13, label %14, label %17

14:                                               ; preds = %10
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = add nsw i64 %15, -1
  store i64 %16, ptr %4, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %14, %10
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = call noundef i32 @_Z7sum_fibx(i64 noundef %18)
  store i32 %19, ptr %3, align 4
  br label %52

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = sub nsw i64 %21, 1
  %23 = call noundef i32 @_Z8diff_fibx(i64 noundef %22)
  %24 = load i64, ptr %5, align 8, !tbaa !5
  %25 = shl i64 %24, 1
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = sub nsw i64 %25, %26
  %28 = sub nsw i64 %27, 1
  %29 = call noundef i32 @_Z8diff_fibx(i64 noundef %28)
  %30 = sub nsw i32 %23, %29
  store i32 %30, ptr %6, align 4, !tbaa !9
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %33, label %36

33:                                               ; preds = %20
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1000000007
  store i32 %35, ptr %6, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %33, %20
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = xor i64 %37, -1
  %39 = and i64 %38, 1
  %40 = icmp ne i64 %39, 0
  br i1 %40, label %41, label %47

41:                                               ; preds = %36
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %47

44:                                               ; preds = %41
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = sub nsw i32 1000000007, %45
  store i32 %46, ptr %6, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %44, %41, %36
  %48 = load i64, ptr %5, align 8, !tbaa !5
  %49 = sub nsw i64 %48, 1
  %50 = call noundef i32 @_Z7sum_fibx(i64 noundef %49)
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %50)
  %51 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %51, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %52

52:                                               ; preds = %47, %17
  %53 = load i32, ptr %3, align 4
  ret i32 %53
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, 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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z7sum_fibx(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z8diff_fibx(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4calcxx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #2 {
  %3 = alloca i32, align 4
  %.not = icmp sgt i64 %0, %1
  br i1 %.not, label %8, label %4

4:                                                ; preds = %2
  %5 = icmp eq i64 %0, %1
  %6 = sext i1 %5 to i64
  %spec.select = add nsw i64 %6, %0
  %7 = tail call noundef i32 @_Z7sum_fibx(i64 noundef %spec.select)
  br label %24

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %9 = add nsw i64 %1, -1
  %10 = tail call noundef i32 @_Z8diff_fibx(i64 noundef %9)
  %11 = shl i64 %1, 1
  %12 = xor i64 %0, -1
  %13 = add i64 %11, %12
  %14 = tail call noundef i32 @_Z8diff_fibx(i64 noundef %13)
  %15 = sub nsw i32 %10, %14
  %16 = icmp slt i32 %15, 0
  %17 = add nsw i32 %15, 1000000007
  %spec.select19 = select i1 %16, i32 %17, i32 %15
  %18 = and i64 %1, 1
  %19 = icmp eq i64 %18, 0
  %20 = icmp ne i32 %spec.select19, 0
  %or.cond = select i1 %19, i1 %20, i1 false
  %21 = sub nsw i32 1000000007, %spec.select19
  %storemerge18 = select i1 %or.cond, i32 %21, i32 %spec.select19
  store i32 %storemerge18, ptr %3, align 4, !tbaa !5
  %22 = tail call noundef i32 @_Z7sum_fibx(i64 noundef %9)
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %22)
  %23 = load i32, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %24

24:                                               ; preds = %8, %4
  %.0 = phi i32 [ %7, %4 ], [ %23, %8 ]
  ret i32 %.0
}

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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"}


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