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

%struct.fdt_header = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @fdt32_to_cpu(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @fdt_offset_ptr(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.fdt_header, ptr %10, i32 0, i32 5
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = call i32 @fdt32_to_cpu(i32 noundef %12)
  %14 = icmp uge i32 %13, 17
  br i1 %14, label %15, label %32

15:                                               ; preds = %3
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = add i32 %16, %17
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp ult i32 %18, %19
  br i1 %20, label %30, label %21

21:                                               ; preds = %15
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = add i32 %22, %23
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.fdt_header, ptr %25, i32 0, i32 9
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = call i32 @fdt32_to_cpu(i32 noundef %27)
  %29 = icmp ugt i32 %24, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %21, %15
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %45

31:                                               ; preds = %21
  br label %32

32:                                               ; preds = %31, %3
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = call ptr @_fdt_offset_ptr(ptr noundef %33, i32 noundef %34)
  store ptr %35, ptr %8, align 8, !tbaa !5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = icmp ult ptr %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %32
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %45

43:                                               ; preds = %32
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %44, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %45

45:                                               ; preds = %43, %42, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %46 = load ptr, ptr %4, align 8
  ret ptr %46
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @_fdt_offset_ptr(ptr noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 20}
!12 = !{!"fdt_header", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36}
!13 = !{!12, !10, i64 36}


; 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
define dso_local ptr @fdt_offset_ptr(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 20
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = tail call i32 @fdt32_to_cpu(i32 noundef %5)
  %7 = icmp ugt i32 %6, 16
  br i1 %7, label %8, label %16

8:                                                ; preds = %3
  %9 = add i32 %2, %1
  %10 = icmp ult i32 %9, %1
  br i1 %10, label %18, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 36
  %13 = load i32, ptr %12, align 4, !tbaa !10
  %14 = tail call i32 @fdt32_to_cpu(i32 noundef %13)
  %15 = icmp ugt i32 %9, %14
  br i1 %15, label %18, label %16

16:                                               ; preds = %11, %3
  %17 = tail call ptr @_fdt_offset_ptr(ptr noundef nonnull %0, i32 noundef %1)
  br label %18

18:                                               ; preds = %8, %11, %16
  %.0 = phi ptr [ %17, %16 ], [ null, %11 ], [ null, %8 ]
  ret ptr %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @_fdt_offset_ptr(ptr noundef, i32 noundef) local_unnamed_addr #0

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 20}
!6 = !{!"fdt_header", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 36}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass