; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ (2116)

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

@a = external dso_local global i64, align 8
@b = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@Max = external dso_local global i64, align 8
@Min = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5solvei(i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %2

2:                                                ; preds = %56, %0
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @a, ptr noundef @b)
  %4 = xor i32 %3, -1
  %5 = icmp ne i32 %4, 0
  br i1 %5, label %6, label %57

6:                                                ; preds = %2
  %7 = load i64, ptr @n, align 8, !tbaa !5
  %8 = trunc i64 %7 to i32
  call void @_Z5solvei(i32 noundef %8)
  %9 = load i64, ptr @a, align 8, !tbaa !5
  %10 = icmp sge i64 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %6
  %12 = load i64, ptr @b, align 8, !tbaa !5
  %13 = icmp sle i64 %12, 0
  br i1 %13, label %20, label %14

14:                                               ; preds = %11, %6
  %15 = load i64, ptr @a, align 8, !tbaa !5
  %16 = icmp sle i64 %15, 0
  br i1 %16, label %17, label %22

17:                                               ; preds = %14
  %18 = load i64, ptr @b, align 8, !tbaa !5
  %19 = icmp sge i64 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %17, %11
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %22

22:                                               ; preds = %20, %17, %14
  %23 = load i64, ptr @a, align 8, !tbaa !5
  %24 = icmp sgt i64 %23, 0
  br i1 %24, label %25, label %39

25:                                               ; preds = %22
  %26 = load i64, ptr @b, align 8, !tbaa !5
  %27 = icmp sgt i64 %26, 0
  br i1 %27, label %28, label %39

28:                                               ; preds = %25
  %29 = load i64, ptr @a, align 8, !tbaa !5
  %30 = load i64, ptr @Max, align 8, !tbaa !5
  %31 = load i64, ptr @b, align 8, !tbaa !5
  %32 = sub nsw i64 %30, %31
  %33 = icmp sgt i64 %29, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %28
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %38

36:                                               ; preds = %28
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %38

38:                                               ; preds = %36, %34
  br label %39

39:                                               ; preds = %38, %25, %22
  %40 = load i64, ptr @a, align 8, !tbaa !5
  %41 = icmp slt i64 %40, 0
  br i1 %41, label %42, label %56

42:                                               ; preds = %39
  %43 = load i64, ptr @b, align 8, !tbaa !5
  %44 = icmp slt i64 %43, 0
  br i1 %44, label %45, label %56

45:                                               ; preds = %42
  %46 = load i64, ptr @a, align 8, !tbaa !5
  %47 = load i64, ptr @Min, align 8, !tbaa !5
  %48 = load i64, ptr @b, align 8, !tbaa !5
  %49 = sub nsw i64 %47, %48
  %50 = icmp slt i64 %46, %49
  br i1 %50, label %51, label %53

51:                                               ; preds = %45
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %55

53:                                               ; preds = %45
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %55

55:                                               ; preds = %53, %51
  br label %56

56:                                               ; preds = %55, %42, %39
  br label %2, !llvm.loop !9

57:                                               ; preds = %2
  ret i32 0
}

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

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

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

!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 = !{!"long long", !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"

@a = external dso_local global i64, align 8
@b = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@Max = external dso_local local_unnamed_addr global i64, align 8
@Min = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %.not11 = icmp eq i32 %1, -1
  br i1 %.not11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %31
  %2 = load i64, ptr @n, align 8, !tbaa !5
  %3 = trunc i64 %2 to i32
  tail call void @_Z5solvei(i32 noundef %3)
  %4 = load i64, ptr @a, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, -1
  %6 = load i64, ptr @b, align 8
  %7 = icmp slt i64 %6, 1
  %or.cond = select i1 %5, i1 %7, i1 false
  br i1 %or.cond, label %11, label %8

8:                                                ; preds = %.lr.ph
  %9 = icmp slt i64 %4, 1
  %10 = icmp sgt i64 %6, -1
  %or.cond3 = select i1 %9, i1 %10, i1 false
  br i1 %or.cond3, label %11, label %13

11:                                               ; preds = %8, %.lr.ph
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %.pre = load i64, ptr @a, align 8, !tbaa !5
  %.pre12 = load i64, ptr @b, align 8
  br label %13

13:                                               ; preds = %11, %8
  %14 = phi i64 [ %.pre12, %11 ], [ %6, %8 ]
  %15 = phi i64 [ %.pre, %11 ], [ %4, %8 ]
  %16 = icmp sgt i64 %15, 0
  %17 = icmp sgt i64 %14, 0
  %or.cond5 = select i1 %16, i1 %17, i1 false
  br i1 %or.cond5, label %.sink.split, label %22

.sink.split:                                      ; preds = %13
  %18 = load i64, ptr @Max, align 8, !tbaa !5
  %19 = sub nsw i64 %18, %14
  %20 = icmp sgt i64 %15, %19
  %.str.2..str.1 = select i1 %20, ptr @.str.2, ptr @.str.1
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2..str.1)
  br label %22

22:                                               ; preds = %.sink.split, %13
  %23 = load i64, ptr @a, align 8, !tbaa !5
  %24 = icmp slt i64 %23, 0
  %25 = load i64, ptr @b, align 8
  %26 = icmp slt i64 %25, 0
  %or.cond7 = select i1 %24, i1 %26, i1 false
  br i1 %or.cond7, label %.sink.split13, label %31

.sink.split13:                                    ; preds = %22
  %27 = load i64, ptr @Min, align 8, !tbaa !5
  %28 = sub nsw i64 %27, %25
  %29 = icmp slt i64 %23, %28
  %.str.2..str.115 = select i1 %29, ptr @.str.2, ptr @.str.1
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2..str.115)
  br label %31

31:                                               ; preds = %.sink.split13, %22
  %32 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %.not = icmp eq i32 %32, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

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

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

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

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 = { mustprogress 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 #2 = { 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 = !{!"long long", !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,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass