; LLVM IR from upupming/algorithm :: AdvancedLevel_C++/1032. Sharing (25) (main)

; 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 { i8, i32, i8 }

@node = external dso_local global [100000 x %struct.NODE], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 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
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca %struct.NODE, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %29, %0
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %32

19:                                               ; preds = %14
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5, ptr noundef %7, ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 12, ptr %9) #4
  %21 = getelementptr inbounds %struct.NODE, ptr %9, i32 0, i32 0
  %22 = load i8, ptr %7, align 1, !tbaa !9
  store i8 %22, ptr %21, align 4, !tbaa !10
  %23 = getelementptr inbounds %struct.NODE, ptr %9, i32 0, i32 1
  %24 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %24, ptr %23, align 4, !tbaa !13
  %25 = getelementptr inbounds %struct.NODE, ptr %9, i32 0, i32 2
  store i8 0, ptr %25, align 4, !tbaa !14
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100000 x %struct.NODE], ptr @node, i64 0, i64 %27
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %28, ptr align 4 %9, i64 12, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 12, ptr %9) #4
  br label %29

29:                                               ; preds = %19
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %8, align 4, !tbaa !5
  br label %14, !llvm.loop !17

32:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %33 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %33, ptr %10, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %43, %32
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = icmp ne i32 %35, -1
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %49

38:                                               ; preds = %34
  %39 = load i32, ptr %10, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100000 x %struct.NODE], ptr @node, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.NODE, ptr %41, i32 0, i32 2
  store i8 1, ptr %42, align 4, !tbaa !14
  br label %43

43:                                               ; preds = %38
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100000 x %struct.NODE], ptr @node, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.NODE, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !13
  store i32 %48, ptr %10, align 4, !tbaa !5
  br label %34, !llvm.loop !19

49:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %50 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %50, ptr %11, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %68, %49
  %52 = load i32, ptr %11, align 4, !tbaa !5
  %53 = icmp ne i32 %52, -1
  br i1 %53, label %55, label %54

54:                                               ; preds = %51
  store i32 8, ptr %12, align 4
  br label %74

55:                                               ; preds = %51
  %56 = load i32, ptr %11, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [100000 x %struct.NODE], ptr @node, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.NODE, ptr %58, i32 0, i32 2
  %60 = load i8, ptr %59, align 4, !tbaa !14, !range !20, !noundef !21
  %61 = trunc i8 %60 to i1
  %62 = zext i1 %61 to i32
  %63 = icmp eq i32 %62, 1
  br i1 %63, label %64, label %67

64:                                               ; preds = %55
  %65 = load i32, ptr %11, align 4, !tbaa !5
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %65)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %12, align 4
  br label %74

67:                                               ; preds = %55
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %11, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100000 x %struct.NODE], ptr @node, i64 0, i64 %70
  %72 = getelementptr inbounds %struct.NODE, ptr %71, i32 0, i32 1
  %73 = load i32, ptr %72, align 4, !tbaa !13
  store i32 %73, ptr %11, align 4, !tbaa !5
  br label %51, !llvm.loop !22

74:                                               ; preds = %64, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %75 = load i32, ptr %12, align 4
  switch i32 %75, label %78 [
    i32 8, label %76
  ]

76:                                               ; preds = %74
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %12, align 4
  br label %78

78:                                               ; preds = %76, %74
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %79 = load i32, ptr %1, align 4
  ret i32 %79
}

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

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

; 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) #3

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

declare i32 @printf(ptr noundef, ...) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 0}
!11 = !{!"_ZTS4NODE", !7, i64 0, !6, i64 4, !12, i64 8}
!12 = !{!"bool", !7, i64 0}
!13 = !{!11, !6, i64 4}
!14 = !{!11, !12, i64 8}
!15 = !{i64 0, i64 1, !9, i64 4, i64 4, !5, i64 8, i64 1, !16}
!16 = !{!12, !12, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = distinct !{!22, !18}


; 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 { i8, i32, i8 }

@node = external dso_local local_unnamed_addr global [100000 x %struct.NODE], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %6) #3
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %.preheader17

.preheader17:                                     ; preds = %.lr.ph, %0
  %.01320 = load i32, ptr %1, align 4, !tbaa !5
  %.not21 = icmp eq i32 %.01320, -1
  br i1 %.not21, label %.preheader, label %.lr.ph23

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.01519 = phi i32 [ %16, %.lr.ph ], [ 0, %0 ]
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %4, ptr noundef nonnull %6, ptr noundef nonnull %5)
  %11 = load i8, ptr %6, align 1, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100000 x %struct.NODE], ptr @node, i64 0, i64 %14
  store i8 %11, ptr %15, align 4, !tbaa !9
  %.sroa.48.0..sroa_idx = getelementptr inbounds i8, ptr %15, i64 4
  store i32 %12, ptr %.sroa.48.0..sroa_idx, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %15, i64 8
  store i8 0, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !10
  %16 = add nuw nsw i32 %.01519, 1
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %.lr.ph, label %.preheader17, !llvm.loop !12

.preheader:                                       ; preds = %.lr.ph23, %.preheader17
  %.01224 = load i32, ptr %2, align 4, !tbaa !5
  %.not1625 = icmp eq i32 %.01224, -1
  br i1 %.not1625, label %.critedge, label %.lr.ph27

.lr.ph23:                                         ; preds = %.preheader17, %.lr.ph23
  %.01322 = phi i32 [ %.013, %.lr.ph23 ], [ %.01320, %.preheader17 ]
  %19 = sext i32 %.01322 to i64
  %20 = getelementptr inbounds [100000 x %struct.NODE], ptr @node, i64 0, i64 %19
  %21 = getelementptr inbounds i8, ptr %20, i64 8
  store i8 1, ptr %21, align 4, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %20, i64 4
  %.013 = load i32, ptr %22, align 4, !tbaa !5
  %.not = icmp eq i32 %.013, -1
  br i1 %.not, label %.preheader, label %.lr.ph23, !llvm.loop !16

23:                                               ; preds = %.lr.ph27
  %24 = getelementptr inbounds i8, ptr %26, i64 4
  %.012 = load i32, ptr %24, align 4, !tbaa !5
  %.not16 = icmp eq i32 %.012, -1
  br i1 %.not16, label %.critedge, label %.lr.ph27, !llvm.loop !17

.lr.ph27:                                         ; preds = %.preheader, %23
  %.01226 = phi i32 [ %.012, %23 ], [ %.01224, %.preheader ]
  %25 = sext i32 %.01226 to i64
  %26 = getelementptr inbounds [100000 x %struct.NODE], ptr @node, i64 0, i64 %25
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  %28 = load i8, ptr %27, align 4, !tbaa !14, !range !18, !noundef !19
  %29 = trunc nuw i8 %28 to i1
  br i1 %29, label %30, label %23

30:                                               ; preds = %.lr.ph27
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.01226)
  br label %33

.critedge:                                        ; preds = %23, %.preheader
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %33

33:                                               ; preds = %30, %.critedge
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 0
}

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

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

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

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

attributes #0 = { mustprogress nofree 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"bool", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !11, i64 8}
!15 = !{!"_ZTS4NODE", !7, i64 0, !6, i64 4, !11, i64 8}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !13}
!18 = !{i8 0, i8 2}
!19 = !{}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass