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

; 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 [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = 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 [4 x i32], align 16
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca [24 x i32], align 16
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %118, %0
  %8 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  %9 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 1
  %10 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 2
  %11 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 3
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %8, ptr noundef %9, ptr noundef %10, ptr noundef %11)
  %13 = xor i32 %12, -1
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %119

15:                                               ; preds = %7
  %16 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  %17 = load i32, ptr %16, align 16, !tbaa !5
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %32

19:                                               ; preds = %15
  %20 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 1
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %32

23:                                               ; preds = %19
  %24 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 2
  %25 = load i32, ptr %24, align 8, !tbaa !5
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %32

27:                                               ; preds = %23
  %28 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 3
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  br label %119

32:                                               ; preds = %27, %23, %19, %15
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %37

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

37:                                               ; preds = %35, %32
  store i32 1, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 96, ptr %5) #4
  %38 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  %39 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  %40 = getelementptr inbounds i32, ptr %39, i64 4
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef %38, ptr noundef %40)
  br label %41

41:                                               ; preds = %66, %37
  %42 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  %43 = load i32, ptr %42, align 16, !tbaa !5
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %65

45:                                               ; preds = %41
  %46 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  %47 = load i32, ptr %46, align 16, !tbaa !5
  %48 = mul nsw i32 %47, 1000
  %49 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 1
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = mul nsw i32 %50, 100
  %52 = add nsw i32 %48, %51
  %53 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 2
  %54 = load i32, ptr %53, align 8, !tbaa !5
  %55 = mul nsw i32 %54, 10
  %56 = add nsw i32 %52, %55
  %57 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 3
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = add nsw i32 %56, %58
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [24 x i32], ptr %5, i64 0, i64 %61
  store i32 %59, ptr %62, align 4, !tbaa !5
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %4, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %45, %41
  br label %66

66:                                               ; preds = %65
  %67 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  %68 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  %69 = getelementptr inbounds i32, ptr %68, i64 4
  %70 = call noundef zeroext i1 @_ZSt16next_permutationIPiEbT_S1_(ptr noundef %67, ptr noundef %69)
  br i1 %70, label %41, label %71, !llvm.loop !9

71:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %115, %71
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %77, label %76

76:                                               ; preds = %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %118

77:                                               ; preds = %72
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  %80 = load i32, ptr %4, align 4, !tbaa !5
  %81 = icmp eq i32 %79, %80
  br i1 %81, label %82, label %88

82:                                               ; preds = %77
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [24 x i32], ptr %5, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %86)
  br label %114

88:                                               ; preds = %77
  %89 = load i32, ptr %6, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [24 x i32], ptr %5, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = sdiv i32 %92, 1000
  %94 = load i32, ptr %6, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [24 x i32], ptr %5, i64 0, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !5
  %99 = sdiv i32 %98, 1000
  %100 = icmp eq i32 %93, %99
  br i1 %100, label %101, label %107

101:                                              ; preds = %88
  %102 = load i32, ptr %6, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [24 x i32], ptr %5, i64 0, i64 %103
  %105 = load i32, ptr %104, align 4, !tbaa !5
  %106 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %105)
  br label %113

107:                                              ; preds = %88
  %108 = load i32, ptr %6, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [24 x i32], ptr %5, i64 0, i64 %109
  %111 = load i32, ptr %110, align 4, !tbaa !5
  %112 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %111)
  br label %113

113:                                              ; preds = %107, %101
  br label %114

114:                                              ; preds = %113, %82
  br label %115

115:                                              ; preds = %114
  %116 = load i32, ptr %6, align 4, !tbaa !5
  %117 = add nsw i32 %116, 1
  store i32 %117, ptr %6, align 4, !tbaa !5
  br label %72, !llvm.loop !11

118:                                              ; preds = %76
  call void @llvm.lifetime.end.p0(i64 96, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %7, !llvm.loop !12

119:                                              ; preds = %31, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #4
  ret i32 0
}

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZSt16next_permutationIPiEbT_S1_(ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { inlinehint 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 #4 = { 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}


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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [4 x i32], align 16
  %2 = alloca [24 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #4
  %3 = getelementptr inbounds i8, ptr %1, i64 4
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = getelementptr inbounds i8, ptr %1, i64 12
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %.not28 = icmp eq i32 %6, -1
  br i1 %.not28, label %._crit_edge32, label %.lr.ph31

.lr.ph31:                                         ; preds = %0
  %7 = getelementptr inbounds i8, ptr %1, i64 16
  br label %8

8:                                                ; preds = %.lr.ph31, %._crit_edge
  %.not2529 = phi i1 [ true, %.lr.ph31 ], [ false, %._crit_edge ]
  %9 = load <4 x i32>, ptr %1, align 16
  %.fr = freeze <4 x i32> %9
  %10 = icmp ne <4 x i32> %.fr, zeroinitializer
  %11 = bitcast <4 x i1> %10 to i4
  %12 = icmp eq i4 %11, 0
  br i1 %12, label %._crit_edge32, label %13

13:                                               ; preds = %8
  br i1 %.not2529, label %16, label %14

14:                                               ; preds = %13
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %16

16:                                               ; preds = %14, %13
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %2) #4
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull %1, ptr noundef nonnull %7)
  br label %17

17:                                               ; preds = %32, %16
  %.021 = phi i32 [ 0, %16 ], [ %.1, %32 ]
  %18 = load i32, ptr %1, align 16, !tbaa !5
  %.not26 = icmp eq i32 %18, 0
  br i1 %.not26, label %32, label %19

19:                                               ; preds = %17
  %20 = mul nsw i32 %18, 1000
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = mul nsw i32 %21, 100
  %23 = add nsw i32 %22, %20
  %24 = load i32, ptr %4, align 8, !tbaa !5
  %25 = mul nsw i32 %24, 10
  %26 = add nsw i32 %23, %25
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = add nsw i32 %26, %27
  %29 = sext i32 %.021 to i64
  %30 = getelementptr inbounds [24 x i32], ptr %2, i64 0, i64 %29
  store i32 %28, ptr %30, align 4, !tbaa !5
  %31 = add nsw i32 %.021, 1
  br label %32

32:                                               ; preds = %17, %19
  %.1 = phi i32 [ %31, %19 ], [ %.021, %17 ]
  %33 = call noundef zeroext i1 @_ZSt16next_permutationIPiEbT_S1_(ptr noundef nonnull %1, ptr noundef nonnull %7)
  br i1 %33, label %17, label %.preheader, !llvm.loop !9

.preheader:                                       ; preds = %32
  %34 = icmp sgt i32 %.1, 0
  br i1 %34, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %35 = zext nneg i32 %.1 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %46, %.preheader
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %2) #4
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %.not = icmp eq i32 %36, -1
  br i1 %.not, label %._crit_edge32, label %8, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph.preheader, %46
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %46 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = icmp eq i64 %indvars.iv.next, %35
  %38 = getelementptr inbounds [24 x i32], ptr %2, i64 0, i64 %indvars.iv
  %39 = load i32, ptr %38, align 4, !tbaa !5
  br i1 %37, label %46, label %40

40:                                               ; preds = %.lr.ph
  %41 = sdiv i32 %39, 1000
  %42 = getelementptr inbounds [24 x i32], ptr %2, i64 0, i64 %indvars.iv.next
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sdiv i32 %43, 1000
  %45 = icmp eq i32 %41, %44
  %.str.3..str.2 = select i1 %45, ptr @.str.3, ptr @.str.2
  br label %46

46:                                               ; preds = %40, %.lr.ph
  %.str.2.sink = phi ptr [ @.str.2, %.lr.ph ], [ %.str.3..str.2, %40 ]
  %47 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2.sink, i32 noundef %39)
  %exitcond.not = icmp eq i64 %indvars.iv.next, %35
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge32:                                    ; preds = %._crit_edge, %8, %0
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #4
  ret i32 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: 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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZSt16next_permutationIPiEbT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { inlinehint 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 #4 = { 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}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass