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

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

@tot = external dso_local global i32, align 4
@que = external dso_local global [200002 x i32], align 16
@cnt = external dso_local global [200002 x i32], align 16
@sum = external dso_local global [200002 x i64], align 16
@ans = external dso_local global i64, align 8

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7bit_sumIiET_PS0_i(ptr noundef, i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7bit_sumIxET_PS0_i(ptr noundef, i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7bit_addIiEvPT_ii(ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7bit_addIxEvPT_ii(ptr noundef, i32 noundef, i32 noundef) #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3subi(i32 noundef %0) #3 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %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
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %11 = load i32, ptr @tot, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i32, ptr @que, i64 %12
  %14 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @que, ptr noundef %13, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %15 = ptrtoint ptr %14 to i64
  %16 = sub i64 %15, ptrtoint (ptr @que to i64)
  %17 = sdiv exact i64 %16, 4
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = call noundef i32 @_Z7bit_sumIiET_PS0_i(ptr noundef @cnt, i32 noundef %19)
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  %23 = call noundef i32 @_Z7bit_sumIiET_PS0_i(ptr noundef @cnt, i32 noundef %22)
  %24 = sub nsw i32 %20, %23
  store i32 %24, ptr %5, align 4, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %64

28:                                               ; preds = %1
  %29 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z7bit_addIiEvPT_ii(ptr noundef @cnt, i32 noundef %29, i32 noundef -1)
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sub nsw i32 0, %31
  call void @_Z7bit_addIxEvPT_ii(ptr noundef @sum, i32 noundef %30, i32 noundef %32)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = call noundef i32 @_Z7bit_sumIiET_PS0_i(ptr noundef @cnt, i32 noundef %33)
  store i32 %34, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %35 = load i32, ptr @tot, align 4, !tbaa !5
  %36 = sub nsw i32 %35, 1
  %37 = call noundef i32 @_Z7bit_sumIiET_PS0_i(ptr noundef @cnt, i32 noundef %36)
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sub nsw i32 %37, %38
  store i32 %39, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = call noundef i64 @_Z7bit_sumIxET_PS0_i(ptr noundef @sum, i32 noundef %40)
  store i64 %41, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %42 = load i32, ptr @tot, align 4, !tbaa !5
  %43 = sub nsw i32 %42, 1
  %44 = call noundef i64 @_Z7bit_sumIxET_PS0_i(ptr noundef @sum, i32 noundef %43)
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = sub nsw i64 %44, %45
  store i64 %46, ptr %10, align 8, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = mul nsw i64 %48, %50
  %52 = load i64, ptr %9, align 8, !tbaa !9
  %53 = sub nsw i64 %51, %52
  %54 = load i64, ptr %10, align 8, !tbaa !9
  %55 = add nsw i64 %53, %54
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = mul nsw i64 %57, %59
  %61 = sub nsw i64 %55, %60
  %62 = load i64, ptr @ans, align 8, !tbaa !9
  %63 = sub nsw i64 %62, %61
  store i64 %63, ptr @ans, align 8, !tbaa !9
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %64

64:                                               ; preds = %28, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %65 = load i1, ptr %2, align 1
  ret i1 %65
}

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

@tot = external dso_local local_unnamed_addr global i32, align 4
@que = external dso_local global [200002 x i32], align 16
@cnt = external dso_local global [200002 x i32], align 16
@sum = external dso_local global [200002 x i64], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7bit_sumIiET_PS0_i(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7bit_sumIxET_PS0_i(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7bit_addIiEvPT_ii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7bit_addIxEvPT_ii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3subi(i32 noundef %0) local_unnamed_addr #2 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr @tot, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds i32, ptr @que, i64 %4
  %6 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @que, ptr noundef nonnull %5, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %7 = ptrtoint ptr %6 to i64
  %8 = sub i64 %7, ptrtoint (ptr @que to i64)
  %9 = lshr exact i64 %8, 2
  %10 = trunc i64 %9 to i32
  %11 = call noundef i32 @_Z7bit_sumIiET_PS0_i(ptr noundef nonnull @cnt, i32 noundef %10)
  %12 = add nsw i32 %10, -1
  %13 = call noundef i32 @_Z7bit_sumIiET_PS0_i(ptr noundef nonnull @cnt, i32 noundef %12)
  %.not = icmp ne i32 %11, %13
  br i1 %.not, label %14, label %33

14:                                               ; preds = %1
  call void @_Z7bit_addIiEvPT_ii(ptr noundef nonnull @cnt, i32 noundef %10, i32 noundef -1)
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sub nsw i32 0, %15
  call void @_Z7bit_addIxEvPT_ii(ptr noundef nonnull @sum, i32 noundef %10, i32 noundef %16)
  %17 = call noundef i32 @_Z7bit_sumIiET_PS0_i(ptr noundef nonnull @cnt, i32 noundef %10)
  %18 = load i32, ptr @tot, align 4, !tbaa !5
  %19 = add nsw i32 %18, -1
  %20 = call noundef i32 @_Z7bit_sumIiET_PS0_i(ptr noundef nonnull @cnt, i32 noundef %19)
  %21 = sub nsw i32 %20, %17
  %22 = call noundef i64 @_Z7bit_sumIxET_PS0_i(ptr noundef nonnull @sum, i32 noundef %10)
  %23 = load i32, ptr @tot, align 4, !tbaa !5
  %24 = add nsw i32 %23, -1
  %25 = call noundef i64 @_Z7bit_sumIxET_PS0_i(ptr noundef nonnull @sum, i32 noundef %24)
  %26 = sext i32 %17 to i64
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = sext i32 %21 to i64
  %reass.add = shl i64 %22, 1
  %30 = load i64, ptr @ans, align 8, !tbaa !9
  %reass.add16 = sub nsw i64 %29, %26
  %reass.mul = mul nsw i64 %reass.add16, %28
  %31 = sub i64 %reass.add, %25
  %.neg = add i64 %31, %30
  %32 = add i64 %.neg, %reass.mul
  store i64 %32, ptr @ans, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %1, %14
  ret i1 %.not
}

attributes #0 = { inlinehint 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 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 = { 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" }

!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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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