; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-12-02 (E - Wow! Such Precision! - 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"

@ans = external dso_local global [66 x ptr], align 16
@n = external dso_local global i32, align 4
@.str.66 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.67 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.68 = external hidden unnamed_addr constant [108 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [11 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
  store i32 0, ptr %1, align 4
  br label %4

4:                                                ; preds = %44, %0
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.66, ptr noundef @n)
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %7, label %45

7:                                                ; preds = %4
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp sle i32 0, %8
  br i1 %9, label %10, label %13

10:                                               ; preds = %7
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp sle i32 %11, 10
  br label %13

13:                                               ; preds = %10, %7
  %14 = phi i1 [ false, %7 ], [ %12, %10 ]
  br i1 %14, label %15, label %16

15:                                               ; preds = %13
  br label %18

16:                                               ; preds = %13
  call void @__assert_fail(ptr noundef @.str.67, ptr noundef @.str.68, i32 noundef 75, ptr noundef @__PRETTY_FUNCTION__.main) #4
  unreachable

17:                                               ; No predecessors!
  br label %18

18:                                               ; preds = %17, %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  %22 = mul nsw i32 %19, %21
  %23 = ashr i32 %22, 1
  store i32 %23, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = add nsw i32 %26, 2
  %28 = mul nsw i32 %25, %27
  %29 = ashr i32 %28, 1
  store i32 %29, ptr %3, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %41, %18
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %44

35:                                               ; preds = %30
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [66 x ptr], ptr @ans, i64 0, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = call i32 @puts(ptr noundef %39)
  br label %41

41:                                               ; preds = %35
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %2, align 4, !tbaa !5
  br label %30, !llvm.loop !11

44:                                               ; preds = %34
  br label %4, !llvm.loop !13

45:                                               ; preds = %4
  ret i32 0
}

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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

declare i32 @puts(ptr noundef) #1

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

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 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { noreturn nounwind }
attributes #5 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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"

@ans = external dso_local local_unnamed_addr global [66 x ptr], align 16
@n = external dso_local global i32, align 4
@.str.66 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.67 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.68 = external hidden unnamed_addr constant [108 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.66, ptr noundef nonnull @n)
  %2 = icmp eq i32 %1, 1
  br i1 %2, label %.lr.ph6, label %._crit_edge

.loopexit:                                        ; preds = %.lr.ph, %8
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.66, ptr noundef nonnull @n)
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %.lr.ph6, label %._crit_edge, !llvm.loop !5

.lr.ph6:                                          ; preds = %0, %.loopexit
  %5 = load i32, ptr @n, align 4
  %6 = icmp ult i32 %5, 11
  br i1 %6, label %8, label %7

7:                                                ; preds = %.lr.ph6
  tail call void @__assert_fail(ptr noundef nonnull @.str.67, ptr noundef nonnull @.str.68, i32 noundef 75, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #3
  unreachable

8:                                                ; preds = %.lr.ph6
  %9 = add nuw nsw i32 %5, 1
  %10 = mul nuw nsw i32 %9, %5
  %11 = lshr i32 %10, 1
  %12 = add nuw nsw i32 %5, 2
  %13 = mul nuw nsw i32 %9, %12
  %14 = lshr i32 %13, 1
  %15 = icmp ult i32 %11, %14
  br i1 %15, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %8
  %16 = lshr i32 %10, 1
  %17 = zext nneg i32 %16 to i64
  %18 = add nuw nsw i32 %14, %16
  %19 = sub nsw i32 %18, %11
  %wide.trip.count = zext i32 %19 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %17, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %20 = getelementptr inbounds [66 x ptr], ptr @ans, i64 0, i64 %indvars.iv
  %21 = load ptr, ptr %20, align 8, !tbaa !7
  %22 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %21)
  %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 %.loopexit, label %.lr.ph, !llvm.loop !11

._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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress 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 = { 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 #3 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass