; LLVM IR from tangjz/acm-icpc :: poj (3005)

; 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
@x_L = external dso_local global i32, align 4
@x_H = external dso_local global i32, align 4
@l = external dso_local global i32, align 4
@r = external dso_local global i32, align 4
@L = external dso_local global i32, align 4
@R = external dso_local global i32, align 4
@M = 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
@_ZL3ans = external hidden constant [245 x i32], align 16
@.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
  store i32 0, ptr %1, align 4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %3

3:                                                ; preds = %54, %0
  %4 = load i32, ptr @t, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @t, align 4, !tbaa !5
  %6 = icmp ne i32 %4, 0
  br i1 %6, label %7, label %61

7:                                                ; preds = %3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @x_L, ptr noundef @x_H)
  store i32 1, ptr @L, align 4, !tbaa !5
  store i32 244, ptr @R, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %29, %7
  %10 = load i32, ptr @L, align 4, !tbaa !5
  %11 = load i32, ptr @R, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %30

13:                                               ; preds = %9
  %14 = load i32, ptr @L, align 4, !tbaa !5
  %15 = load i32, ptr @R, align 4, !tbaa !5
  %16 = add nsw i32 %14, %15
  %17 = ashr i32 %16, 1
  store i32 %17, ptr @M, align 4, !tbaa !5
  %18 = load i32, ptr @x_L, align 4, !tbaa !5
  %19 = load i32, ptr @M, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [245 x i32], ptr @_ZL3ans, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp sle i32 %18, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %13
  %25 = load i32, ptr @M, align 4, !tbaa !5
  store i32 %25, ptr @R, align 4, !tbaa !5
  br label %29

26:                                               ; preds = %13
  %27 = load i32, ptr @M, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @L, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %26, %24
  br label %9, !llvm.loop !9

30:                                               ; preds = %9
  %31 = load i32, ptr @L, align 4, !tbaa !5
  store i32 %31, ptr @l, align 4, !tbaa !5
  store i32 0, ptr @L, align 4, !tbaa !5
  store i32 243, ptr @R, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %53, %30
  %33 = load i32, ptr @L, align 4, !tbaa !5
  %34 = load i32, ptr @R, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %54

36:                                               ; preds = %32
  %37 = load i32, ptr @L, align 4, !tbaa !5
  %38 = load i32, ptr @R, align 4, !tbaa !5
  %39 = add nsw i32 %37, %38
  %40 = add nsw i32 %39, 1
  %41 = ashr i32 %40, 1
  store i32 %41, ptr @M, align 4, !tbaa !5
  %42 = load i32, ptr @x_H, align 4, !tbaa !5
  %43 = load i32, ptr @M, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [245 x i32], ptr @_ZL3ans, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = icmp sge i32 %42, %46
  br i1 %47, label %48, label %50

48:                                               ; preds = %36
  %49 = load i32, ptr @M, align 4, !tbaa !5
  store i32 %49, ptr @L, align 4, !tbaa !5
  br label %53

50:                                               ; preds = %36
  %51 = load i32, ptr @M, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  store i32 %52, ptr @R, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %50, %48
  br label %32, !llvm.loop !11

54:                                               ; preds = %32
  %55 = load i32, ptr @R, align 4, !tbaa !5
  store i32 %55, ptr @r, align 4, !tbaa !5
  %56 = load i32, ptr @r, align 4, !tbaa !5
  %57 = load i32, ptr @l, align 4, !tbaa !5
  %58 = sub nsw i32 %56, %57
  %59 = add nsw i32 %58, 1
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %59)
  br label %3, !llvm.loop !12

61:                                               ; preds = %3
  ret i32 0
}

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

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

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

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

@t = external dso_local global i32, align 4
@x_L = external dso_local global i32, align 4
@x_H = external dso_local global i32, align 4
@l = external dso_local local_unnamed_addr global i32, align 4
@r = external dso_local local_unnamed_addr global i32, align 4
@L = external dso_local local_unnamed_addr global i32, align 4
@R = external dso_local local_unnamed_addr global i32, align 4
@M = 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
@_ZL3ans = external hidden local_unnamed_addr constant [245 x i32], align 16
@.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
  %.not16 = icmp eq i32 %2, 0
  br i1 %.not16, label %._crit_edge19, label %.lr.ph

.lr.ph:                                           ; preds = %0, %35
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @x_L, ptr noundef nonnull @x_H)
  %5 = load i32, ptr @x_L, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %.lr.ph, %6
  %7 = phi i32 [ 1, %.lr.ph ], [ %16, %6 ]
  %8 = phi i32 [ 244, %.lr.ph ], [ %15, %6 ]
  %9 = add nsw i32 %8, %7
  %10 = ashr i32 %9, 1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [245 x i32], ptr @_ZL3ans, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not6 = icmp sgt i32 %5, %13
  %14 = add nsw i32 %10, 1
  %15 = select i1 %.not6, i32 %8, i32 %10
  %16 = select i1 %.not6, i32 %14, i32 %7
  %17 = icmp slt i32 %16, %15
  br i1 %17, label %6, label %.lr.ph12, !llvm.loop !9

.lr.ph12:                                         ; preds = %6
  store i32 %16, ptr @l, align 4, !tbaa !5
  store i32 0, ptr @L, align 4, !tbaa !5
  store i32 243, ptr @R, align 4, !tbaa !5
  %18 = load i32, ptr @x_H, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %.lr.ph12, %31
  %20 = phi i32 [ 0, %.lr.ph12 ], [ %33, %31 ]
  %21 = phi i32 [ 243, %.lr.ph12 ], [ %32, %31 ]
  %22 = add nsw i32 %20, 1
  %23 = add i32 %22, %21
  %24 = ashr i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [245 x i32], ptr @_ZL3ans, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not5 = icmp slt i32 %18, %27
  br i1 %.not5, label %29, label %28

28:                                               ; preds = %19
  store i32 %24, ptr @L, align 4, !tbaa !5
  br label %31

29:                                               ; preds = %19
  %30 = add nsw i32 %24, -1
  store i32 %30, ptr @R, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %29, %28
  %32 = phi i32 [ %30, %29 ], [ %21, %28 ]
  %33 = phi i32 [ %20, %29 ], [ %24, %28 ]
  %34 = icmp slt i32 %33, %32
  br i1 %34, label %19, label %35, !llvm.loop !11

35:                                               ; preds = %31
  store i32 %24, ptr @M, align 4, !tbaa !5
  store i32 %32, ptr @r, align 4, !tbaa !5
  %reass.sub = sub i32 %32, %16
  %36 = add i32 %reass.sub, 1
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %36)
  %38 = load i32, ptr @t, align 4, !tbaa !5
  %39 = add nsw i32 %38, -1
  store i32 %39, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %38, 0
  br i1 %.not, label %._crit_edge19, label %.lr.ph, !llvm.loop !12

._crit_edge19:                                    ; preds = %35, %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

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

!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: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass