; 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

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

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

21:                                               ; preds = %2
  %22 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %22, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %24

23:                                               ; preds = %2
  store i32 0, ptr %10, align 4
  br label %24

24:                                               ; preds = %23, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %25 = load i32, ptr %10, align 4
  switch i32 %25, label %108 [
    i32 0, label %26
  ]

26:                                               ; preds = %24
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = sext i8 %28 to i32
  %30 = icmp ne i32 %29, 47
  br i1 %30, label %31, label %59

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = call ptr @strchr(ptr noundef %32, i32 noundef 47) #5
  store ptr %33, ptr %11, align 8, !tbaa !5
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %38, label %36

36:                                               ; preds = %31
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %37, ptr %11, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %36, %31
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = ptrtoint ptr %41 to i64
  %44 = ptrtoint ptr %42 to i64
  %45 = sub i64 %43, %44
  %46 = trunc i64 %45 to i32
  %47 = call ptr @fdt_get_alias_namelen(ptr noundef %39, ptr noundef %40, i32 noundef %46)
  store ptr %47, ptr %7, align 8, !tbaa !5
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %51, label %50

50:                                               ; preds = %38
  store i32 -5, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %56

51:                                               ; preds = %38
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = call i32 @fdt_path_offset(ptr noundef %52, ptr noundef %53)
  store i32 %54, ptr %8, align 4, !tbaa !9
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %55, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %10, align 4
  br label %56

56:                                               ; preds = %51, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %57 = load i32, ptr %10, align 4
  switch i32 %57, label %108 [
    i32 0, label %58
  ]

58:                                               ; preds = %56
  br label %59

59:                                               ; preds = %58, %26
  br label %60

60:                                               ; preds = %105, %59
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load i8, ptr %61, align 1, !tbaa !11
  %63 = icmp ne i8 %62, 0
  br i1 %63, label %64, label %106

64:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  br label %65

65:                                               ; preds = %70, %64
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load i8, ptr %66, align 1, !tbaa !11
  %68 = sext i8 %67 to i32
  %69 = icmp eq i32 %68, 47
  br i1 %69, label %70, label %73

70:                                               ; preds = %65
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i32 1
  store ptr %72, ptr %7, align 8, !tbaa !5
  br label %65, !llvm.loop !12

73:                                               ; preds = %65
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load i8, ptr %74, align 1, !tbaa !11
  %76 = icmp ne i8 %75, 0
  br i1 %76, label %79, label %77

77:                                               ; preds = %73
  %78 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %78, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %103

79:                                               ; preds = %73
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = call ptr @strchr(ptr noundef %80, i32 noundef 47) #5
  store ptr %81, ptr %12, align 8, !tbaa !5
  %82 = load ptr, ptr %12, align 8, !tbaa !5
  %83 = icmp ne ptr %82, null
  br i1 %83, label %86, label %84

84:                                               ; preds = %79
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %85, ptr %12, align 8, !tbaa !5
  br label %86

86:                                               ; preds = %84, %79
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = load i32, ptr %8, align 4, !tbaa !9
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = load ptr, ptr %12, align 8, !tbaa !5
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = ptrtoint ptr %90 to i64
  %93 = ptrtoint ptr %91 to i64
  %94 = sub i64 %92, %93
  %95 = trunc i64 %94 to i32
  %96 = call i32 @fdt_subnode_offset_namelen(ptr noundef %87, i32 noundef %88, ptr noundef %89, i32 noundef %95)
  store i32 %96, ptr %8, align 4, !tbaa !9
  %97 = load i32, ptr %8, align 4, !tbaa !9
  %98 = icmp slt i32 %97, 0
  br i1 %98, label %99, label %101

99:                                               ; preds = %86
  %100 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %100, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %103

101:                                              ; preds = %86
  %102 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %102, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %10, align 4
  br label %103

103:                                              ; preds = %101, %99, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %104 = load i32, ptr %10, align 4
  switch i32 %104, label %108 [
    i32 0, label %105
  ]

105:                                              ; preds = %103
  br label %60, !llvm.loop !14

106:                                              ; preds = %60
  %107 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %107, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %108

108:                                              ; preds = %106, %103, %56, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %109 = load i32, ptr %3, align 4
  ret i32 %109
}

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strchr(ptr noundef, i32 noundef) #3

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

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 willreturn memory(read) "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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

declare i32 @fdt_check_header(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @fdt_path_offset(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %4 = getelementptr inbounds i8, ptr %1, i64 %3
  %5 = tail call i32 @fdt_check_header(ptr noundef %0) #4
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %.thread

6:                                                ; preds = %2
  %7 = load i8, ptr %1, align 1, !tbaa !5
  %.not59 = icmp eq i8 %7, 47
  br i1 %.not59, label %.preheader86, label %8

8:                                                ; preds = %6
  %9 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %1, i32 noundef 47) #3
  %.not60 = icmp eq ptr %9, null
  %spec.select = select i1 %.not60, ptr %4, ptr %9
  %10 = ptrtoint ptr %spec.select to i64
  %11 = ptrtoint ptr %1 to i64
  %12 = sub i64 %10, %11
  %13 = trunc i64 %12 to i32
  %14 = tail call ptr @fdt_get_alias_namelen(ptr noundef %0, ptr noundef nonnull %1, i32 noundef %13)
  %.not61.not = icmp eq ptr %14, null
  br i1 %.not61.not, label %.thread, label %15

15:                                               ; preds = %8
  %16 = tail call i32 @fdt_path_offset(ptr noundef %0, ptr noundef nonnull %14)
  br label %.preheader86

.preheader86:                                     ; preds = %15, %6
  %.250.ph = phi ptr [ %1, %6 ], [ %spec.select, %15 ]
  %.246.ph = phi i32 [ 0, %6 ], [ %16, %15 ]
  br label %17

17:                                               ; preds = %.preheader86, %22
  %.250 = phi ptr [ %spec.select65, %22 ], [ %.250.ph, %.preheader86 ]
  %.246 = phi i32 [ %28, %22 ], [ %.246.ph, %.preheader86 ]
  %18 = load i8, ptr %.250, align 1, !tbaa !5
  %.not62 = icmp eq i8 %18, 0
  br i1 %.not62, label %.thread, label %.preheader

.preheader:                                       ; preds = %17, %20
  %19 = phi i8 [ %.pr, %20 ], [ %18, %17 ]
  %.351 = phi ptr [ %21, %20 ], [ %.250, %17 ]
  switch i8 %19, label %22 [
    i8 47, label %20
    i8 0, label %.thread
  ]

20:                                               ; preds = %.preheader
  %21 = getelementptr inbounds i8, ptr %.351, i64 1
  %.pr = load i8, ptr %21, align 1, !tbaa !5
  br label %.preheader, !llvm.loop !8

22:                                               ; preds = %.preheader
  %23 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %.351, i32 noundef 47) #3
  %.not64 = icmp eq ptr %23, null
  %spec.select65 = select i1 %.not64, ptr %4, ptr %23
  %24 = ptrtoint ptr %spec.select65 to i64
  %25 = ptrtoint ptr %.351 to i64
  %26 = sub i64 %24, %25
  %27 = trunc i64 %26 to i32
  %28 = tail call i32 @fdt_subnode_offset_namelen(ptr noundef %0, i32 noundef %.246, ptr noundef nonnull %.351, i32 noundef %27)
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %.thread, label %17, !llvm.loop !10

.thread:                                          ; preds = %22, %17, %.preheader, %8, %2
  %.5 = phi i32 [ %5, %2 ], [ -5, %8 ], [ %.246, %.preheader ], [ %28, %22 ], [ %.246, %17 ]
  ret i32 %.5
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strchr(ptr noundef, i32 noundef) local_unnamed_addr #2

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

attributes #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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }
attributes #4 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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