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

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

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1
@t = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@z = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5exgcdiiRiS_(i32 noundef, i32 noundef, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4bsgsiii(i32 noundef, i32 noundef, i32 noundef) #2

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

declare i32 @puts(ptr noundef) #3

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @t, ptr noundef @k)
  br label %5

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

9:                                                ; preds = %5
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.3, ptr noundef @y, ptr noundef @z, ptr noundef @p)
  %11 = load i32, ptr @p, align 4, !tbaa !5
  %12 = load i32, ptr @y, align 4, !tbaa !5
  %13 = srem i32 %12, %11
  store i32 %13, ptr @y, align 4, !tbaa !5
  %14 = load i32, ptr @k, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %19

16:                                               ; preds = %9
  %17 = load i32, ptr @p, align 4, !tbaa !5
  %18 = sub nsw i32 %17, 1
  br label %21

19:                                               ; preds = %9
  %20 = load i32, ptr @p, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %19, %16
  %22 = phi i32 [ %18, %16 ], [ %20, %19 ]
  %23 = load i32, ptr @z, align 4, !tbaa !5
  %24 = srem i32 %23, %22
  store i32 %24, ptr @z, align 4, !tbaa !5
  %25 = load i32, ptr @k, align 4, !tbaa !5
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %33

27:                                               ; preds = %21
  %28 = load i32, ptr @y, align 4, !tbaa !5
  %29 = load i32, ptr @z, align 4, !tbaa !5
  %30 = load i32, ptr @p, align 4, !tbaa !5
  %31 = call noundef i32 @_Z3powiii(i32 noundef %28, i32 noundef %29, i32 noundef %30)
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %31)
  br label %88

33:                                               ; preds = %21
  %34 = load i32, ptr @k, align 4, !tbaa !5
  %35 = icmp eq i32 %34, 2
  br i1 %35, label %36, label %67

36:                                               ; preds = %33
  %37 = load i32, ptr @z, align 4, !tbaa !5
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %41, label %39

39:                                               ; preds = %36
  %40 = call i32 @puts(ptr noundef @.str.4)
  br label %66

41:                                               ; preds = %36
  %42 = load i32, ptr @y, align 4, !tbaa !5
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %46, label %44

44:                                               ; preds = %41
  %45 = call i32 @puts(ptr noundef @.str.1)
  br label %65

46:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %47 = load i32, ptr @y, align 4, !tbaa !5
  %48 = load i32, ptr @p, align 4, !tbaa !5
  call void @_Z5exgcdiiRiS_(i32 noundef %47, i32 noundef %48, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = icmp slt i32 %49, 0
  br i1 %50, label %51, label %55

51:                                               ; preds = %46
  %52 = load i32, ptr @p, align 4, !tbaa !5
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = add nsw i32 %53, %52
  store i32 %54, ptr %2, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %51, %46
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = load i32, ptr @z, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = mul nsw i64 %57, %59
  %61 = load i32, ptr @p, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = srem i64 %60, %62
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %63)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %65

65:                                               ; preds = %55, %44
  br label %66

66:                                               ; preds = %65, %39
  br label %87

67:                                               ; preds = %33
  %68 = load i32, ptr @k, align 4, !tbaa !5
  %69 = icmp eq i32 %68, 3
  br i1 %69, label %70, label %86

70:                                               ; preds = %67
  %71 = load i32, ptr @y, align 4, !tbaa !5
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %81, label %73

73:                                               ; preds = %70
  %74 = load i32, ptr @z, align 4, !tbaa !5
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %78, label %76

76:                                               ; preds = %73
  %77 = call i32 @puts(ptr noundef @.str.5)
  br label %80

78:                                               ; preds = %73
  %79 = call i32 @puts(ptr noundef @.str.1)
  br label %80

80:                                               ; preds = %78, %76
  br label %85

81:                                               ; preds = %70
  %82 = load i32, ptr @y, align 4, !tbaa !5
  %83 = load i32, ptr @z, align 4, !tbaa !5
  %84 = load i32, ptr @p, align 4, !tbaa !5
  call void @_Z4bsgsiii(i32 noundef %82, i32 noundef %83, i32 noundef %84)
  br label %85

85:                                               ; preds = %81, %80
  br label %86

86:                                               ; preds = %85, %67
  br label %87

87:                                               ; preds = %86, %66
  br label %88

88:                                               ; preds = %87, %27
  br label %5, !llvm.loop !9

89:                                               ; preds = %5
  ret i32 0
}

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

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


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

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1
@t = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@z = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4bsgsiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #3

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

.lr.ph:                                           ; preds = %0, %46
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.3, ptr noundef nonnull @y, ptr noundef nonnull @z, ptr noundef nonnull @p)
  %7 = load i32, ptr @p, align 4
  %8 = load i32, ptr @y, align 4, !tbaa !5
  %9 = srem i32 %8, %7
  store i32 %9, ptr @y, align 4, !tbaa !5
  %10 = load i32, ptr @k, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 1
  %12 = sext i1 %11 to i32
  %13 = add nsw i32 %7, %12
  %14 = load i32, ptr @z, align 4, !tbaa !5
  %15 = srem i32 %14, %13
  store i32 %15, ptr @z, align 4, !tbaa !5
  switch i32 %10, label %46 [
    i32 1, label %16
    i32 2, label %19
    i32 3, label %39
  ]

16:                                               ; preds = %.lr.ph
  %17 = call noundef i32 @_Z3powiii(i32 noundef %9, i32 noundef %15, i32 noundef %7)
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %17)
  br label %46

19:                                               ; preds = %.lr.ph
  %.not5 = icmp eq i32 %15, 0
  br i1 %.not5, label %20, label %22

20:                                               ; preds = %19
  %21 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %46

22:                                               ; preds = %19
  %.not6 = icmp eq i32 %9, 0
  br i1 %.not6, label %23, label %25

23:                                               ; preds = %22
  %24 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %46

25:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  call void @_Z5exgcdiiRiS_(i32 noundef %9, i32 noundef %7, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 0
  %.pre = load i32, ptr @p, align 4, !tbaa !5
  br i1 %27, label %28, label %30

28:                                               ; preds = %25
  %29 = add nsw i32 %.pre, %26
  store i32 %29, ptr %1, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %28, %25
  %31 = phi i32 [ %29, %28 ], [ %26, %25 ]
  %32 = sext i32 %31 to i64
  %33 = load i32, ptr @z, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = mul nsw i64 %34, %32
  %36 = sext i32 %.pre to i64
  %37 = srem i64 %35, %36
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %37)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  br label %46

39:                                               ; preds = %.lr.ph
  %.not3 = icmp eq i32 %9, 0
  br i1 %.not3, label %40, label %45

40:                                               ; preds = %39
  %.not4 = icmp eq i32 %15, 0
  br i1 %.not4, label %41, label %43

41:                                               ; preds = %40
  %42 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %46

43:                                               ; preds = %40
  %44 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %46

45:                                               ; preds = %39
  call void @_Z4bsgsiii(i32 noundef %9, i32 noundef %15, i32 noundef %7)
  br label %46

46:                                               ; preds = %.lr.ph, %23, %30, %20, %45, %43, %41, %16
  %47 = load i32, ptr @t, align 4, !tbaa !5
  %48 = add nsw i32 %47, -1
  store i32 %48, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %47, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

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

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

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


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