; LLVM IR from gem5/gem5 :: ext/libfdt (fdt)

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @fdt_next_tag(ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @_fdt_check_node_offset(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @fdt_next_node(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = icmp sge i32 %11, 0
  br i1 %12, label %13, label %21

13:                                               ; preds = %3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = call i32 @_fdt_check_node_offset(ptr noundef %14, i32 noundef %15)
  store i32 %16, ptr %8, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %20

18:                                               ; preds = %13
  %19 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %19, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %66

20:                                               ; preds = %13
  br label %21

21:                                               ; preds = %20, %3
  br label %22

22:                                               ; preds = %61, %21
  %23 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %23, ptr %6, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = call i32 @fdt_next_tag(ptr noundef %24, i32 noundef %25, ptr noundef %8)
  store i32 %26, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !9
  switch i32 %27, label %60 [
    i32 3, label %28
    i32 4, label %28
    i32 1, label %29
    i32 2, label %37
    i32 9, label %48
  ]

28:                                               ; preds = %22, %22
  br label %60

29:                                               ; preds = %22
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %36

32:                                               ; preds = %29
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %33, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %32, %29
  br label %60

37:                                               ; preds = %22
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %47

40:                                               ; preds = %37
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr %41, align 4, !tbaa !9
  %44 = icmp slt i32 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %40
  %46 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %46, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %66

47:                                               ; preds = %40, %37
  br label %60

48:                                               ; preds = %22
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = icmp sge i32 %49, 0
  br i1 %50, label %57, label %51

51:                                               ; preds = %48
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = icmp eq i32 %52, -8
  br i1 %53, label %54, label %58

54:                                               ; preds = %51
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %58, label %57

57:                                               ; preds = %54, %48
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %66

58:                                               ; preds = %54, %51
  %59 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %59, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %66

60:                                               ; preds = %47, %36, %28, %22
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %9, align 4, !tbaa !9
  %63 = icmp ne i32 %62, 1
  br i1 %63, label %22, label %64, !llvm.loop !11

64:                                               ; preds = %61
  %65 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %65, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %66

66:                                               ; preds = %64, %58, %57, %45, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %67 = load i32, ptr %4, align 4
  ret i32 %67
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"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"

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @fdt_next_tag(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @_fdt_check_node_offset(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @fdt_next_node(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  %5 = icmp sgt i32 %1, -1
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  %7 = tail call i32 @_fdt_check_node_offset(ptr noundef %0, i32 noundef %1)
  store i32 %7, ptr %4, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 0
  br i1 %8, label %.thread, label %9

9:                                                ; preds = %6, %3
  %10 = phi i32 [ %7, %6 ], [ 0, %3 ]
  %.not18 = icmp eq ptr %2, null
  br i1 %.not18, label %.split.us, label %.split

.split.us:                                        ; preds = %9, %.split.us
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = call i32 @fdt_next_tag(ptr noundef %0, i32 noundef %11, ptr noundef nonnull %4)
  switch i32 %12, label %.split.us [
    i32 9, label %.split24.us
    i32 1, label %.split26.us
  ], !llvm.loop !9

.split:                                           ; preds = %9, %.backedge
  %13 = phi i32 [ %.pre, %.backedge ], [ %10, %9 ]
  %14 = call i32 @fdt_next_tag(ptr noundef %0, i32 noundef %13, ptr noundef nonnull %4)
  switch i32 %14, label %.backedge [
    i32 9, label %.split24.us
    i32 2, label %18
    i32 1, label %.split26.us
  ]

.backedge:                                        ; preds = %18, %.split
  %.pre = load i32, ptr %4, align 4, !tbaa !5
  br label %.split, !llvm.loop !9

.split26.us:                                      ; preds = %.split, %.split.us
  %.us-phi = phi i32 [ %11, %.split.us ], [ %13, %.split ]
  br i1 %.not18, label %.thread, label %15

15:                                               ; preds = %.split26.us
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %2, align 4, !tbaa !5
  br label %.thread

18:                                               ; preds = %.split
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = add nsw i32 %19, -1
  store i32 %20, ptr %2, align 4, !tbaa !5
  %21 = icmp slt i32 %19, 1
  br i1 %21, label %22, label %.backedge

22:                                               ; preds = %18
  %23 = load i32, ptr %4, align 4, !tbaa !5
  br label %.thread

.split24.us:                                      ; preds = %.split, %.split.us
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp sgt i32 %24, -1
  br i1 %25, label %.thread, label %26

26:                                               ; preds = %.split24.us
  %27 = icmp ne i32 %24, -8
  %28 = icmp ne ptr %2, null
  %or.cond = or i1 %28, %27
  %spec.select = select i1 %or.cond, i32 %24, i32 -1
  br label %.thread

.thread:                                          ; preds = %.split26.us, %15, %26, %.split24.us, %6, %22
  %.0 = phi i32 [ %23, %22 ], [ %7, %6 ], [ -1, %.split24.us ], [ %spec.select, %26 ], [ %.us-phi, %15 ], [ %.us-phi, %.split26.us ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #2
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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