; 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: nounwind uwtable
define dso_local i32 @fdt_check_header(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.fdt_header, ptr %4, i32 0, i32 0
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = call i32 @fdt32_to_cpu(i32 noundef %6)
  %8 = icmp eq i32 %7, -804389139
  br i1 %8, label %9, label %24

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.fdt_header, ptr %10, i32 0, i32 5
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = call i32 @fdt32_to_cpu(i32 noundef %12)
  %14 = icmp ult i32 %13, 16
  br i1 %14, label %15, label %16

15:                                               ; preds = %9
  store i32 -10, ptr %2, align 4
  br label %41

16:                                               ; preds = %9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.fdt_header, ptr %17, i32 0, i32 6
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = call i32 @fdt32_to_cpu(i32 noundef %19)
  %21 = icmp ugt i32 %20, 17
  br i1 %21, label %22, label %23

22:                                               ; preds = %16
  store i32 -10, ptr %2, align 4
  br label %41

23:                                               ; preds = %16
  br label %40

24:                                               ; preds = %1
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.fdt_header, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = call i32 @fdt32_to_cpu(i32 noundef %27)
  %29 = icmp eq i32 %28, 804389138
  br i1 %29, label %30, label %38

30:                                               ; preds = %24
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.fdt_header, ptr %31, i32 0, i32 9
  %33 = load i32, ptr %32, align 4, !tbaa !14
  %34 = call i32 @fdt32_to_cpu(i32 noundef %33)
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %30
  store i32 -7, ptr %2, align 4
  br label %41

37:                                               ; preds = %30
  br label %39

38:                                               ; preds = %24
  store i32 -9, ptr %2, align 4
  br label %41

39:                                               ; preds = %37
  br label %40

40:                                               ; preds = %39, %23
  store i32 0, ptr %2, align 4
  br label %41

41:                                               ; preds = %40, %38, %36, %22, %15
  %42 = load i32, ptr %2, align 4
  ret i32 %42
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @fdt32_to_cpu(i32 noundef) #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 = { 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" }

!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, !11, i64 0}
!10 = !{!"fdt_header", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 20}
!13 = !{!10, !11, i64 24}
!14 = !{!10, !11, 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: nounwind uwtable
define dso_local range(i32 -10, 1) i32 @fdt_check_header(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 4, !tbaa !5
  %3 = tail call i32 @fdt32_to_cpu(i32 noundef %2)
  %4 = icmp eq i32 %3, -804389139
  br i1 %4, label %5, label %15

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 20
  %7 = load i32, ptr %6, align 4, !tbaa !10
  %8 = tail call i32 @fdt32_to_cpu(i32 noundef %7)
  %9 = icmp ult i32 %8, 16
  br i1 %9, label %25, label %10

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = tail call i32 @fdt32_to_cpu(i32 noundef %12)
  %14 = icmp ugt i32 %13, 17
  br i1 %14, label %25, label %24

15:                                               ; preds = %1
  %16 = load i32, ptr %0, align 4, !tbaa !5
  %17 = tail call i32 @fdt32_to_cpu(i32 noundef %16)
  %18 = icmp eq i32 %17, 804389138
  br i1 %18, label %19, label %25

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %0, i64 36
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = tail call i32 @fdt32_to_cpu(i32 noundef %21)
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %25, label %24

24:                                               ; preds = %19, %10
  br label %25

25:                                               ; preds = %15, %19, %10, %5, %24
  %.0 = phi i32 [ 0, %24 ], [ -10, %5 ], [ -10, %10 ], [ -7, %19 ], [ -9, %15 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @fdt32_to_cpu(i32 noundef) local_unnamed_addr #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 = { 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" }

!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 0}
!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 20}
!11 = !{!6, !7, i64 24}
!12 = !{!6, !7, i64 36}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass