; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-11-15 (F - Illegal spices - dby)

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

@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@a = external dso_local global [100030 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

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

8:                                                ; preds = %96, %0
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @k, ptr noundef @p)
  %10 = icmp ne i32 %9, -1
  br i1 %10, label %11, label %97

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 2, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %23, %11
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = load i32, ptr @n, align 4, !tbaa !9
  %15 = load i32, ptr @k, align 4, !tbaa !9
  %16 = sub nsw i32 %14, %15
  %17 = icmp slt i32 %13, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %26

19:                                               ; preds = %12
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100030 x i32], ptr @a, i64 0, i64 %21
  store i32 1, ptr %22, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %19
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %5, align 4, !tbaa !9
  br label %12, !llvm.loop !11

26:                                               ; preds = %18
  %27 = load i32, ptr @n, align 4, !tbaa !9
  %28 = load i32, ptr @k, align 4, !tbaa !9
  %29 = sub nsw i32 %27, %28
  store i32 %29, ptr %3, align 4, !tbaa !9
  %30 = load i32, ptr @n, align 4, !tbaa !9
  %31 = load i32, ptr @k, align 4, !tbaa !9
  %32 = sub nsw i32 %30, %31
  %33 = sext i32 %32 to i64
  store i64 %33, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %34 = load i32, ptr @n, align 4, !tbaa !9
  %35 = load i32, ptr @k, align 4, !tbaa !9
  %36 = sub nsw i32 %34, %35
  store i32 %36, ptr %6, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %69, %26
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = load i32, ptr @n, align 4, !tbaa !9
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %42, label %41

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

42:                                               ; preds = %37
  %43 = load i32, ptr %3, align 4, !tbaa !9
  %44 = mul nsw i32 %43, 100
  %45 = load i32, ptr @p, align 4, !tbaa !9
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = mul nsw i32 %45, %46
  %48 = icmp slt i32 %44, %47
  br i1 %48, label %49, label %56

49:                                               ; preds = %42
  %50 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %50, ptr %3, align 4, !tbaa !9
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %4, align 4, !tbaa !9
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100030 x i32], ptr @a, i64 0, i64 %54
  store i32 %52, ptr %55, align 4, !tbaa !9
  br label %61

56:                                               ; preds = %42
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100030 x i32], ptr @a, i64 0, i64 %59
  store i32 %57, ptr %60, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %56, %49
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [100030 x i32], ptr @a, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = load i64, ptr %2, align 8, !tbaa !5
  %68 = add nsw i64 %67, %66
  store i64 %68, ptr %2, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %61
  %70 = load i32, ptr %6, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %6, align 4, !tbaa !9
  br label %37, !llvm.loop !13

72:                                               ; preds = %41
  %73 = load i64, ptr %2, align 8, !tbaa !5
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %73)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %93, %72
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = load i32, ptr @n, align 4, !tbaa !9
  %78 = icmp slt i32 %76, %77
  br i1 %78, label %80, label %79

79:                                               ; preds = %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %96

80:                                               ; preds = %75
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [100030 x i32], ptr @a, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !9
  %85 = load i32, ptr %7, align 4, !tbaa !9
  %86 = load i32, ptr @n, align 4, !tbaa !9
  %87 = sub nsw i32 %86, 1
  %88 = icmp slt i32 %85, %87
  %89 = zext i1 %88 to i64
  %90 = select i1 %88, i8 32, i8 10
  %91 = sext i8 %90 to i32
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %84, i32 noundef %91)
  br label %93

93:                                               ; preds = %80
  %94 = load i32, ptr %7, align 4, !tbaa !9
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %7, align 4, !tbaa !9
  br label %75, !llvm.loop !14

96:                                               ; preds = %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %8, !llvm.loop !15

97:                                               ; preds = %8
  ret i32 0
}

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

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

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

declare i32 @printf(ptr noundef, ...) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


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

@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@a = external dso_local local_unnamed_addr global [100030 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @k, ptr noundef nonnull @p)
  %.not41 = icmp eq i32 %1, -1
  br i1 %.not41, label %._crit_edge42, label %.preheader

.loopexit:                                        ; preds = %.lr.ph40, %._crit_edge36
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @k, ptr noundef nonnull @p)
  %.not = icmp eq i32 %2, -1
  br i1 %.not, label %._crit_edge42, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %0, %.loopexit
  %3 = load i32, ptr @n, align 4, !tbaa !7
  %4 = load i32, ptr @k, align 4, !tbaa !7
  %5 = sub nsw i32 %3, %4
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %5 to i64
  %min.iters.check = icmp ult i32 %5, 8
  br i1 %min.iters.check, label %.lr.ph.preheader50, label %vector.ph

.lr.ph.preheader50:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 2147483640
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %7 = getelementptr inbounds [100030 x i32], ptr @a, i64 0, i64 %index
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %7, align 16, !tbaa !7
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %8, align 16, !tbaa !7
  %index.next = add nuw i64 %index, 8
  %9 = icmp eq i64 %index.next, %n.vec
  br i1 %9, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader50

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %.preheader
  %10 = sext i32 %5 to i64
  %11 = icmp sgt i32 %4, 0
  br i1 %11, label %.lr.ph35, label %._crit_edge36

.lr.ph35:                                         ; preds = %._crit_edge
  %12 = load i32, ptr @p, align 4, !tbaa !7
  %13 = sext i32 %12 to i64
  %14 = sext i32 %3 to i64
  br label %19

.lr.ph:                                           ; preds = %.lr.ph.preheader50, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader50 ]
  %15 = getelementptr inbounds [100030 x i32], ptr @a, i64 0, i64 %indvars.iv
  store i32 1, ptr %15, align 4, !tbaa !7
  %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_edge, label %.lr.ph, !llvm.loop !14

._crit_edge36:                                    ; preds = %19, %._crit_edge
  %.024.lcssa = phi i64 [ %10, %._crit_edge ], [ %28, %19 ]
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.024.lcssa)
  %17 = load i32, ptr @n, align 4, !tbaa !7
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph40, label %.loopexit

19:                                               ; preds = %.lr.ph35, %19
  %indvars.iv44 = phi i64 [ %10, %.lr.ph35 ], [ %indvars.iv.next45, %19 ]
  %.02132 = phi i32 [ 2, %.lr.ph35 ], [ %.02132.sink, %19 ]
  %.02231 = phi i32 [ %5, %.lr.ph35 ], [ %.123, %19 ]
  %.02430 = phi i64 [ %10, %.lr.ph35 ], [ %28, %19 ]
  %20 = mul nsw i32 %.02231, 100
  %21 = mul nsw i64 %indvars.iv44, %13
  %22 = sext i32 %20 to i64
  %23 = icmp sgt i64 %21, %22
  %24 = trunc nsw i64 %indvars.iv44 to i32
  %25 = zext i1 %23 to i32
  %.02132.sink = add nuw nsw i32 %.02132, %25
  %.123 = select i1 %23, i32 %24, i32 %.02231
  %26 = getelementptr inbounds [100030 x i32], ptr @a, i64 0, i64 %indvars.iv44
  store i32 %.02132.sink, ptr %26, align 4
  %27 = zext nneg i32 %.02132.sink to i64
  %28 = add nsw i64 %.02430, %27
  %indvars.iv.next45 = add nsw i64 %indvars.iv44, 1
  %29 = icmp slt i64 %indvars.iv.next45, %14
  br i1 %29, label %19, label %._crit_edge36, !llvm.loop !15

.lr.ph40:                                         ; preds = %._crit_edge36, %.lr.ph40
  %indvars.iv47 = phi i64 [ %indvars.iv.next48, %.lr.ph40 ], [ 0, %._crit_edge36 ]
  %30 = phi i32 [ %38, %.lr.ph40 ], [ %17, %._crit_edge36 ]
  %31 = getelementptr inbounds [100030 x i32], ptr @a, i64 0, i64 %indvars.iv47
  %32 = load i32, ptr %31, align 4, !tbaa !7
  %33 = add nsw i32 %30, -1
  %34 = sext i32 %33 to i64
  %35 = icmp slt i64 %indvars.iv47, %34
  %36 = select i1 %35, i32 32, i32 10
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %32, i32 noundef %36)
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %38 = load i32, ptr @n, align 4, !tbaa !7
  %39 = sext i32 %38 to i64
  %40 = icmp slt i64 %indvars.iv.next48, %39
  br i1 %40, label %.lr.ph40, label %.loopexit, !llvm.loop !16

._crit_edge42:                                    ; preds = %.loopexit, %0
  ret i32 0
}

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

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

attributes #0 = { mustprogress nofree 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 #1 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6, !12, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !6, !13, !12}
!15 = distinct !{!15, !6}
!16 = distinct !{!16, !6}


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