; LLVM IR from AllAlgorithms/c :: algorithms/data-structures (bfs)

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

@root = external dso_local global ptr, align 8
@rear = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [49 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [35 x i8], align 1
@queue = external dso_local global [20 x i32], align 16
@i = external dso_local global i32, align 4
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @main() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  store ptr null, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !9
  %3 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %4

4:                                                ; preds = %26, %0
  br label %5

5:                                                ; preds = %4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2)
  %7 = load i32, ptr %2, align 4, !tbaa !9
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %5
  br label %27

10:                                               ; preds = %5
  %11 = call noalias ptr @malloc(i64 noundef 24) #5
  store ptr %11, ptr %1, align 8, !tbaa !5
  %12 = load ptr, ptr %1, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.btnode, ptr %12, i32 0, i32 2
  store ptr null, ptr %13, align 8, !tbaa !11
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.btnode, ptr %14, i32 0, i32 1
  store ptr null, ptr %15, align 8, !tbaa !13
  %16 = load i32, ptr %2, align 4, !tbaa !9
  %17 = load ptr, ptr %1, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.btnode, ptr %17, i32 0, i32 0
  store i32 %16, ptr %18, align 8, !tbaa !14
  %19 = load ptr, ptr @root, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %23

21:                                               ; preds = %10
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %22, ptr @root, align 8, !tbaa !5
  br label %26

23:                                               ; preds = %10
  %24 = load ptr, ptr %1, align 8, !tbaa !5
  %25 = load ptr, ptr @root, align 8, !tbaa !5
  call void @insert(ptr noundef %24, ptr noundef %25)
  br label %26

26:                                               ; preds = %23, %21
  br label %4

27:                                               ; preds = %9
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %29 = load ptr, ptr @root, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.btnode, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !14
  %32 = load i32, ptr @rear, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @rear, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [20 x i32], ptr @queue, i64 0, i64 %34
  store i32 %31, ptr %35, align 4, !tbaa !9
  %36 = load ptr, ptr @root, align 8, !tbaa !5
  call void @bfs_traverse(ptr noundef %36)
  store i32 0, ptr @i, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %47, %27
  %38 = load i32, ptr @i, align 4, !tbaa !9
  %39 = load i32, ptr @rear, align 4, !tbaa !9
  %40 = icmp sle i32 %38, %39
  br i1 %40, label %41, label %50

41:                                               ; preds = %37
  %42 = load i32, ptr @i, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [20 x i32], ptr @queue, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %45)
  br label %47

47:                                               ; preds = %41
  %48 = load i32, ptr @i, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr @i, align 4, !tbaa !9
  br label %37, !llvm.loop !15

50:                                               ; preds = %37
  %51 = load ptr, ptr @root, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.btnode, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = getelementptr inbounds %struct.btnode, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.btnode, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.btnode, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !14
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %59)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

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

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @insert(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @bfs_traverse(ptr noundef) #0

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

attributes #0 = { 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 = { "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 allocsize(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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"btnode", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@root = external dso_local local_unnamed_addr global ptr, align 8
@rear = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [49 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [35 x i8], align 1
@queue = external dso_local local_unnamed_addr global [20 x i32], align 16
@i = external dso_local local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  store i32 1, ptr %1, align 4, !tbaa !5
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %13
  %6 = phi i32 [ %15, %13 ], [ %4, %0 ]
  %7 = call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #6
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %8, i8 0, i64 16, i1 false)
  store i32 %6, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr @root, align 8, !tbaa !12
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %.lr.ph
  store ptr %7, ptr @root, align 8, !tbaa !12
  br label %13

12:                                               ; preds = %.lr.ph
  call void @insert(ptr noundef nonnull %7, ptr noundef nonnull %9)
  br label %13

13:                                               ; preds = %12, %11
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %13, %0
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %18 = load ptr, ptr @root, align 8, !tbaa !12
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = load i32, ptr @rear, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @rear, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [20 x i32], ptr @queue, i64 0, i64 %22
  store i32 %19, ptr %23, align 4, !tbaa !5
  call void @bfs_traverse(ptr noundef nonnull %18)
  store i32 0, ptr @i, align 4, !tbaa !5
  %24 = load i32, ptr @rear, align 4, !tbaa !5
  %.not6 = icmp slt i32 %24, 0
  br i1 %.not6, label %._crit_edge10, label %.lr.ph9

.lr.ph9:                                          ; preds = %._crit_edge, %.lr.ph9
  %storemerge7 = phi i32 [ %30, %.lr.ph9 ], [ 0, %._crit_edge ]
  %25 = sext i32 %storemerge7 to i64
  %26 = getelementptr inbounds [20 x i32], ptr @queue, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %27)
  %29 = load i32, ptr @i, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @i, align 4, !tbaa !5
  %31 = load i32, ptr @rear, align 4, !tbaa !5
  %.not.not = icmp slt i32 %29, %31
  br i1 %.not.not, label %.lr.ph9, label %._crit_edge10, !llvm.loop !13

._crit_edge10:                                    ; preds = %.lr.ph9, %._crit_edge
  %32 = load ptr, ptr @root, align 8, !tbaa !12
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = getelementptr inbounds i8, ptr %36, i64 16
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = load i32, ptr %38, align 8, !tbaa !9
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %39)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret void
}

; 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 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @insert(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @bfs_traverse(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"btnode", !6, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !11, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass