; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/1988.ll (Z5solvev)

; 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
@a = external dso_local global [35 x i32], align 16
@ans = external dso_local global [110 x i32], align 16
@num = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4findi(i32 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 nounwind uwtable
declare dso_local void @_Z6changei(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5solvev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr @num, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %3 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %3, ptr %2, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %62, %0
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = icmp sge i32 %5, 1
  br i1 %6, label %8, label %7

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

8:                                                ; preds = %4
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [35 x i32], ptr @a, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %8
  br label %62

16:                                               ; preds = %8
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = call noundef i32 @_Z4findi(i32 noundef %17)
  store i32 %18, ptr %1, align 4, !tbaa !5
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = icmp ne i32 %19, 1
  br i1 %20, label %21, label %28

21:                                               ; preds = %16
  %22 = load i32, ptr %1, align 4, !tbaa !5
  call void @_Z6changei(i32 noundef %22)
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = load i32, ptr @num, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @num, align 4, !tbaa !5
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [110 x i32], ptr @ans, i64 0, i64 %26
  store i32 %23, ptr %27, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %21, %16
  %29 = load i32, ptr getelementptr inbounds ([35 x i32], ptr @a, i64 0, i64 1), align 4, !tbaa !5
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %31, label %38

31:                                               ; preds = %28
  %32 = load i32, ptr @num, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @num, align 4, !tbaa !5
  %34 = sext i32 %32 to i64
  %35 = getelementptr inbounds [110 x i32], ptr @ans, i64 0, i64 %34
  store i32 1, ptr %35, align 4, !tbaa !5
  %36 = load i32, ptr getelementptr inbounds ([35 x i32], ptr @a, i64 0, i64 1), align 4, !tbaa !5
  %37 = sub nsw i32 0, %36
  store i32 %37, ptr getelementptr inbounds ([35 x i32], ptr @a, i64 0, i64 1), align 4, !tbaa !5
  br label %38

38:                                               ; preds = %31, %28
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = icmp ne i32 %39, 1
  br i1 %40, label %41, label %48

41:                                               ; preds = %38
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = load i32, ptr @num, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr @num, align 4, !tbaa !5
  %45 = sext i32 %43 to i64
  %46 = getelementptr inbounds [110 x i32], ptr @ans, i64 0, i64 %45
  store i32 %42, ptr %46, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z6changei(i32 noundef %47)
  br label %61

48:                                               ; preds = %38
  %49 = load i32, ptr @num, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr @num, align 4, !tbaa !5
  %51 = sext i32 %49 to i64
  %52 = getelementptr inbounds [110 x i32], ptr @ans, i64 0, i64 %51
  store i32 1, ptr %52, align 4, !tbaa !5
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [35 x i32], ptr @a, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sub nsw i32 0, %56
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [35 x i32], ptr @a, i64 0, i64 %59
  store i32 %57, ptr %60, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %48, %41
  br label %62

62:                                               ; preds = %61, %15
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = add nsw i32 %63, -1
  store i32 %64, ptr %2, align 4, !tbaa !5
  br label %4, !llvm.loop !9

65:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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"

@n = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [35 x i32], align 16
@ans = external dso_local local_unnamed_addr global [110 x i32], align 16
@num = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4findi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6changei(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 {
  store i32 0, ptr @num, align 4, !tbaa !5
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %3 = zext nneg i32 %1 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %38, %.thread, %0
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %38
  %indvars.iv = phi i64 [ %3, %.lr.ph.preheader ], [ %indvars.iv.next, %38 ]
  %4 = getelementptr inbounds [35 x i32], ptr @a, i64 0, i64 %indvars.iv
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = zext i32 %5 to i64
  %7 = icmp eq i64 %indvars.iv, %6
  br i1 %7, label %38, label %8

8:                                                ; preds = %.lr.ph
  %9 = trunc nuw nsw i64 %indvars.iv to i32
  %10 = tail call noundef i32 @_Z4findi(i32 noundef %9)
  %.not = icmp eq i32 %10, 1
  br i1 %.not, label %16, label %11

11:                                               ; preds = %8
  tail call void @_Z6changei(i32 noundef %10)
  %12 = load i32, ptr @num, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr @num, align 4, !tbaa !5
  %14 = sext i32 %12 to i64
  %15 = getelementptr inbounds [110 x i32], ptr @ans, i64 0, i64 %14
  store i32 %10, ptr %15, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %11, %8
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @a, i64 4), align 4, !tbaa !5
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %19, label %25

19:                                               ; preds = %16
  %20 = load i32, ptr @num, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @num, align 4, !tbaa !5
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [110 x i32], ptr @ans, i64 0, i64 %22
  store i32 1, ptr %23, align 4, !tbaa !5
  %24 = sub nsw i32 0, %17
  store i32 %24, ptr getelementptr inbounds (i8, ptr @a, i64 4), align 4, !tbaa !5
  br label %25

25:                                               ; preds = %19, %16
  %.not14 = icmp eq i64 %indvars.iv, 1
  br i1 %.not14, label %.thread, label %26

26:                                               ; preds = %25
  %27 = load i32, ptr @num, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @num, align 4, !tbaa !5
  %29 = sext i32 %27 to i64
  %30 = getelementptr inbounds [110 x i32], ptr @ans, i64 0, i64 %29
  store i32 %9, ptr %30, align 4, !tbaa !5
  tail call void @_Z6changei(i32 noundef %9)
  br label %38

.thread:                                          ; preds = %25
  %31 = getelementptr inbounds [35 x i32], ptr @a, i64 0, i64 %indvars.iv
  %32 = load i32, ptr @num, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @num, align 4, !tbaa !5
  %34 = sext i32 %32 to i64
  %35 = getelementptr inbounds [110 x i32], ptr @ans, i64 0, i64 %34
  store i32 1, ptr %35, align 4, !tbaa !5
  %36 = load i32, ptr %31, align 4, !tbaa !5
  %37 = sub nsw i32 0, %36
  store i32 %37, ptr %31, align 4, !tbaa !5
  br label %._crit_edge

38:                                               ; preds = %26, %.lr.ph
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %39 = icmp sgt i64 %indvars.iv, 1
  br i1 %39, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

attributes #0 = { mustprogress 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" }

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