; LLVM IR from kazunetakahashi/atcoder :: 2017/0325_yahoo-procon2017-final/C2.ll (Z9add_kukaniii)

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

@M = external dso_local global i32, align 4
@added = external dso_local global [317 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8make_cnti(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 nounwind uwtable
declare dso_local void @_Z3addii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z9add_kukaniii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %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 i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %11 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %11, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %12 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %12, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 -1, ptr %9, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %23, %3
  %14 = load i32, ptr %7, align 4, !tbaa !5
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %21

17:                                               ; preds = %13
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = srem i32 %18, 317
  %20 = icmp ne i32 %19, 0
  br label %21

21:                                               ; preds = %17, %13
  %22 = phi i1 [ false, %13 ], [ %20, %17 ]
  br i1 %22, label %23, label %29

23:                                               ; preds = %21
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = sdiv i32 %24, 317
  store i32 %25, ptr %9, align 4, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %7, align 4, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3addii(i32 noundef %26, i32 noundef %28)
  br label %13, !llvm.loop !9

29:                                               ; preds = %21
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = icmp ne i32 %30, -1
  br i1 %31, label %32, label %34

32:                                               ; preds = %29
  %33 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z8make_cnti(i32 noundef %33)
  br label %34

34:                                               ; preds = %32, %29
  store i32 -1, ptr %9, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %45, %34
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %39, label %43

39:                                               ; preds = %35
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = srem i32 %40, 317
  %42 = icmp ne i32 %41, 0
  br label %43

43:                                               ; preds = %39, %35
  %44 = phi i1 [ false, %35 ], [ %42, %39 ]
  br i1 %44, label %45, label %51

45:                                               ; preds = %43
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = add nsw i32 %46, -1
  store i32 %47, ptr %8, align 4, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3addii(i32 noundef %47, i32 noundef %48)
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sdiv i32 %49, 317
  store i32 %50, ptr %9, align 4, !tbaa !5
  br label %35, !llvm.loop !11

51:                                               ; preds = %43
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = icmp ne i32 %52, -1
  br i1 %53, label %54, label %56

54:                                               ; preds = %51
  %55 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z8make_cnti(i32 noundef %55)
  br label %56

56:                                               ; preds = %54, %51
  br label %57

57:                                               ; preds = %61, %56
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = icmp slt i32 %58, %59
  br i1 %60, label %61, label %78

61:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = sdiv i32 %62, 317
  store i32 %63, ptr %10, align 4, !tbaa !5
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [317 x i32], ptr @added, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = add nsw i32 %68, %64
  store i32 %69, ptr %67, align 4, !tbaa !5
  %70 = load i32, ptr @M, align 4, !tbaa !5
  %71 = load i32, ptr %10, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [317 x i32], ptr @added, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = srem i32 %74, %70
  store i32 %75, ptr %73, align 4, !tbaa !5
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = add nsw i32 %76, 317
  store i32 %77, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %57, !llvm.loop !12

78:                                               ; preds = %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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 = { 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}
!12 = distinct !{!12, !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"

@M = external dso_local local_unnamed_addr global i32, align 4
@added = external dso_local local_unnamed_addr global [317 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8make_cnti(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3addii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z9add_kukaniii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sge i32 %0, %1
  %5 = srem i32 %0, 317
  %.not34 = icmp eq i32 %5, 0
  %or.cond35 = or i1 %4, %.not34
  br i1 %or.cond35, label %.critedge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.036 = phi i32 [ %6, %.lr.ph ], [ %0, %3 ]
  %6 = add nsw i32 %.036, 1
  tail call void @_Z3addii(i32 noundef %.036, i32 noundef %2)
  %7 = icmp sge i32 %6, %1
  %8 = srem i32 %6, 317
  %.not = icmp eq i32 %8, 0
  %or.cond = or i1 %7, %.not
  br i1 %or.cond, label %.critedge, label %.lr.ph, !llvm.loop !5

.critedge:                                        ; preds = %.lr.ph
  %.036.off = add i32 %.036, 633
  %.not30 = icmp ult i32 %.036.off, 317
  br i1 %.not30, label %.critedge.thread, label %9

9:                                                ; preds = %.critedge
  %10 = sdiv i32 %.036, 317
  tail call void @_Z8make_cnti(i32 noundef %10)
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %3, %9, %.critedge
  %.0.lcssa49 = phi i32 [ %6, %9 ], [ %6, %.critedge ], [ %0, %3 ]
  %11 = icmp sge i32 %.0.lcssa49, %1
  %12 = srem i32 %1, 317
  %.not3138 = icmp eq i32 %12, 0
  %or.cond3339 = or i1 %11, %.not3138
  br i1 %or.cond3339, label %.critedge2.thread, label %.lr.ph41

.lr.ph41:                                         ; preds = %.critedge.thread, %.lr.ph41
  %.02940 = phi i32 [ %13, %.lr.ph41 ], [ %1, %.critedge.thread ]
  %13 = add nsw i32 %.02940, -1
  tail call void @_Z3addii(i32 noundef %13, i32 noundef %2)
  %14 = icmp sge i32 %.0.lcssa49, %13
  %15 = srem i32 %13, 317
  %16 = sdiv i32 %13, 317
  %.not31 = icmp eq i32 %15, 0
  %or.cond33 = or i1 %14, %.not31
  br i1 %or.cond33, label %.critedge2, label %.lr.ph41, !llvm.loop !7

.critedge2:                                       ; preds = %.lr.ph41
  %.off = add i32 %.02940, 632
  %.not32 = icmp ult i32 %.off, 317
  br i1 %.not32, label %.critedge2.thread, label %17

17:                                               ; preds = %.critedge2
  tail call void @_Z8make_cnti(i32 noundef %16)
  br label %.critedge2.thread

.critedge2.thread:                                ; preds = %.critedge.thread, %17, %.critedge2
  %.029.lcssa53 = phi i32 [ %13, %17 ], [ %13, %.critedge2 ], [ %1, %.critedge.thread ]
  %18 = icmp slt i32 %.0.lcssa49, %.029.lcssa53
  br i1 %18, label %.lr.ph44, label %._crit_edge

.lr.ph44:                                         ; preds = %.critedge2.thread
  %19 = load i32, ptr @M, align 4, !tbaa !8
  br label %20

20:                                               ; preds = %.lr.ph44, %20
  %.143 = phi i32 [ %.0.lcssa49, %.lr.ph44 ], [ %27, %20 ]
  %21 = sdiv i32 %.143, 317
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [317 x i32], ptr @added, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !8
  %25 = add nsw i32 %24, %2
  %26 = srem i32 %25, %19
  store i32 %26, ptr %23, align 4, !tbaa !8
  %27 = add nsw i32 %.143, 317
  %28 = icmp slt i32 %27, %.029.lcssa53
  br i1 %28, label %20, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %20, %.critedge2.thread
  ret void
}

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = distinct !{!12, !6}


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