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

; 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

declare i32 @fdt_check_header(ptr noundef) #1

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

declare i32 @fdt_next_node(ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @fdt_supernode_atdepth_offset(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 -13, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = call i32 @fdt_check_header(ptr noundef %15)
  store i32 %16, ptr %13, align 4, !tbaa !9
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %20

18:                                               ; preds = %4
  %19 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %19, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %21

20:                                               ; preds = %4
  store i32 0, ptr %14, align 4
  br label %21

21:                                               ; preds = %20, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  %22 = load i32, ptr %14, align 4
  switch i32 %22, label %79 [
    i32 0, label %23
  ]

23:                                               ; preds = %21
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %79

27:                                               ; preds = %23
  store i32 0, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %61, %27
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = icmp sge i32 %29, 0
  br i1 %30, label %31, label %35

31:                                               ; preds = %28
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = icmp sle i32 %32, %33
  br label %35

35:                                               ; preds = %31, %28
  %36 = phi i1 [ false, %28 ], [ %34, %31 ]
  br i1 %36, label %37, label %65

37:                                               ; preds = %35
  %38 = load i32, ptr %11, align 4, !tbaa !9
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = icmp eq i32 %38, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %37
  %42 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %42, ptr %12, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %41, %37
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = icmp eq i32 %44, %45
  br i1 %46, label %47, label %60

47:                                               ; preds = %43
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %53

50:                                               ; preds = %47
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %51, ptr %52, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %50, %47
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = load i32, ptr %11, align 4, !tbaa !9
  %56 = icmp sgt i32 %54, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %53
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %79

58:                                               ; preds = %53
  %59 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %59, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %79

60:                                               ; preds = %43
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = call i32 @fdt_next_node(ptr noundef %62, i32 noundef %63, ptr noundef %11)
  store i32 %64, ptr %10, align 4, !tbaa !9
  br label %28, !llvm.loop !11

65:                                               ; preds = %35
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = icmp eq i32 %66, -1
  br i1 %67, label %71, label %68

68:                                               ; preds = %65
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = icmp sge i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %68, %65
  store i32 -4, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %79

72:                                               ; preds = %68
  %73 = load i32, ptr %10, align 4, !tbaa !9
  %74 = icmp eq i32 %73, -4
  br i1 %74, label %75, label %76

75:                                               ; preds = %72
  store i32 -11, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %79

76:                                               ; preds = %72
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %78, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %79

79:                                               ; preds = %77, %75, %71, %58, %57, %26, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %80 = load i32, ptr %5, align 4
  ret i32 %80
}

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

declare i32 @fdt_check_header(ptr noundef) local_unnamed_addr #1

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

declare i32 @fdt_next_node(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @fdt_supernode_atdepth_offset(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef writeonly %3) local_unnamed_addr #2 {
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %6 = tail call i32 @fdt_check_header(ptr noundef %0) #3
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %._crit_edge.thread

7:                                                ; preds = %4
  %8 = icmp slt i32 %2, 0
  br i1 %8, label %._crit_edge.thread, label %9

9:                                                ; preds = %7
  store i32 0, ptr %5, align 4, !tbaa !5
  %10 = icmp sgt i32 %1, -1
  br i1 %10, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %9, %18
  %.02332 = phi i32 [ %spec.select, %18 ], [ -13, %9 ]
  %.02531 = phi i32 [ %19, %18 ], [ 0, %9 ]
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = icmp eq i32 %11, %2
  %spec.select = select i1 %12, i32 %.02531, i32 %.02332
  %13 = icmp eq i32 %.02531, %1
  br i1 %13, label %14, label %18

14:                                               ; preds = %.lr.ph
  %.not29 = icmp eq ptr %3, null
  br i1 %.not29, label %16, label %15

15:                                               ; preds = %14
  store i32 %11, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %15, %14
  %17 = icmp slt i32 %11, %2
  %.spec.select = select i1 %17, i32 -1, i32 %spec.select
  br label %._crit_edge.thread

18:                                               ; preds = %.lr.ph
  %19 = call i32 @fdt_next_node(ptr noundef %0, i32 noundef %.02531, ptr noundef nonnull %5) #3
  %.not33 = icmp ugt i32 %19, %1
  br i1 %.not33, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %18
  %or.cond = icmp sgt i32 %19, -2
  br i1 %or.cond, label %._crit_edge.thread, label %20

20:                                               ; preds = %._crit_edge
  %21 = icmp eq i32 %19, -4
  %..025 = select i1 %21, i32 -11, i32 %19
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %9, %20, %._crit_edge, %16, %7, %4
  %.1 = phi i32 [ %6, %4 ], [ -1, %7 ], [ %.spec.select, %16 ], [ -4, %._crit_edge ], [ %..025, %20 ], [ -4, %9 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  ret i32 %.1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass