; LLVM IR from tangjz/acm-icpc :: lydsy (1438)

; 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
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@d = 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 [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z5checkiii(i32 noundef, i32 noundef, 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
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %3

3:                                                ; preds = %60, %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 %65

7:                                                ; preds = %3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @a, ptr noundef @b, ptr noundef @c, ptr noundef @d)
  %9 = load i32, ptr @c, align 4, !tbaa !5
  %10 = load i32, ptr @a, align 4, !tbaa !5
  %11 = srem i32 %9, %10
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %18

13:                                               ; preds = %7
  %14 = load i32, ptr @d, align 4, !tbaa !5
  %15 = load i32, ptr @b, align 4, !tbaa !5
  %16 = srem i32 %14, %15
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %60, label %18

18:                                               ; preds = %13, %7
  %19 = load i32, ptr @c, align 4, !tbaa !5
  %20 = load i32, ptr @b, align 4, !tbaa !5
  %21 = srem i32 %19, %20
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %18
  %24 = load i32, ptr @d, align 4, !tbaa !5
  %25 = load i32, ptr @a, align 4, !tbaa !5
  %26 = srem i32 %24, %25
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %60, label %28

28:                                               ; preds = %23, %18
  %29 = load i32, ptr @c, align 4, !tbaa !5
  %30 = load i32, ptr @a, align 4, !tbaa !5
  %31 = srem i32 %29, %30
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %43

33:                                               ; preds = %28
  %34 = load i32, ptr @c, align 4, !tbaa !5
  %35 = load i32, ptr @b, align 4, !tbaa !5
  %36 = srem i32 %34, %35
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %43

38:                                               ; preds = %33
  %39 = load i32, ptr @d, align 4, !tbaa !5
  %40 = load i32, ptr @a, align 4, !tbaa !5
  %41 = load i32, ptr @b, align 4, !tbaa !5
  %42 = call noundef zeroext i1 @_Z5checkiii(i32 noundef %39, i32 noundef %40, i32 noundef %41)
  br i1 %42, label %60, label %43

43:                                               ; preds = %38, %33, %28
  %44 = load i32, ptr @d, align 4, !tbaa !5
  %45 = load i32, ptr @a, align 4, !tbaa !5
  %46 = srem i32 %44, %45
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %58

48:                                               ; preds = %43
  %49 = load i32, ptr @d, align 4, !tbaa !5
  %50 = load i32, ptr @b, align 4, !tbaa !5
  %51 = srem i32 %49, %50
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %58

53:                                               ; preds = %48
  %54 = load i32, ptr @c, align 4, !tbaa !5
  %55 = load i32, ptr @a, align 4, !tbaa !5
  %56 = load i32, ptr @b, align 4, !tbaa !5
  %57 = call noundef zeroext i1 @_Z5checkiii(i32 noundef %54, i32 noundef %55, i32 noundef %56)
  br label %58

58:                                               ; preds = %53, %48, %43
  %59 = phi i1 [ false, %48 ], [ false, %43 ], [ %57, %53 ]
  br label %60

60:                                               ; preds = %58, %38, %23, %13
  %61 = phi i1 [ true, %38 ], [ true, %23 ], [ true, %13 ], [ %59, %58 ]
  %62 = zext i1 %61 to i64
  %63 = select i1 %61, ptr @.str.2, ptr @.str.3
  %64 = call i32 @puts(ptr noundef %63)
  br label %3, !llvm.loop !9

65:                                               ; preds = %3
  ret i32 0
}

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

declare i32 @puts(ptr noundef) #2

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

@t = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@d = 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 [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z5checkiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse 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 @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
  %.not8 = icmp eq i32 %2, 0
  br i1 %.not8, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.thread4
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @c, ptr noundef nonnull @d)
  %5 = load i32, ptr @c, align 4, !tbaa !5
  %6 = load i32, ptr @a, align 4, !tbaa !5
  %7 = srem i32 %5, %6
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %.thread5

9:                                                ; preds = %.lr.ph
  %10 = load i32, ptr @d, align 4, !tbaa !5
  %11 = load i32, ptr @b, align 4, !tbaa !5
  %12 = srem i32 %10, %11
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %.thread2, label %14

14:                                               ; preds = %9
  %15 = srem i32 %5, %11
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %20, label %.thread1

.thread5:                                         ; preds = %.lr.ph
  %17 = load i32, ptr @b, align 4, !tbaa !5
  %18 = srem i32 %5, %17
  %19 = icmp eq i32 %18, 0
  %.pre9 = load i32, ptr @d, align 4, !tbaa !5
  br i1 %19, label %.thread6, label %.thread1

20:                                               ; preds = %14
  %21 = srem i32 %10, %6
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %.thread2, label %25

.thread6:                                         ; preds = %.thread5
  %23 = srem i32 %.pre9, %6
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %.thread2, label %.thread1

25:                                               ; preds = %20
  %26 = tail call noundef zeroext i1 @_Z5checkiii(i32 noundef %10, i32 noundef %6, i32 noundef %11)
  br i1 %26, label %.thread2, label %..thread1_crit_edge

..thread1_crit_edge:                              ; preds = %25
  %.pre = load i32, ptr @d, align 4, !tbaa !5
  %.pre10 = load i32, ptr @a, align 4, !tbaa !5
  br label %.thread1

.thread1:                                         ; preds = %..thread1_crit_edge, %.thread6, %.thread5, %14
  %27 = phi i32 [ %.pre10, %..thread1_crit_edge ], [ %6, %.thread6 ], [ %6, %.thread5 ], [ %6, %14 ]
  %28 = phi i32 [ %.pre, %..thread1_crit_edge ], [ %.pre9, %.thread6 ], [ %.pre9, %.thread5 ], [ %10, %14 ]
  %29 = srem i32 %28, %27
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %.thread4

31:                                               ; preds = %.thread1
  %32 = load i32, ptr @b, align 4, !tbaa !5
  %33 = srem i32 %28, %32
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %.thread4

35:                                               ; preds = %31
  %36 = load i32, ptr @c, align 4, !tbaa !5
  %37 = tail call noundef zeroext i1 @_Z5checkiii(i32 noundef %36, i32 noundef %27, i32 noundef %32)
  br i1 %37, label %.thread2, label %.thread4

.thread2:                                         ; preds = %.thread6, %9, %20, %25, %35
  br label %.thread4

.thread4:                                         ; preds = %.thread1, %31, %35, %.thread2
  %38 = phi ptr [ @.str.2, %.thread2 ], [ @.str.3, %35 ], [ @.str.3, %31 ], [ @.str.3, %.thread1 ]
  %39 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %38)
  %40 = load i32, ptr @t, align 4, !tbaa !5
  %41 = add nsw i32 %40, -1
  store i32 %41, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %40, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.thread4, %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 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

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


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass