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

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %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
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %9

9:                                                ; preds = %109, %18, %0
  %10 = load i32, ptr @t, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr @t, align 4, !tbaa !5
  %12 = icmp ne i32 %10, 0
  br i1 %12, label %13, label %112

13:                                               ; preds = %9
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m)
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = load i32, ptr @m, align 4, !tbaa !5
  %17 = icmp sle i32 %15, %16
  br i1 %17, label %18, label %23

18:                                               ; preds = %13
  %19 = load i32, ptr @m, align 4, !tbaa !5
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = sub nsw i32 %19, %20
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %21)
  br label %9, !llvm.loop !9

23:                                               ; preds = %13
  store i32 1061109567, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %32, %23
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = shl i32 1, %25
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = load i32, ptr @m, align 4, !tbaa !5
  %29 = sub nsw i32 %27, %28
  %30 = icmp sle i32 %26, %29
  br i1 %30, label %31, label %35

31:                                               ; preds = %24
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %2, align 4, !tbaa !5
  br label %24, !llvm.loop !11

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

36:                                               ; preds = %105, %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = shl i32 1, %38
  %40 = sub nsw i32 %37, %39
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %5, align 4, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = icmp slt i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %36
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %44, %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %46 = load i32, ptr @m, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sub nsw i32 %46, %47
  store i32 %48, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %52, label %54

52:                                               ; preds = %45
  %53 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %53, ptr %6, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %52, %45
  %55 = load i32, ptr @ans, align 4, !tbaa !5
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = add nsw i32 %56, %57
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = add nsw i32 %58, %59
  %61 = icmp sgt i32 %55, %60
  br i1 %61, label %62, label %68

62:                                               ; preds = %54
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = add nsw i32 %63, %64
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = add nsw i32 %65, %66
  store i32 %67, ptr @ans, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %62, %54
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = load i32, ptr @m, align 4, !tbaa !5
  %71 = icmp eq i32 %69, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %68
  store i32 7, ptr %7, align 4
  br label %102

73:                                               ; preds = %68
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = sub nsw i32 %74, 1
  %76 = shl i32 1, %75
  %77 = sub nsw i32 %76, 1
  %78 = load i32, ptr @n, align 4, !tbaa !5
  %79 = sub nsw i32 %78, %77
  store i32 %79, ptr @n, align 4, !tbaa !5
  %80 = load i32, ptr %2, align 4, !tbaa !5
  %81 = sub nsw i32 %80, 1
  %82 = load i32, ptr %3, align 4, !tbaa !5
  %83 = add nsw i32 %82, %81
  store i32 %83, ptr %3, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %98, %73
  %85 = load i32, ptr %2, align 4, !tbaa !5
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %87, label %95

87:                                               ; preds = %84
  %88 = load i32, ptr %2, align 4, !tbaa !5
  %89 = sub nsw i32 %88, 1
  %90 = shl i32 1, %89
  %91 = load i32, ptr @n, align 4, !tbaa !5
  %92 = load i32, ptr @m, align 4, !tbaa !5
  %93 = sub nsw i32 %91, %92
  %94 = icmp sgt i32 %90, %93
  br label %95

95:                                               ; preds = %87, %84
  %96 = phi i1 [ false, %84 ], [ %94, %87 ]
  br i1 %96, label %97, label %101

97:                                               ; preds = %95
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %2, align 4, !tbaa !5
  %100 = add nsw i32 %99, -1
  store i32 %100, ptr %2, align 4, !tbaa !5
  br label %84, !llvm.loop !12

101:                                              ; preds = %95
  store i32 0, ptr %7, align 4
  br label %102

102:                                              ; preds = %101, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %103 = load i32, ptr %7, align 4
  switch i32 %103, label %108 [
    i32 0, label %104
  ]

104:                                              ; preds = %102
  br label %105

105:                                              ; preds = %104
  %106 = load i32, ptr %4, align 4, !tbaa !5
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %4, align 4, !tbaa !5
  br label %36, !llvm.loop !13

108:                                              ; preds = %102
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %109

109:                                              ; preds = %108
  %110 = load i32, ptr @ans, align 4, !tbaa !5
  %111 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %110)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %9, !llvm.loop !9

112:                                              ; preds = %9
  ret i32 0
}

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

attributes #0 = { 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 #1 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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"

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not39 = icmp eq i32 %2, 0
  br i1 %.not39, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.backedge
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = load i32, ptr @m, align 4, !tbaa !5
  %.not32 = icmp sgt i32 %5, %6
  br i1 %.not32, label %12, label %7

7:                                                ; preds = %.lr.ph
  %8 = sub nsw i32 %6, %5
  br label %.backedge

.backedge:                                        ; preds = %26, %7
  %.sink = phi i32 [ %8, %7 ], [ %27, %26 ]
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.sink)
  %10 = load i32, ptr @t, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

12:                                               ; preds = %.lr.ph
  store i32 1061109567, ptr @ans, align 4, !tbaa !5
  %13 = sub nsw i32 %5, %6
  br label %14

14:                                               ; preds = %14, %12
  %.026 = phi i32 [ 0, %12 ], [ %16, %14 ]
  %15 = shl nuw i32 1, %.026
  %.not33 = icmp sgt i32 %15, %13
  %16 = add nuw nsw i32 %.026, 1
  br i1 %.not33, label %.preheader, label %14, !llvm.loop !11

.preheader:                                       ; preds = %14, %.critedge
  %17 = phi i32 [ %27, %.critedge ], [ 1061109567, %14 ]
  %18 = phi i32 [ %30, %.critedge ], [ %5, %14 ]
  %.127 = phi i32 [ %.2, %.critedge ], [ %.026, %14 ]
  %.025 = phi i32 [ %31, %.critedge ], [ 0, %14 ]
  %.024 = phi i32 [ %38, %.critedge ], [ 0, %14 ]
  %.neg = shl nsw i32 -1, %.127
  %19 = add i32 %18, %.neg
  %20 = tail call i32 @llvm.smax.i32(i32 %19, i32 -1)
  %spec.store.select = add nsw i32 %20, 1
  %21 = sub nsw i32 %6, %spec.store.select
  %spec.select = tail call i32 @llvm.smax.i32(i32 %21, i32 %.024)
  %22 = add i32 %.025, %.127
  %23 = add i32 %22, %spec.select
  %24 = icmp sgt i32 %17, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %.preheader
  store i32 %23, ptr @ans, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %25, %.preheader
  %27 = phi i32 [ %23, %25 ], [ %17, %.preheader ]
  %.not36 = icmp eq i32 %spec.store.select, %6
  br i1 %.not36, label %.backedge, label %28

28:                                               ; preds = %26
  %29 = add nsw i32 %.127, -1
  %notmask = shl nsw i32 -1, %29
  %.neg34 = add nsw i32 %notmask, 1
  %30 = add i32 %.neg34, %18
  store i32 %30, ptr @n, align 4, !tbaa !5
  %31 = add nsw i32 %.025, %29
  %32 = sub nsw i32 %30, %6
  br label %33

33:                                               ; preds = %34, %28
  %.2 = phi i32 [ %.127, %28 ], [ %35, %34 ]
  %.not35 = icmp eq i32 %.2, 0
  br i1 %.not35, label %.critedge, label %34

34:                                               ; preds = %33
  %35 = add nsw i32 %.2, -1
  %36 = shl nuw i32 1, %35
  %37 = icmp sgt i32 %36, %32
  br i1 %37, label %33, label %.critedge, !llvm.loop !12

.critedge:                                        ; preds = %34, %33
  %38 = add nuw nsw i32 %.024, 1
  br label %.preheader

._crit_edge:                                      ; preds = %.backedge, %0
  ret i32 0
}

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

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

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

attributes #0 = { mustprogress nofree norecurse 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 = { 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 = { 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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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