; LLVM IR from tangjz/acm-icpc :: lydsy/1452.ll (Z3addPA300_iiii)

; 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
@m = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3addPA300_iiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  br label %10

10:                                               ; preds = %41, %4
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr @n, align 4, !tbaa !9
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  %16 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %16, ptr %9, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %32, %15
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = load i32, ptr @m, align 4, !tbaa !9
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %40

21:                                               ; preds = %17
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [300 x i32], ptr %23, i64 %25
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [300 x i32], ptr %26, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = add nsw i32 %30, %22
  store i32 %31, ptr %29, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %21
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = xor i32 %33, -1
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  %37 = and i32 %34, %36
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = add nsw i32 %38, %37
  store i32 %39, ptr %9, align 4, !tbaa !9
  br label %17, !llvm.loop !11

40:                                               ; preds = %17
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = xor i32 %42, -1
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  %46 = and i32 %43, %45
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = add nsw i32 %47, %46
  store i32 %48, ptr %6, align 4, !tbaa !9
  br label %10, !llvm.loop !13

49:                                               ; preds = %14
  ret void
}

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


; 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
@m = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z3addPA300_iiii(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, %1
  %7 = load i32, ptr @m, align 4
  %8 = icmp sgt i32 %7, %2
  %or.cond = select i1 %6, i1 %8, i1 false
  br i1 %or.cond, label %.preheader, label %._crit_edge15

.preheader:                                       ; preds = %4, %._crit_edge
  %9 = phi i32 [ %24, %._crit_edge ], [ %5, %4 ]
  %10 = phi i32 [ %25, %._crit_edge ], [ %7, %4 ]
  %.01214 = phi i32 [ %29, %._crit_edge ], [ %1, %4 ]
  %11 = icmp sgt i32 %10, %2
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %12 = sext i32 %.01214 to i64
  br label %13

._crit_edge15:                                    ; preds = %._crit_edge, %4
  ret void

13:                                               ; preds = %.lr.ph, %13
  %.013 = phi i32 [ %2, %.lr.ph ], [ %21, %13 ]
  %14 = sext i32 %.013 to i64
  %15 = getelementptr inbounds [300 x i32], ptr %0, i64 %12, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add nsw i32 %16, %3
  store i32 %17, ptr %15, align 4, !tbaa !5
  %18 = xor i32 %.013, -1
  %19 = add nsw i32 %.013, 1
  %20 = and i32 %19, %18
  %21 = add nsw i32 %20, %.013
  %22 = load i32, ptr @m, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %13, label %._crit_edge.loopexit, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %13
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %24 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %9, %.preheader ]
  %25 = phi i32 [ %22, %._crit_edge.loopexit ], [ %10, %.preheader ]
  %26 = xor i32 %.01214, -1
  %27 = add nsw i32 %.01214, 1
  %28 = and i32 %27, %26
  %29 = add nsw i32 %28, %.01214
  %30 = icmp slt i32 %29, %24
  br i1 %30, label %.preheader, label %._crit_edge15, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, 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" }

!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}
!12 = !{!"llvm.loop.unswitch.partial.disable"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass