; LLVM IR from kazunetakahashi/atcoder :: 201510_201609/0828_ARC060/E2.ll (Z1gii)

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

@N = external dso_local global i32, align 4
@x = external dso_local global [100010 x i32], align 16
@L = external dso_local global i32, align 4
@memo = external dso_local global [100010 x [18 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z1gii(i32 noundef %0, i32 noundef %1) #0 {
  %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
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100010 x [18 x i32]], ptr @memo, i64 0, i64 %9
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [18 x i32], ptr %10, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp ne i32 %14, -1
  br i1 %15, label %16, label %24

16:                                               ; preds = %2
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100010 x [18 x i32]], ptr @memo, i64 0, i64 %18
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [18 x i32], ptr %19, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %23, ptr %3, align 4
  br label %79

24:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = load i32, ptr @N, align 4, !tbaa !5
  %27 = sub nsw i32 %26, 1
  %28 = icmp eq i32 %25, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %24
  %30 = load i32, ptr @N, align 4, !tbaa !5
  %31 = sub nsw i32 %30, 1
  store i32 %31, ptr %6, align 4, !tbaa !5
  br label %71

32:                                               ; preds = %24
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %62

35:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %36 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %36, ptr %7, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %57, %35
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  %40 = load i32, ptr @N, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %55

42:                                               ; preds = %37
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100010 x i32], ptr @x, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100010 x i32], ptr @x, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = sub nsw i32 %47, %51
  %53 = load i32, ptr @L, align 4, !tbaa !5
  %54 = icmp sle i32 %52, %53
  br label %55

55:                                               ; preds = %42, %37
  %56 = phi i1 [ false, %37 ], [ %54, %42 ]
  br i1 %56, label %57, label %60

57:                                               ; preds = %55
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %7, align 4, !tbaa !5
  br label %37, !llvm.loop !9

60:                                               ; preds = %55
  %61 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %61, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %70

62:                                               ; preds = %32
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = sub nsw i32 %64, 1
  %66 = call noundef i32 @_Z1gii(i32 noundef %63, i32 noundef %65)
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = sub nsw i32 %67, 1
  %69 = call noundef i32 @_Z1gii(i32 noundef %66, i32 noundef %68)
  store i32 %69, ptr %6, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %62, %60
  br label %71

71:                                               ; preds = %70, %29
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [100010 x [18 x i32]], ptr @memo, i64 0, i64 %74
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [18 x i32], ptr %75, i64 0, i64 %77
  store i32 %72, ptr %78, align 4, !tbaa !5
  store i32 %72, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %79

79:                                               ; preds = %71, %16
  %80 = load i32, ptr %3, align 4
  ret i32 %80
}

; 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

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


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

@N = external dso_local local_unnamed_addr global i32, align 4
@x = external dso_local local_unnamed_addr global [100010 x i32], align 16
@L = external dso_local local_unnamed_addr global i32, align 4
@memo = external dso_local local_unnamed_addr global [100010 x [18 x i32]], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z1gii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = sext i32 %1 to i64
  %5 = getelementptr inbounds [100010 x [18 x i32]], ptr @memo, i64 0, i64 %3, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not = icmp eq i32 %6, -1
  br i1 %.not, label %7, label %30

7:                                                ; preds = %2
  %8 = load i32, ptr @N, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  %10 = icmp eq i32 %9, %0
  br i1 %10, label %.critedge, label %11

11:                                               ; preds = %7
  %12 = icmp eq i32 %1, 0
  br i1 %12, label %.preheader, label %25

.preheader:                                       ; preds = %11
  %13 = getelementptr inbounds [100010 x i32], ptr @x, i64 0, i64 %3
  %14 = load i32, ptr @L, align 4
  %15 = sext i32 %8 to i64
  %16 = add i32 %0, 1
  %smax = tail call i32 @llvm.smax.i32(i32 %8, i32 %16)
  %17 = add i32 %smax, -1
  br label %18

18:                                               ; preds = %.preheader, %20
  %indvars.iv = phi i64 [ %3, %.preheader ], [ %indvars.iv.next, %20 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %19 = icmp slt i64 %indvars.iv.next, %15
  br i1 %19, label %20, label %.critedge

20:                                               ; preds = %18
  %21 = getelementptr inbounds [100010 x i32], ptr @x, i64 0, i64 %indvars.iv.next
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = load i32, ptr %13, align 4, !tbaa !5
  %24 = sub nsw i32 %22, %23
  %.not26 = icmp sgt i32 %24, %14
  br i1 %.not26, label %.critedge.loopexit.split.loop.exit28, label %18, !llvm.loop !9

25:                                               ; preds = %11
  %26 = add nsw i32 %1, -1
  %27 = tail call noundef i32 @_Z1gii(i32 noundef %0, i32 noundef %26)
  %28 = tail call noundef i32 @_Z1gii(i32 noundef %27, i32 noundef %26)
  br label %.critedge

.critedge.loopexit.split.loop.exit28:             ; preds = %20
  %29 = trunc nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %18, %.critedge.loopexit.split.loop.exit28, %7, %25
  %.019 = phi i32 [ %28, %25 ], [ %0, %7 ], [ %29, %.critedge.loopexit.split.loop.exit28 ], [ %17, %18 ]
  store i32 %.019, ptr %5, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %2, %.critedge
  %.020 = phi i32 [ %.019, %.critedge ], [ %6, %2 ]
  ret i32 %.020
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 speculatable willreturn memory(none) }

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


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