; LLVM IR from tangjz/acm-icpc :: hdu (6211)

; 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
@cnt = external dso_local global [131073 x i32], align 16
@k = 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 [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsxxx(i64 noundef, i64 noundef, i64 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 norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 4194304, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = call noalias ptr @malloc(i64 noundef %12) #7
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %13, i64 %15
  store ptr %16, ptr %3, align 8, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !9
  call void asm sideeffect "movq $0, %rsp\0A", "r,~{dirflag},~{fpsr},~{flags}"(ptr %17) #6, !srcloc !11
  call void @_Z3dfsxxx(i64 noundef 3, i64 noundef 4, i64 noundef 5)
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %19

19:                                               ; preds = %61, %0
  %20 = load i32, ptr @t, align 4, !tbaa !5
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr @t, align 4, !tbaa !5
  %22 = icmp ne i32 %20, 0
  br i1 %22, label %23, label %64

23:                                               ; preds = %19
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @k)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  store i64 0, ptr %4, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %25 = load i32, ptr @k, align 4, !tbaa !5
  %26 = shl i32 1, %25
  store i32 %26, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  br label %27

27:                                               ; preds = %58, %23
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 4, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %61

32:                                               ; preds = %27
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %7)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store i64 0, ptr %9, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %34 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %34, ptr %10, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %47, %32
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = icmp slt i32 %36, 131073
  br i1 %37, label %39, label %38

38:                                               ; preds = %35
  store i32 7, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %51

39:                                               ; preds = %35
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [131073 x i32], ptr @cnt, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = load i64, ptr %9, align 8, !tbaa !12
  %46 = add nsw i64 %45, %44
  store i64 %46, ptr %9, align 8, !tbaa !12
  br label %47

47:                                               ; preds = %39
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = add nsw i32 %49, %48
  store i32 %50, ptr %10, align 4, !tbaa !5
  br label %35, !llvm.loop !14

51:                                               ; preds = %38
  %52 = load i64, ptr %9, align 8, !tbaa !12
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = mul nsw i64 %52, %54
  %56 = load i64, ptr %4, align 8, !tbaa !12
  %57 = add nsw i64 %56, %55
  store i64 %57, ptr %4, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %58

58:                                               ; preds = %51
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %5, align 4, !tbaa !5
  br label %27, !llvm.loop !16

61:                                               ; preds = %31
  %62 = load i64, ptr %4, align 8, !tbaa !12
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %62)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  br label %19, !llvm.loop !17

64:                                               ; preds = %19
  call void @exit(i32 noundef 0) #8
  unreachable
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #5

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nounwind allocsize(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 = { "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 = { noreturn 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { noreturn 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{i64 593}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


; 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
@cnt = external dso_local local_unnamed_addr global [131073 x i32], align 16
@k = 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 [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsxxx(i64 noundef, i64 noundef, i64 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 norecurse noreturn uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = tail call noalias dereferenceable_or_null(4194304) ptr @malloc(i64 noundef 4194304) #7
  %3 = getelementptr inbounds i8, ptr %2, i64 4194304
  tail call void asm sideeffect "movq $0, %rsp\0A", "r,~{dirflag},~{fpsr},~{flags}"(ptr nonnull %3) #8, !srcloc !5
  tail call void @_Z3dfsxxx(i64 noundef 3, i64 noundef 4, i64 noundef 5)
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %5 = load i32, ptr @t, align 4, !tbaa !6
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !6
  %.not26 = icmp eq i32 %5, 0
  br i1 %.not26, label %._crit_edge29, label %.lr.ph28

.lr.ph28:                                         ; preds = %0, %._crit_edge24
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @k)
  %8 = load i32, ptr @k, align 4, !tbaa !6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #8
  %.not30 = icmp eq i32 %8, 31
  br i1 %.not30, label %._crit_edge24, label %.lr.ph23.preheader

.lr.ph23.preheader:                               ; preds = %.lr.ph28
  %9 = shl nuw nsw i32 1, %8
  %10 = zext nneg i32 %9 to i64
  %wide.trip.count = zext nneg i32 %9 to i64
  %11 = zext nneg i32 %8 to i64
  %ident.check.not = icmp eq i32 %8, 0
  br label %.lr.ph23

._crit_edge24:                                    ; preds = %._crit_edge, %.lr.ph28
  %.015.lcssa = phi i64 [ 0, %.lr.ph28 ], [ %36, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #8
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.015.lcssa)
  %13 = load i32, ptr @t, align 4, !tbaa !6
  %14 = add nsw i32 %13, -1
  store i32 %14, ptr @t, align 4, !tbaa !6
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %._crit_edge29, label %.lr.ph28, !llvm.loop !10

.lr.ph23:                                         ; preds = %.lr.ph23.preheader, %._crit_edge
  %indvars.iv = phi i64 [ 0, %.lr.ph23.preheader ], [ %indvars.iv.next, %._crit_edge ]
  %.01521 = phi i64 [ 0, %.lr.ph23.preheader ], [ %36, %._crit_edge ]
  %indvars35 = trunc i64 %indvars.iv to i32
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %16 = icmp ult i32 %indvars35, 131073
  br i1 %16, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph23
  %17 = add nuw nsw i64 %indvars.iv, %10
  %18 = icmp ult i64 %17, 131073
  %umin = zext i1 %18 to i64
  %19 = add nuw nsw i64 %indvars.iv, %10
  %umax = call i64 @llvm.umax.i64(i64 %17, i64 131073)
  %20 = add nuw i64 %19, %umin
  %21 = sub i64 %umax, %20
  %22 = select i1 %18, i64 2, i64 1
  %23 = lshr i64 %21, %11
  %24 = add i64 %22, %23
  %min.iters.check = icmp ugt i64 %24, 3
  %or.cond = and i1 %min.iters.check, %ident.check.not
  br i1 %or.cond, label %vector.ph, label %.lr.ph.preheader41

.lr.ph.preheader41:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv32.ph = phi i64 [ %indvars.iv, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.01418.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %32, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %24, -4
  %ind.end = add i64 %indvars.iv, %n.vec
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %29, %vector.body ]
  %vec.phi39 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %30, %vector.body ]
  %offset.idx = add i64 %indvars.iv, %index
  %25 = getelementptr inbounds [131073 x i32], ptr @cnt, i64 0, i64 %offset.idx
  %26 = getelementptr inbounds i8, ptr %25, i64 8
  %wide.load = load <2 x i32>, ptr %25, align 4, !tbaa !6
  %wide.load40 = load <2 x i32>, ptr %26, align 4, !tbaa !6
  %27 = sext <2 x i32> %wide.load to <2 x i64>
  %28 = sext <2 x i32> %wide.load40 to <2 x i64>
  %29 = add <2 x i64> %vec.phi, %27
  %30 = add <2 x i64> %vec.phi39, %28
  %index.next = add nuw i64 %index, 4
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !12

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %30, %29
  %32 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %24, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader41

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %.lr.ph23
  %.014.lcssa = phi i64 [ 0, %.lr.ph23 ], [ %32, %middle.block ], [ %40, %.lr.ph ]
  %33 = load i32, ptr %1, align 4, !tbaa !6
  %34 = sext i32 %33 to i64
  %35 = mul nsw i64 %.014.lcssa, %34
  %36 = add nsw i64 %35, %.01521
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge24, label %.lr.ph23, !llvm.loop !15

.lr.ph:                                           ; preds = %.lr.ph.preheader41, %.lr.ph
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %.lr.ph ], [ %indvars.iv32.ph, %.lr.ph.preheader41 ]
  %.01418 = phi i64 [ %40, %.lr.ph ], [ %.01418.ph, %.lr.ph.preheader41 ]
  %37 = getelementptr inbounds [131073 x i32], ptr @cnt, i64 0, i64 %indvars.iv32
  %38 = load i32, ptr %37, align 4, !tbaa !6
  %39 = sext i32 %38 to i64
  %40 = add nsw i64 %.01418, %39
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, %10
  %41 = icmp ult i64 %indvars.iv.next33, 131073
  br i1 %41, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge29:                                    ; preds = %._crit_edge24, %0
  call void @exit(i32 noundef 0) #9
  unreachable
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #5

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #6

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #6

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress norecurse noreturn 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 #5 = { noreturn 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 #6 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { nounwind }
attributes #9 = { noreturn 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 = !{i64 593}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11, !13, !14}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !11}
!16 = distinct !{!16, !11, !13}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass