; LLVM IR from tangjz/acm-icpc :: TDL_training/2016-03-20 (H - Technical support - tjz)

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

@a = external dso_local global i32, align 4
@flag = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@val = external dso_local global [200001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = 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 i32, align 4
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @a)
  %4 = load i32, ptr @a, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  store i32 %5, ptr @a, align 4, !tbaa !5
  %6 = load i32, ptr @a, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %10

8:                                                ; preds = %0
  %9 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  br label %90

10:                                               ; preds = %0
  %11 = load i32, ptr @a, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %13, label %16

13:                                               ; preds = %10
  %14 = load i32, ptr @a, align 4, !tbaa !5
  %15 = sub nsw i32 0, %14
  store i32 %15, ptr @a, align 4, !tbaa !5
  store i32 1, ptr @flag, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %13, %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %73, %16
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = load i32, ptr @a, align 4, !tbaa !5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sdiv i32 %19, %20
  %22 = icmp sle i32 %18, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %76

24:                                               ; preds = %17
  %25 = load i32, ptr @a, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = srem i32 %25, %26
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %72

29:                                               ; preds = %24
  %30 = load i32, ptr @flag, align 4, !tbaa !5
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %51

32:                                               ; preds = %29
  %33 = load i32, ptr @a, align 4, !tbaa !5
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sdiv i32 %33, %34
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sub nsw i32 %35, %36
  %38 = load i32, ptr @tot, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr @tot, align 4, !tbaa !5
  %40 = sext i32 %38 to i64
  %41 = getelementptr inbounds [200001 x i32], ptr @val, i64 0, i64 %40
  store i32 %37, ptr %41, align 4, !tbaa !5
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = load i32, ptr @a, align 4, !tbaa !5
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sdiv i32 %43, %44
  %46 = sub nsw i32 %42, %45
  %47 = load i32, ptr @tot, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr @tot, align 4, !tbaa !5
  %49 = sext i32 %47 to i64
  %50 = getelementptr inbounds [200001 x i32], ptr @val, i64 0, i64 %49
  store i32 %46, ptr %50, align 4, !tbaa !5
  br label %71

51:                                               ; preds = %29
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = load i32, ptr @a, align 4, !tbaa !5
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = sdiv i32 %53, %54
  %56 = add nsw i32 %52, %55
  %57 = load i32, ptr @tot, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr @tot, align 4, !tbaa !5
  %59 = sext i32 %57 to i64
  %60 = getelementptr inbounds [200001 x i32], ptr @val, i64 0, i64 %59
  store i32 %56, ptr %60, align 4, !tbaa !5
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = sub nsw i32 0, %61
  %63 = load i32, ptr @a, align 4, !tbaa !5
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = sdiv i32 %63, %64
  %66 = sub nsw i32 %62, %65
  %67 = load i32, ptr @tot, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr @tot, align 4, !tbaa !5
  %69 = sext i32 %67 to i64
  %70 = getelementptr inbounds [200001 x i32], ptr @val, i64 0, i64 %69
  store i32 %66, ptr %70, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %51, %32
  br label %72

72:                                               ; preds = %71, %24
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %2, align 4, !tbaa !5
  br label %17, !llvm.loop !9

76:                                               ; preds = %23
  %77 = load i32, ptr @tot, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i32, ptr @val, i64 %78
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @val, ptr noundef %79)
  %80 = load i32, ptr @tot, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i32, ptr @val, i64 %81
  %83 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef @val, ptr noundef %82)
  %84 = ptrtoint ptr %83 to i64
  %85 = sub i64 %84, ptrtoint (ptr @val to i64)
  %86 = sdiv exact i64 %85, 4
  %87 = trunc i64 %86 to i32
  store i32 %87, ptr @tot, align 4, !tbaa !5
  %88 = load i32, ptr @tot, align 4, !tbaa !5
  %89 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %88)
  store i32 0, ptr %1, align 4
  br label %90

90:                                               ; preds = %76, %8
  %91 = load i32, ptr %1, align 4
  ret i32 %91
}

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

declare i32 @puts(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

; 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 ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef, ptr noundef) #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 nosync nounwind willreturn memory(argmem: readwrite) }
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"}


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

@a = external dso_local global i32, align 4
@flag = external dso_local local_unnamed_addr global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@val = external dso_local global [200001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = 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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @a)
  %2 = load i32, ptr @a, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @a, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %5, label %7

5:                                                ; preds = %0
  %6 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %58

7:                                                ; preds = %0
  %8 = icmp slt i32 %2, -1
  br i1 %8, label %.thread, label %.lr.ph

.thread:                                          ; preds = %7
  %9 = xor i32 %2, -1
  store i32 %9, ptr @a, align 4, !tbaa !5
  store i32 1, ptr @flag, align 4, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %7, %.thread
  %10 = phi i32 [ %9, %.thread ], [ %3, %7 ]
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  %11 = load i32, ptr @flag, align 4
  %.fr = freeze i32 %11
  %.not16 = icmp eq i32 %.fr, 0
  br i1 %.not16, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %25
  %12 = phi i32 [ %28, %25 ], [ %10, %.lr.ph ]
  %.018.us = phi i32 [ %27, %25 ], [ 1, %.lr.ph ]
  %13 = phi i32 [ %26, %25 ], [ %tot.promoted, %.lr.ph ]
  %14 = urem i32 %10, %.018.us
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %25

16:                                               ; preds = %.lr.ph.split.us
  %17 = add i32 %12, %.018.us
  %18 = add nsw i32 %13, 1
  %19 = sext i32 %13 to i64
  %20 = getelementptr inbounds [200001 x i32], ptr @val, i64 0, i64 %19
  store i32 %17, ptr %20, align 4, !tbaa !5
  %21 = sub i32 0, %17
  %22 = add nsw i32 %13, 2
  store i32 %22, ptr @tot, align 4, !tbaa !5
  %23 = sext i32 %18 to i64
  %24 = getelementptr inbounds [200001 x i32], ptr @val, i64 0, i64 %23
  store i32 %21, ptr %24, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %16, %.lr.ph.split.us
  %26 = phi i32 [ %13, %.lr.ph.split.us ], [ %22, %16 ]
  %27 = add nuw nsw i32 %.018.us, 1
  %28 = udiv i32 %10, %27
  %.not.us.not = icmp ult i32 %.018.us, %28
  br i1 %.not.us.not, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %54, %25
  %29 = phi i32 [ %26, %25 ], [ %55, %54 ]
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr @val, i64 %30
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @val, ptr noundef nonnull %31)
  %32 = load i32, ptr @tot, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr @val, i64 %33
  %35 = tail call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef nonnull @val, ptr noundef nonnull %34)
  %36 = ptrtoint ptr %35 to i64
  %37 = sub i64 %36, ptrtoint (ptr @val to i64)
  %38 = lshr exact i64 %37, 2
  %39 = trunc i64 %38 to i32
  store i32 %39, ptr @tot, align 4, !tbaa !5
  %40 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %39)
  br label %58

.lr.ph.split:                                     ; preds = %.lr.ph, %54
  %41 = phi i32 [ %57, %54 ], [ %10, %.lr.ph ]
  %.018 = phi i32 [ %56, %54 ], [ 1, %.lr.ph ]
  %42 = phi i32 [ %55, %54 ], [ %tot.promoted, %.lr.ph ]
  %43 = urem i32 %10, %.018
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %54

45:                                               ; preds = %.lr.ph.split
  %46 = sub nsw i32 %41, %.018
  %47 = add nsw i32 %42, 1
  %48 = sext i32 %42 to i64
  %49 = getelementptr inbounds [200001 x i32], ptr @val, i64 0, i64 %48
  store i32 %46, ptr %49, align 4, !tbaa !5
  %50 = sub nsw i32 %.018, %41
  %51 = add nsw i32 %42, 2
  store i32 %51, ptr @tot, align 4, !tbaa !5
  %52 = sext i32 %47 to i64
  %53 = getelementptr inbounds [200001 x i32], ptr @val, i64 0, i64 %52
  store i32 %50, ptr %53, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %.lr.ph.split, %45
  %55 = phi i32 [ %42, %.lr.ph.split ], [ %51, %45 ]
  %56 = add nuw nsw i32 %.018, 1
  %57 = udiv i32 %10, %56
  %.not.not = icmp ult i32 %.018, %57
  br i1 %.not.not, label %.lr.ph.split, label %._crit_edge, !llvm.loop !9

58:                                               ; preds = %._crit_edge, %5
  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 @puts(ptr nocapture noundef readonly) local_unnamed_addr #1

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 = { 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" }

!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: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass