; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdePkg/Library (GetParamByNodeName)

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

declare ptr @AllocateCopyPool(i64 noundef, ptr noundef) #0

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

18:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %69

19:                                               ; preds = %2
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = getelementptr inbounds i16, ptr %20, i64 %21
  store ptr %22, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i16, ptr %23, align 2, !tbaa !11
  %25 = zext i16 %24 to i32
  %26 = icmp eq i32 %25, 40
  br i1 %26, label %28, label %27

27:                                               ; preds = %19
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %69

28:                                               ; preds = %19
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds i16, ptr %29, i32 1
  store ptr %30, ptr %6, align 8, !tbaa !5
  store i64 0, ptr %9, align 8, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %31, ptr %7, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %44, %28
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i16, ptr %33, align 2, !tbaa !11
  %35 = zext i16 %34 to i32
  %36 = icmp eq i32 %35, 0
  %37 = xor i1 %36, true
  br i1 %37, label %38, label %49

38:                                               ; preds = %32
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i16, ptr %39, align 2, !tbaa !11
  %41 = zext i16 %40 to i32
  %42 = icmp eq i32 %41, 41
  br i1 %42, label %43, label %44

43:                                               ; preds = %38
  br label %49

44:                                               ; preds = %38
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds i16, ptr %45, i32 1
  store ptr %46, ptr %7, align 8, !tbaa !5
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = add i64 %47, 1
  store i64 %48, ptr %9, align 8, !tbaa !9
  br label %32, !llvm.loop !13

49:                                               ; preds = %43, %32
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i16, ptr %50, align 2, !tbaa !11
  %52 = zext i16 %51 to i32
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %49
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %69

55:                                               ; preds = %49
  %56 = load i64, ptr %9, align 8, !tbaa !9
  %57 = add i64 %56, 1
  %58 = mul i64 %57, 2
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = call ptr @AllocateCopyPool(i64 noundef %58, ptr noundef %59)
  store ptr %60, ptr %6, align 8, !tbaa !5
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %64

63:                                               ; preds = %55
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %69

64:                                               ; preds = %55
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i64, ptr %9, align 8, !tbaa !9
  %67 = getelementptr inbounds i16, ptr %65, i64 %66
  store i16 0, ptr %67, align 2, !tbaa !11
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %68, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %69

69:                                               ; preds = %64, %63, %54, %27, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %70 = load ptr, ptr %3, align 8
  ret ptr %70
}

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

declare i64 @StrLen(ptr noundef) #0

declare i64 @StrnCmp(ptr noundef, ptr noundef, i64 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 = { "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 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!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"

declare ptr @AllocateCopyPool(i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @GetParamByNodeName(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call i64 @StrLen(ptr noundef %1) #2
  %4 = tail call i64 @StrnCmp(ptr noundef %0, ptr noundef %1, i64 noundef %3) #2
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %5, label %.loopexit

5:                                                ; preds = %2
  %6 = getelementptr inbounds i16, ptr %0, i64 %3
  %7 = load i16, ptr %6, align 2, !tbaa !5
  %8 = icmp eq i16 %7, 40
  br i1 %8, label %9, label %.loopexit

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %6, i64 2
  br label %11

11:                                               ; preds = %13, %9
  %.021 = phi ptr [ %10, %9 ], [ %14, %13 ]
  %.0 = phi i64 [ 0, %9 ], [ %15, %13 ]
  %12 = load i16, ptr %.021, align 2, !tbaa !5
  switch i16 %12, label %13 [
    i16 0, label %.loopexit
    i16 41, label %16
  ]

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %.021, i64 2
  %15 = add i64 %.0, 1
  br label %11, !llvm.loop !9

16:                                               ; preds = %11
  %17 = shl i64 %.0, 1
  %18 = add i64 %17, 2
  %19 = tail call ptr @AllocateCopyPool(i64 noundef %18, ptr noundef nonnull %10) #2
  %20 = icmp eq ptr %19, null
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %16
  %22 = getelementptr inbounds i16, ptr %19, i64 %.0
  store i16 0, ptr %22, align 2, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %11, %16, %5, %2, %21
  %.020 = phi ptr [ %19, %21 ], [ null, %2 ], [ null, %5 ], [ null, %16 ], [ null, %11 ]
  ret ptr %.020
}

declare i64 @StrLen(ptr noundef) local_unnamed_addr #0

declare i64 @StrnCmp(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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 = { 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 = !{!"short", !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: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass