; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ (2725（模拟）)

; 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.Node = type { i32, i32, i32, i32 }

@s = external dso_local global [50 x i8], align 16
@len = external dso_local global i32, align 4
@ans = external dso_local global %struct.Node, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i64, i64 } @_Z4calcii(i32 noundef, 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 norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.Node, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.Node, align 4
  %7 = alloca %struct.Node, align 4
  store i32 0, ptr %1, align 4
  br label %8

8:                                                ; preds = %57, %0
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @s)
  %10 = xor i32 %9, -1
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %61

12:                                               ; preds = %8
  %13 = call i32 @strcmp(ptr noundef @s, ptr noundef @.str.1) #7
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  br label %61

16:                                               ; preds = %12
  store i32 0, ptr getelementptr inbounds (%struct.Node, ptr @ans, i32 0, i32 2), align 4, !tbaa !5
  store i32 0, ptr getelementptr inbounds (%struct.Node, ptr @ans, i32 0, i32 3), align 4, !tbaa !10
  store i32 0, ptr @ans, align 4, !tbaa !11
  %17 = load i32, ptr @len, align 4, !tbaa !12
  %18 = sub nsw i32 %17, 1
  store i32 %18, ptr getelementptr inbounds (%struct.Node, ptr @ans, i32 0, i32 1), align 4, !tbaa !13
  %19 = call i64 @strlen(ptr noundef @s) #7
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr @len, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #8
  store i32 0, ptr %3, align 4, !tbaa !12
  br label %21

21:                                               ; preds = %54, %16
  %22 = load i32, ptr %3, align 4, !tbaa !12
  %23 = load i32, ptr @len, align 4, !tbaa !12
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 4, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #8
  br label %57

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #8
  store i32 1, ptr %5, align 4, !tbaa !12
  br label %27

27:                                               ; preds = %50, %26
  %28 = load i32, ptr %3, align 4, !tbaa !12
  %29 = load i32, ptr %5, align 4, !tbaa !12
  %30 = add nsw i32 %28, %29
  %31 = load i32, ptr @len, align 4, !tbaa !12
  %32 = icmp sle i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %27
  store i32 7, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  br label %53

34:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #8
  %35 = load i32, ptr %3, align 4, !tbaa !12
  %36 = load i32, ptr %5, align 4, !tbaa !12
  %37 = call { i64, i64 } @_Z4calcii(i32 noundef %35, i32 noundef %36)
  %38 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  %39 = extractvalue { i64, i64 } %37, 0
  store i64 %39, ptr %38, align 4
  %40 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  %41 = extractvalue { i64, i64 } %37, 1
  store i64 %41, ptr %40, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 4 %6, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #8
  %42 = load i32, ptr %3, align 4, !tbaa !12
  %43 = getelementptr inbounds %struct.Node, ptr %2, i32 0, i32 0
  store i32 %42, ptr %43, align 4, !tbaa !11
  %44 = load i32, ptr %5, align 4, !tbaa !12
  %45 = getelementptr inbounds %struct.Node, ptr %2, i32 0, i32 1
  store i32 %44, ptr %45, align 4, !tbaa !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %2, i64 16, i1 false), !tbaa.struct !14
  %46 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %47 = load i64, ptr %46, align 4
  %48 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %49 = load i64, ptr %48, align 4
  call void @_ZN4Node6UpdateES_(ptr noundef nonnull align 4 dereferenceable(16) @ans, i64 %47, i64 %49)
  br label %50

50:                                               ; preds = %34
  %51 = load i32, ptr %5, align 4, !tbaa !12
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %5, align 4, !tbaa !12
  br label %27, !llvm.loop !15

53:                                               ; preds = %33
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %3, align 4, !tbaa !12
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %3, align 4, !tbaa !12
  br label %21, !llvm.loop !17

57:                                               ; preds = %25
  %58 = load i32, ptr @ans, align 4, !tbaa !11
  %59 = load i32, ptr getelementptr inbounds (%struct.Node, ptr @ans, i32 0, i32 1), align 4, !tbaa !13
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %58, i32 noundef %59)
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #8
  br label %8, !llvm.loop !18

61:                                               ; preds = %15, %8
  ret i32 0
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Node6UpdateES_(ptr noundef nonnull align 4 dereferenceable(16), i64, i64) #6 align 2

declare i32 @printf(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 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 #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 willreturn memory(read) "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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 #7 = { nounwind willreturn memory(read) }
attributes #8 = { 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, !7, i64 8}
!6 = !{!"_ZTS4Node", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 12}
!11 = !{!6, !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{i64 0, i64 4, !12, i64 4, i64 4, !12, i64 8, i64 4, !12, i64 12, i64 4, !12}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


; 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.Node = type { i32, i32, i32, i32 }

@s = external dso_local global [50 x i8], align 16
@len = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local global %struct.Node, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i64, i64 } @_Z4calcii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @s)
  %.not17 = icmp eq i32 %1, -1
  br i1 %.not17, label %._crit_edge20, label %.lr.ph19

.lr.ph19:                                         ; preds = %0, %._crit_edge16
  %2 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @s, ptr noundef nonnull dereferenceable(1) @.str.1) #5
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %._crit_edge20, label %4

4:                                                ; preds = %.lr.ph19
  store i32 0, ptr getelementptr inbounds (i8, ptr @ans, i64 8), align 4, !tbaa !5
  store i32 0, ptr getelementptr inbounds (i8, ptr @ans, i64 12), align 4, !tbaa !10
  store i32 0, ptr @ans, align 4, !tbaa !11
  %5 = load i32, ptr @len, align 4, !tbaa !12
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr getelementptr inbounds (i8, ptr @ans, i64 4), align 4, !tbaa !13
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @s) #5
  %8 = trunc i64 %7 to i32
  store i32 %8, ptr @len, align 4, !tbaa !12
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.preheader, label %._crit_edge16

.preheader:                                       ; preds = %4, %._crit_edge
  %10 = phi i32 [ %17, %._crit_edge ], [ %8, %4 ]
  %indvars.iv23 = phi i64 [ %indvars.iv.next24, %._crit_edge ], [ 0, %4 ]
  %11 = sext i32 %10 to i64
  %.not1213.not = icmp slt i64 %indvars.iv23, %11
  br i1 %.not1213.not, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %12 = trunc nuw nsw i64 %indvars.iv23 to i32
  br label %19

._crit_edge16.loopexit:                           ; preds = %._crit_edge
  %.pre = load i32, ptr @ans, align 4, !tbaa !11
  %.pre26 = load i32, ptr getelementptr inbounds (i8, ptr @ans, i64 4), align 4, !tbaa !13
  br label %._crit_edge16

._crit_edge16:                                    ; preds = %._crit_edge16.loopexit, %4
  %13 = phi i32 [ %.pre26, %._crit_edge16.loopexit ], [ %6, %4 ]
  %14 = phi i32 [ %.pre, %._crit_edge16.loopexit ], [ 0, %4 ]
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %14, i32 noundef %13)
  %16 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @s)
  %.not = icmp eq i32 %16, -1
  br i1 %.not, label %._crit_edge20, label %.lr.ph19, !llvm.loop !14

._crit_edge.loopexit:                             ; preds = %19
  %.pre27 = sext i32 %24 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.pre-phi = phi i64 [ %.pre27, %._crit_edge.loopexit ], [ %11, %.preheader ]
  %17 = phi i32 [ %24, %._crit_edge.loopexit ], [ %10, %.preheader ]
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %18 = icmp slt i64 %indvars.iv.next24, %.pre-phi
  br i1 %18, label %.preheader, label %._crit_edge16.loopexit, !llvm.loop !16

19:                                               ; preds = %.lr.ph, %19
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %19 ]
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  %21 = tail call { i64, i64 } @_Z4calcii(i32 noundef %12, i32 noundef %20)
  %22 = extractvalue { i64, i64 } %21, 1
  %.sroa.010.4.insert.shift = shl nuw nsw i64 %indvars.iv, 32
  %.sroa.010.4.insert.insert = or disjoint i64 %.sroa.010.4.insert.shift, %indvars.iv23
  tail call void @_ZN4Node6UpdateES_(ptr noundef nonnull align 4 dereferenceable(16) @ans, i64 %.sroa.010.4.insert.insert, i64 %22)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = add nuw nsw i64 %indvars.iv.next, %indvars.iv23
  %24 = load i32, ptr @len, align 4, !tbaa !12
  %25 = trunc nuw i64 %23 to i32
  %.not12 = icmp slt i32 %24, %25
  br i1 %.not12, label %._crit_edge.loopexit, label %19, !llvm.loop !17

._crit_edge20:                                    ; preds = %._crit_edge16, %.lr.ph19, %0
  ret i32 0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Node6UpdateES_(ptr noundef nonnull align 4 dereferenceable(16), i64, i64) local_unnamed_addr #4 align 2

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

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 = { 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 #2 = { 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 #3 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 #5 = { nounwind willreturn memory(read) }

!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, !7, i64 8}
!6 = !{!"_ZTS4Node", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 12}
!11 = !{!6, !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


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