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

%struct.fdt_property = type { i32, i32, i32, [0 x i8] }

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @fdt32_to_cpu(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: nounwind uwtable
declare dso_local i32 @fdt_first_property_offset(ptr noundef, i32 noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @fdt_get_property_namelen(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = call i32 @fdt_first_property_offset(ptr noundef %14, i32 noundef %15)
  store i32 %16, ptr %8, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %43, %5
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = icmp sge i32 %18, 0
  br i1 %19, label %20, label %47

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  %24 = call ptr @fdt_get_property_by_offset(ptr noundef %21, i32 noundef %22, ptr noundef %23)
  store ptr %24, ptr %12, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %20
  store i32 -13, ptr %8, align 4, !tbaa !9
  store i32 2, ptr %13, align 4
  br label %40

27:                                               ; preds = %20
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.fdt_property, ptr %29, i32 0, i32 2
  %31 = load i32, ptr %30, align 4, !tbaa !11
  %32 = call i32 @fdt32_to_cpu(i32 noundef %31)
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = call i32 @_fdt_string_eq(ptr noundef %28, i32 noundef %32, ptr noundef %33, i32 noundef %34)
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %27
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %38, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %40

39:                                               ; preds = %27
  store i32 0, ptr %13, align 4
  br label %40

40:                                               ; preds = %39, %37, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %41 = load i32, ptr %13, align 4
  switch i32 %41, label %56 [
    i32 0, label %42
    i32 2, label %47
    i32 1, label %54
  ]

42:                                               ; preds = %40
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = call i32 @fdt_next_property_offset(ptr noundef %44, i32 noundef %45)
  store i32 %46, ptr %8, align 4, !tbaa !9
  br label %17, !llvm.loop !13

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

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

53:                                               ; preds = %50, %47
  store ptr null, ptr %6, align 8
  br label %54

54:                                               ; preds = %53, %40
  %55 = load ptr, ptr %6, align 8
  ret ptr %55

56:                                               ; preds = %40
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden i32 @_fdt_string_eq(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #2

attributes #0 = { inlinehint 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 = { 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 = !{!12, !10, i64 8}
!12 = !{!"fdt_property", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 12}
!13 = distinct !{!13, !14}
!14 = !{!"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: inlinehint nounwind uwtable
declare hidden i32 @fdt32_to_cpu(i32 noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @fdt_get_property_namelen(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = tail call i32 @fdt_first_property_offset(ptr noundef %0, i32 noundef %1)
  %7 = icmp sgt i32 %6, -1
  br i1 %7, label %.lr.ph, label %.thread30

.lr.ph:                                           ; preds = %5, %14
  %.01834 = phi i32 [ %15, %14 ], [ %6, %5 ]
  %8 = tail call ptr @fdt_get_property_by_offset(ptr noundef %0, i32 noundef %.01834, ptr noundef %4)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %.thread30, label %9

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds i8, ptr %8, i64 8
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = tail call i32 @fdt32_to_cpu(i32 noundef %11)
  %13 = tail call i32 @_fdt_string_eq(ptr noundef %0, i32 noundef %12, ptr noundef %2, i32 noundef %3)
  %.not23 = icmp eq i32 %13, 0
  br i1 %.not23, label %14, label %.loopexit

14:                                               ; preds = %9
  %15 = tail call i32 @fdt_next_property_offset(ptr noundef %0, i32 noundef %.01834)
  %16 = icmp sgt i32 %15, -1
  br i1 %16, label %.lr.ph, label %.thread30, !llvm.loop !10

.thread30:                                        ; preds = %14, %.lr.ph, %5
  %.220 = phi i32 [ %6, %5 ], [ -13, %.lr.ph ], [ %15, %14 ]
  %.not24 = icmp eq ptr %4, null
  br i1 %.not24, label %.loopexit, label %17

17:                                               ; preds = %.thread30
  store i32 %.220, ptr %4, align 4, !tbaa !12
  br label %.loopexit

.loopexit:                                        ; preds = %9, %.thread30, %17
  %.2 = phi ptr [ null, %17 ], [ null, %.thread30 ], [ %8, %9 ]
  ret ptr %.2
}

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

attributes #0 = { inlinehint 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 = { 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" }

!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 = !{!"fdt_property", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!7, !7, i64 0}


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