; LLVM IR from tangjz/acm-icpc :: poj (1845)

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

@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 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: mustprogress uwtable
declare dso_local noundef i32 @_Z3sumix(i32 noundef, i64 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @a, ptr noundef @b)
  store i32 1, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %45, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = mul nsw i64 %7, %9
  %11 = load i32, ptr @a, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = icmp sle i64 %10, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %48

15:                                               ; preds = %5
  %16 = load i32, ptr @a, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = srem i32 %16, %17
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %44

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %26, %20
  %22 = load i32, ptr @a, align 4, !tbaa !5
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = srem i32 %22, %23
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %32

26:                                               ; preds = %21
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = load i32, ptr @a, align 4, !tbaa !5
  %29 = sdiv i32 %28, %27
  store i32 %29, ptr @a, align 4, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %3, align 4, !tbaa !5
  br label %21, !llvm.loop !9

32:                                               ; preds = %21
  %33 = load i32, ptr @ans, align 4, !tbaa !5
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = srem i32 %34, 9901
  %36 = load i32, ptr @b, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = mul nsw i64 %37, %39
  %41 = call noundef i32 @_Z3sumix(i32 noundef %35, i64 noundef %40)
  %42 = mul nsw i32 %33, %41
  %43 = srem i32 %42, 9901
  store i32 %43, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %44

44:                                               ; preds = %32, %15
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !11

48:                                               ; preds = %14
  %49 = load i32, ptr @a, align 4, !tbaa !5
  %50 = icmp sgt i32 %49, 1
  br i1 %50, label %51, label %60

51:                                               ; preds = %48
  %52 = load i32, ptr @ans, align 4, !tbaa !5
  %53 = load i32, ptr @a, align 4, !tbaa !5
  %54 = srem i32 %53, 9901
  %55 = load i32, ptr @b, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = call noundef i32 @_Z3sumix(i32 noundef %54, i64 noundef %56)
  %58 = mul nsw i32 %52, %57
  %59 = srem i32 %58, 9901
  store i32 %59, ptr @ans, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %51, %48
  %61 = load i32, ptr @ans, align 4, !tbaa !5
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %61)
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

declare i32 @printf(ptr noundef, ...) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 norecurse 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 = { "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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3sumix(i32 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @a, ptr noundef nonnull @b)
  store i32 1, ptr @ans, align 4, !tbaa !5
  %2 = load i32, ptr @a, align 4, !tbaa !5
  %.not13 = icmp slt i32 %2, 4
  br i1 %.not13, label %._crit_edge17, label %.lr.ph16

._crit_edge17:                                    ; preds = %24, %0
  %3 = phi i32 [ 1, %0 ], [ %26, %24 ]
  %.lcssa = phi i32 [ %2, %0 ], [ %25, %24 ]
  %4 = icmp sgt i32 %.lcssa, 1
  br i1 %4, label %29, label %36

.lr.ph16:                                         ; preds = %0, %24
  %5 = phi i32 [ %25, %24 ], [ %2, %0 ]
  %6 = phi i32 [ %26, %24 ], [ 1, %0 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %24 ], [ 2, %0 ]
  %7 = trunc nuw nsw i64 %indvars.iv to i32
  %8 = srem i32 %5, %7
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %.lr.ph, label %24

.lr.ph:                                           ; preds = %.lr.ph16, %.lr.ph
  %.011 = phi i32 [ %12, %.lr.ph ], [ 0, %.lr.ph16 ]
  %10 = phi i32 [ %11, %.lr.ph ], [ %5, %.lr.ph16 ]
  %11 = sdiv i32 %10, %7
  %12 = add nuw nsw i32 %.011, 1
  %13 = srem i32 %11, %7
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.lr.ph, label %15, !llvm.loop !9

15:                                               ; preds = %.lr.ph
  store i32 %11, ptr @a, align 4, !tbaa !5
  %16 = urem i32 %7, 9901
  %17 = load i32, ptr @b, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = zext nneg i32 %12 to i64
  %20 = mul nsw i64 %18, %19
  %21 = tail call noundef i32 @_Z3sumix(i32 noundef %16, i64 noundef %20)
  %22 = mul nsw i32 %21, %6
  %23 = srem i32 %22, 9901
  store i32 %23, ptr @ans, align 4, !tbaa !5
  %.pre = load i32, ptr @a, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %.lr.ph16, %15
  %25 = phi i32 [ %5, %.lr.ph16 ], [ %.pre, %15 ]
  %26 = phi i32 [ %6, %.lr.ph16 ], [ %23, %15 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = mul nuw nsw i64 %indvars.iv.next, %indvars.iv.next
  %28 = sext i32 %25 to i64
  %.not = icmp sgt i64 %27, %28
  br i1 %.not, label %._crit_edge17, label %.lr.ph16, !llvm.loop !11

29:                                               ; preds = %._crit_edge17
  %30 = urem i32 %.lcssa, 9901
  %31 = load i32, ptr @b, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = tail call noundef i32 @_Z3sumix(i32 noundef %30, i64 noundef %32)
  %34 = mul nsw i32 %33, %3
  %35 = srem i32 %34, 9901
  store i32 %35, ptr @ans, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %29, %._crit_edge17
  %37 = phi i32 [ %35, %29 ], [ %3, %._crit_edge17 ]
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %37)
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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 norecurse 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 = { nofree 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass