; LLVM IR from tangjz/acm-icpc :: self_training/2015-01-31 (D)

; 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
@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@cnt = external dso_local global [11 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca [10 x i8], align 1
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %8

8:                                                ; preds = %62, %0
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr @t, align 4, !tbaa !5
  %11 = icmp ne i32 %9, 0
  br i1 %11, label %12, label %63

12:                                               ; preds = %8
  call void @llvm.memset.p0.i64(ptr align 16 @cnt, i8 0, i64 88, i1 false)
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @q)
  br label %14

14:                                               ; preds = %61, %12
  %15 = load i32, ptr @q, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr @q, align 4, !tbaa !5
  %17 = icmp ne i32 %15, 0
  br i1 %17, label %18, label %62

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 10, ptr %4) #4
  %19 = getelementptr inbounds [10 x i8], ptr %4, i64 0, i64 0
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %19, ptr noundef %2, ptr noundef %3)
  %21 = getelementptr inbounds [10 x i8], ptr %4, i64 0, i64 0
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = icmp eq i32 %23, 80
  br i1 %24, label %25, label %33

25:                                               ; preds = %18
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [11 x i64], ptr @cnt, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !10
  %32 = add nsw i64 %31, %27
  store i64 %32, ptr %30, align 8, !tbaa !10
  br label %61

33:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %55, %33
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = icmp slt i32 %35, 11
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %34
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [11 x i64], ptr @cnt, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !10
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = sdiv i32 %43, %44
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sub nsw i32 %46, 1
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sdiv i32 %47, %48
  %50 = sub nsw i32 %45, %49
  %51 = sext i32 %50 to i64
  %52 = mul nsw i64 %42, %51
  %53 = load i64, ptr %5, align 8, !tbaa !10
  %54 = add nsw i64 %53, %52
  store i64 %54, ptr %5, align 8, !tbaa !10
  br label %55

55:                                               ; preds = %38
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %6, align 4, !tbaa !5
  br label %34, !llvm.loop !12

58:                                               ; preds = %37
  %59 = load i64, ptr %5, align 8, !tbaa !10
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %59)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %61

61:                                               ; preds = %58, %25
  call void @llvm.lifetime.end.p0(i64 10, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %14, !llvm.loop !14

62:                                               ; preds = %14
  br label %8, !llvm.loop !15

63:                                               ; preds = %8
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

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 nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


; 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
@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@cnt = external dso_local local_unnamed_addr global [11 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [10 x i8], align 1
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %5 = load i32, ptr @t, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !5
  %.not12 = icmp eq i32 %5, 0
  br i1 %.not12, label %._crit_edge, label %.lr.ph13

.loopexit:                                        ; preds = %84, %.lr.ph13
  %7 = load i32, ptr @t, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph13, !llvm.loop !9

.lr.ph13:                                         ; preds = %0, %.loopexit
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(88) @cnt, i8 0, i64 88, i1 false)
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @q)
  %10 = load i32, ptr @q, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr @q, align 4, !tbaa !5
  %.not811 = icmp eq i32 %10, 0
  br i1 %.not811, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph13, %84
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 10, ptr nonnull %3) #4
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %3, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %13 = load i8, ptr %3, align 1, !tbaa !11
  %14 = icmp eq i8 %13, 80
  %15 = load i32, ptr %2, align 4, !tbaa !5
  br i1 %14, label %77, label %.preheader

.preheader:                                       ; preds = %.lr.ph
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = add nsw i32 %16, -1
  %18 = load i64, ptr getelementptr inbounds (i8, ptr @cnt, i64 8), align 8, !tbaa !12
  %19 = sub nsw i32 %15, %17
  %20 = sext i32 %19 to i64
  %21 = mul nsw i64 %18, %20
  %22 = load i64, ptr getelementptr inbounds (i8, ptr @cnt, i64 16), align 16, !tbaa !12
  %23 = sdiv i32 %15, 2
  %.neg = sdiv i32 %17, -2
  %24 = add nsw i32 %.neg, %23
  %25 = sext i32 %24 to i64
  %26 = mul nsw i64 %22, %25
  %27 = add nsw i64 %26, %21
  %28 = load i64, ptr getelementptr inbounds (i8, ptr @cnt, i64 24), align 8, !tbaa !12
  %29 = sdiv i32 %15, 3
  %.neg15 = sdiv i32 %17, -3
  %30 = add nsw i32 %.neg15, %29
  %31 = sext i32 %30 to i64
  %32 = mul nsw i64 %28, %31
  %33 = add nsw i64 %32, %27
  %34 = load i64, ptr getelementptr inbounds (i8, ptr @cnt, i64 32), align 16, !tbaa !12
  %35 = sdiv i32 %15, 4
  %.neg16 = sdiv i32 %17, -4
  %36 = add nsw i32 %.neg16, %35
  %37 = sext i32 %36 to i64
  %38 = mul nsw i64 %34, %37
  %39 = add nsw i64 %38, %33
  %40 = load i64, ptr getelementptr inbounds (i8, ptr @cnt, i64 40), align 8, !tbaa !12
  %41 = sdiv i32 %15, 5
  %.neg17 = sdiv i32 %17, -5
  %42 = add nsw i32 %.neg17, %41
  %43 = sext i32 %42 to i64
  %44 = mul nsw i64 %40, %43
  %45 = add nsw i64 %44, %39
  %46 = load i64, ptr getelementptr inbounds (i8, ptr @cnt, i64 48), align 16, !tbaa !12
  %47 = sdiv i32 %15, 6
  %.neg18 = sdiv i32 %17, -6
  %48 = add nsw i32 %.neg18, %47
  %49 = sext i32 %48 to i64
  %50 = mul nsw i64 %46, %49
  %51 = add nsw i64 %50, %45
  %52 = load i64, ptr getelementptr inbounds (i8, ptr @cnt, i64 56), align 8, !tbaa !12
  %53 = sdiv i32 %15, 7
  %.neg19 = sdiv i32 %17, -7
  %54 = add nsw i32 %.neg19, %53
  %55 = sext i32 %54 to i64
  %56 = mul nsw i64 %52, %55
  %57 = add nsw i64 %56, %51
  %58 = load i64, ptr getelementptr inbounds (i8, ptr @cnt, i64 64), align 16, !tbaa !12
  %59 = sdiv i32 %15, 8
  %.neg20 = sdiv i32 %17, -8
  %60 = add nsw i32 %.neg20, %59
  %61 = sext i32 %60 to i64
  %62 = mul nsw i64 %58, %61
  %63 = add nsw i64 %62, %57
  %64 = load i64, ptr getelementptr inbounds (i8, ptr @cnt, i64 72), align 8, !tbaa !12
  %65 = sdiv i32 %15, 9
  %.neg21 = sdiv i32 %17, -9
  %66 = add nsw i32 %.neg21, %65
  %67 = sext i32 %66 to i64
  %68 = mul nsw i64 %64, %67
  %69 = add nsw i64 %68, %63
  %70 = load i64, ptr getelementptr inbounds (i8, ptr @cnt, i64 80), align 16, !tbaa !12
  %71 = sdiv i32 %15, 10
  %.neg22 = sdiv i32 %17, -10
  %72 = add nsw i32 %.neg22, %71
  %73 = sext i32 %72 to i64
  %74 = mul nsw i64 %70, %73
  %75 = add nsw i64 %74, %69
  %76 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %75)
  br label %84

77:                                               ; preds = %.lr.ph
  %78 = sext i32 %15 to i64
  %79 = load i32, ptr %1, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [11 x i64], ptr @cnt, i64 0, i64 %80
  %82 = load i64, ptr %81, align 8, !tbaa !12
  %83 = add nsw i64 %82, %78
  store i64 %83, ptr %81, align 8, !tbaa !12
  br label %84

84:                                               ; preds = %.preheader, %77
  call void @llvm.lifetime.end.p0(i64 10, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %85 = load i32, ptr @q, align 4, !tbaa !5
  %86 = add nsw i32 %85, -1
  store i32 %86, ptr @q, align 4, !tbaa !5
  %.not8 = icmp eq i32 %85, 0
  br i1 %.not8, label %.loopexit, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

; 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" }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !10}


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