; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd/1088.ll (Z5buildiii)

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

%struct.SegTree = type { [6 x i32], i32 }

@seg = external dso_local global [262144 x %struct.SegTree], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7push_upi(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 uwtable
define dso_local void @_Z5buildiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = icmp eq i32 %9, %10
  br i1 %11, label %12, label %52

12:                                               ; preds = %3
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [262144 x %struct.SegTree], ptr @seg, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.SegTree, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds [6 x i32], ptr %16, i64 0, i64 0
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %17)
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [262144 x %struct.SegTree], ptr @seg, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.SegTree, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds [6 x i32], ptr %22, i64 0, i64 0
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = srem i32 %24, 61
  store i32 %25, ptr %23, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %48, %12
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = icmp slt i32 %27, 6
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %26
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [262144 x %struct.SegTree], ptr @seg, i64 0, i64 %32
  %34 = getelementptr inbounds %struct.SegTree, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = sub nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [6 x i32], ptr %34, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = call noundef i32 @_Z3sqri(i32 noundef %39)
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [262144 x %struct.SegTree], ptr @seg, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.SegTree, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [6 x i32], ptr %44, i64 0, i64 %46
  store i32 %40, ptr %47, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %30
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !5
  br label %26, !llvm.loop !9

51:                                               ; preds = %29
  br label %70

52:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = add nsw i32 %53, %54
  %56 = ashr i32 %55, 1
  store i32 %56, ptr %8, align 4, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = add nsw i32 %57, %58
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z5buildiii(i32 noundef %59, i32 noundef %60, i32 noundef %61)
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = add nsw i32 %62, %63
  %65 = add nsw i32 %64, 1
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  %68 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z5buildiii(i32 noundef %65, i32 noundef %67, i32 noundef %68)
  %69 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z7push_upi(i32 noundef %69)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %70

70:                                               ; preds = %52, %51
  ret void
}

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

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 = { 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 #3 = { "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"

%struct.SegTree = type { [6 x i32], i32 }

@seg = external dso_local global [262144 x %struct.SegTree], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5buildiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %1, %2
  br i1 %4, label %common.ret.loopexit, label %20

common.ret.loopexit:                              ; preds = %3
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [262144 x %struct.SegTree], ptr @seg, i64 0, i64 %5
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %6)
  %8 = load i32, ptr %6, align 4, !tbaa !5
  %9 = srem i32 %8, 61
  store i32 %9, ptr %6, align 4, !tbaa !5
  %10 = tail call noundef i32 @_Z3sqri(i32 noundef %9)
  %11 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %10, ptr %11, align 4, !tbaa !5
  %12 = tail call noundef i32 @_Z3sqri(i32 noundef %10)
  %13 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %12, ptr %13, align 4, !tbaa !5
  %14 = tail call noundef i32 @_Z3sqri(i32 noundef %12)
  %15 = getelementptr inbounds i8, ptr %6, i64 12
  store i32 %14, ptr %15, align 4, !tbaa !5
  %16 = tail call noundef i32 @_Z3sqri(i32 noundef %14)
  %17 = getelementptr inbounds i8, ptr %6, i64 16
  store i32 %16, ptr %17, align 4, !tbaa !5
  %18 = tail call noundef i32 @_Z3sqri(i32 noundef %16)
  %19 = getelementptr inbounds i8, ptr %6, i64 20
  store i32 %18, ptr %19, align 4, !tbaa !5
  br label %common.ret25

common.ret25:                                     ; preds = %20, %common.ret.loopexit
  ret void

20:                                               ; preds = %3
  %21 = add nsw i32 %2, %1
  %22 = ashr i32 %21, 1
  %23 = shl nsw i32 %0, 1
  tail call void @_Z5buildiii(i32 noundef %23, i32 noundef %1, i32 noundef %22)
  %24 = or disjoint i32 %23, 1
  %25 = add nsw i32 %22, 1
  tail call void @_Z5buildiii(i32 noundef %24, i32 noundef %25, i32 noundef %2)
  tail call void @_Z7push_upi(i32 noundef %0)
  br label %common.ret25
}

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

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 = { 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 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass