; LLVM IR from tangjz/acm-icpc :: hdu (4673)

; 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
@hp = external dso_local global i32, align 4
@a = external dso_local global [30001 x i32], align 16
@b = external dso_local global [30001 x i32], align 16
@d = external dso_local global [30001 x i32], align 16
@sz = external dso_local global [1001 x i32], align 16
@typ = external dso_local global [1001 x [3 x i32]], align 16
@cst = external dso_local global [1001 x [3 x i32]], align 16
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 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 void @_Z7prepareRiPiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef, ptr noundef) #1

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4calci(i32 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %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 %1, align 4
  br label %8

8:                                                ; preds = %86, %0
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m, ptr noundef @hp)
  %10 = icmp eq i32 %9, 3
  br i1 %10, label %11, label %87

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %28, %11
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %31

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i32, ptr @a, i64 %19
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr @b, i64 %22
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr @d, i64 %25
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %20, ptr noundef %23, ptr noundef %26)
  br label %28

28:                                               ; preds = %17
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !9

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

32:                                               ; preds = %49, %31
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = load i32, ptr @m, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %52

37:                                               ; preds = %32
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1001 x i32], ptr @sz, i64 0, i64 %39
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1001 x [3 x i32]], ptr @typ, i64 0, i64 %42
  %44 = getelementptr inbounds [3 x i32], ptr %43, i64 0, i64 0
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1001 x [3 x i32]], ptr @cst, i64 0, i64 %46
  %48 = getelementptr inbounds [3 x i32], ptr %47, i64 0, i64 0
  call void @_Z7prepareRiPiS0_(ptr noundef nonnull align 4 dereferenceable(4) %40, ptr noundef %44, ptr noundef %48)
  br label %49

49:                                               ; preds = %37
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %3, align 4, !tbaa !5
  br label %32, !llvm.loop !11

52:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %53 = load i32, ptr @m, align 4, !tbaa !5
  store i32 %53, ptr %5, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %72, %52
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = icmp slt i32 %55, %56
  br i1 %57, label %58, label %74

58:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = add nsw i32 %59, %60
  %62 = ashr i32 %61, 1
  store i32 %62, ptr %6, align 4, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = call noundef i32 @_Z4calci(i32 noundef %63)
  %65 = load i32, ptr @hp, align 4, !tbaa !5
  %66 = icmp slt i32 %64, %65
  br i1 %66, label %67, label %69

67:                                               ; preds = %58
  %68 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %68, ptr %5, align 4, !tbaa !5
  br label %72

69:                                               ; preds = %58
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %4, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %69, %67
  %73 = phi ptr [ %5, %67 ], [ %4, %69 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %54, !llvm.loop !12

74:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = call noundef i32 @_Z4calci(i32 noundef %75)
  store i32 %76, ptr %7, align 4, !tbaa !5
  %77 = load i32, ptr %7, align 4, !tbaa !5
  %78 = load i32, ptr @hp, align 4, !tbaa !5
  %79 = icmp slt i32 %77, %78
  br i1 %79, label %80, label %84

80:                                               ; preds = %74
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = load i32, ptr %7, align 4, !tbaa !5
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %81, i32 noundef %82)
  br label %86

84:                                               ; preds = %74
  %85 = call i32 @puts(ptr noundef @.str.3)
  br label %86

86:                                               ; preds = %84, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %8, !llvm.loop !13

87:                                               ; preds = %8
  ret i32 0
}

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

declare i32 @puts(ptr noundef) #2

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@hp = external dso_local global i32, align 4
@a = external dso_local global [30001 x i32], align 16
@b = external dso_local global [30001 x i32], align 16
@d = external dso_local global [30001 x i32], align 16
@sz = external dso_local global [1001 x i32], align 16
@typ = external dso_local global [1001 x [3 x i32]], align 16
@cst = external dso_local global [1001 x [3 x i32]], align 16
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1

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

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @hp)
  %2 = icmp eq i32 %1, 3
  br i1 %2, label %.preheader28, label %._crit_edge36

.preheader28:                                     ; preds = %0, %35
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %.preheader27

.preheader27:                                     ; preds = %.lr.ph, %.preheader28
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph31, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader28, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader28 ]
  %7 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %8 = getelementptr inbounds i32, ptr @b, i64 %indvars.iv
  %9 = getelementptr inbounds i32, ptr @d, i64 %indvars.iv
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %7, ptr noundef nonnull %8, ptr noundef nonnull %9)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %.preheader27, !llvm.loop !9

.preheader:                                       ; preds = %.lr.ph31
  %14 = icmp sgt i32 %18, 0
  br i1 %14, label %.lr.ph34, label %._crit_edge

.lr.ph31:                                         ; preds = %.preheader27, %.lr.ph31
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %.lr.ph31 ], [ 0, %.preheader27 ]
  %15 = getelementptr inbounds [1001 x i32], ptr @sz, i64 0, i64 %indvars.iv39
  %16 = getelementptr inbounds [1001 x [3 x i32]], ptr @typ, i64 0, i64 %indvars.iv39
  %17 = getelementptr inbounds [1001 x [3 x i32]], ptr @cst, i64 0, i64 %indvars.iv39
  tail call void @_Z7prepareRiPiS0_(ptr noundef nonnull align 4 dereferenceable(4) %15, ptr noundef nonnull %16, ptr noundef nonnull %17)
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %18 = load i32, ptr @m, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next40, %19
  br i1 %20, label %.lr.ph31, label %.preheader, !llvm.loop !11

.lr.ph34:                                         ; preds = %.preheader, %.lr.ph34
  %.02233 = phi i32 [ %.1, %.lr.ph34 ], [ %18, %.preheader ]
  %.02332 = phi i32 [ %.124, %.lr.ph34 ], [ 0, %.preheader ]
  %21 = add nuw nsw i32 %.02233, %.02332
  %22 = lshr i32 %21, 1
  %23 = tail call noundef i32 @_Z4calci(i32 noundef %22)
  %24 = load i32, ptr @hp, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  %26 = add nuw nsw i32 %22, 1
  %.124 = select i1 %25, i32 %.02332, i32 %26
  %.1 = select i1 %25, i32 %22, i32 %.02233
  %27 = icmp slt i32 %.124, %.1
  br i1 %27, label %.lr.ph34, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph34, %.preheader27, %.preheader
  %.023.lcssa = phi i32 [ 0, %.preheader ], [ 0, %.preheader27 ], [ %.124, %.lr.ph34 ]
  %28 = tail call noundef i32 @_Z4calci(i32 noundef %.023.lcssa)
  %29 = load i32, ptr @hp, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %._crit_edge
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.023.lcssa, i32 noundef %28)
  br label %35

33:                                               ; preds = %._crit_edge
  %34 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %35

35:                                               ; preds = %33, %31
  %36 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @hp)
  %37 = icmp eq i32 %36, 3
  br i1 %37, label %.preheader28, label %._crit_edge36, !llvm.loop !13

._crit_edge36:                                    ; preds = %35, %0
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #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 = { 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" }
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" }

!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}
!13 = distinct !{!13, !10}


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