; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (GetNameElement)

; 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.IFR_BLOCK_DATA = type { %struct._LIST_ENTRY, i16, i16, i16, i8, i8, %struct._LIST_ENTRY, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }

@.str.11 = external hidden unnamed_addr constant [2 x i32], align 4
@.str.29 = external hidden unnamed_addr constant [2 x i32], align 4

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

declare ptr @StrStr(ptr noundef, ptr noundef) #1

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

declare ptr @AllocateZeroPool(i64 noundef) #1

declare void @FreePool(ptr noundef) #1

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

declare i64 @StrSize(ptr noundef) #1

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

declare ptr @InitializeListHead(ptr noundef) #1

declare ptr @RemoveEntryList(ptr noundef) #1

declare zeroext i8 @IsListEmpty(ptr noundef) #1

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

16:                                               ; preds = %2
  br label %80

17:                                               ; preds = %2
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %18, i32 0, i32 0
  %20 = call ptr @InitializeListHead(ptr noundef %19)
  br label %21

21:                                               ; preds = %77, %17
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %29

24:                                               ; preds = %21
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i16, ptr %25, align 2, !tbaa !9
  %27 = zext i16 %26 to i32
  %28 = icmp eq i32 %27, 38
  br label %29

29:                                               ; preds = %24, %21
  %30 = phi i1 [ false, %21 ], [ %28, %24 ]
  br i1 %30, label %31, label %78

31:                                               ; preds = %29
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %32, ptr %33, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds i16, ptr %34, i64 1
  store ptr %35, ptr %6, align 8, !tbaa !5
  store i8 0, ptr %10, align 1, !tbaa !11
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = call ptr @StrStr(ptr noundef %36, ptr noundef @.str.29)
  store ptr %37, ptr %7, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %41

39:                                               ; preds = %31
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  store i16 0, ptr %40, align 2, !tbaa !9
  store i8 1, ptr %10, align 1, !tbaa !11
  br label %48

41:                                               ; preds = %31
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call ptr @StrStr(ptr noundef %42, ptr noundef @.str.11)
  store ptr %43, ptr %7, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %47

45:                                               ; preds = %41
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  store i16 0, ptr %46, align 2, !tbaa !9
  br label %47

47:                                               ; preds = %45, %41
  br label %48

48:                                               ; preds = %47, %39
  %49 = call ptr @AllocateZeroPool(i64 noundef 48)
  store ptr %49, ptr %8, align 8, !tbaa !5
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = icmp eq ptr %50, null
  br i1 %51, label %52, label %53

52:                                               ; preds = %48
  br label %80

53:                                               ; preds = %48
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = call i64 @StrSize(ptr noundef %54)
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = call ptr @AllocateCopyPool(i64 noundef %55, ptr noundef %56)
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %58, i32 0, i32 7
  store ptr %57, ptr %59, align 8, !tbaa !12
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %60, i32 0, i32 0
  call void @InsertBlockData(ptr noundef %61, ptr noundef %8)
  %62 = load i8, ptr %10, align 1, !tbaa !11
  %63 = icmp ne i8 %62, 0
  br i1 %63, label %64, label %70

64:                                               ; preds = %53
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds i16, ptr %65, i64 1
  store ptr %66, ptr %6, align 8, !tbaa !5
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  store i16 61, ptr %67, align 2, !tbaa !9
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = call ptr @StrStr(ptr noundef %68, ptr noundef @.str.11)
  store ptr %69, ptr %6, align 8, !tbaa !5
  br label %77

70:                                               ; preds = %53
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = icmp ne ptr %71, null
  br i1 %72, label %73, label %76

73:                                               ; preds = %70
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %74, ptr %6, align 8, !tbaa !5
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  store i16 38, ptr %75, align 2, !tbaa !9
  br label %76

76:                                               ; preds = %73, %70
  br label %77

77:                                               ; preds = %76, %64
  br label %21, !llvm.loop !15

78:                                               ; preds = %29
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %79, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %114

80:                                               ; preds = %52, %16
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %113

83:                                               ; preds = %80
  br label %84

84:                                               ; preds = %109, %83
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %85, i32 0, i32 0
  %87 = call zeroext i8 @IsListEmpty(ptr noundef %86)
  %88 = icmp ne i8 %87, 0
  %89 = xor i1 %88, true
  br i1 %89, label %90, label %111

90:                                               ; preds = %84
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %91, i32 0, i32 0
  %93 = getelementptr inbounds %struct._LIST_ENTRY, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !17
  %95 = ptrtoint ptr %94 to i64
  %96 = sub i64 %95, 0
  %97 = inttoptr i64 %96 to ptr
  store ptr %97, ptr %8, align 8, !tbaa !5
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %98, i32 0, i32 0
  %100 = call ptr @RemoveEntryList(ptr noundef %99)
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %101, i32 0, i32 7
  %103 = load ptr, ptr %102, align 8, !tbaa !12
  %104 = icmp ne ptr %103, null
  br i1 %104, label %105, label %109

105:                                              ; preds = %90
  %106 = load ptr, ptr %8, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.IFR_BLOCK_DATA, ptr %106, i32 0, i32 7
  %108 = load ptr, ptr %107, align 8, !tbaa !12
  call void @FreePool(ptr noundef %108)
  br label %109

109:                                              ; preds = %105, %90
  %110 = load ptr, ptr %8, align 8, !tbaa !5
  call void @FreePool(ptr noundef %110)
  br label %84, !llvm.loop !18

111:                                              ; preds = %84
  %112 = load ptr, ptr %9, align 8, !tbaa !5
  call void @FreePool(ptr noundef %112)
  br label %113

113:                                              ; preds = %111, %80
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %114

114:                                              ; preds = %113, %78
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  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
  %115 = load ptr, ptr %3, align 8
  ret ptr %115
}

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 }

!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 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 40}
!13 = !{!"", !14, i64 0, !10, i64 16, !10, i64 18, !10, i64 20, !7, i64 22, !7, i64 23, !14, i64 24, !6, i64 40}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!13, !6, i64 0}
!18 = distinct !{!18, !16}


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

@.str.11 = external hidden unnamed_addr constant [2 x i32], align 4
@.str.29 = external hidden unnamed_addr constant [2 x i32], align 4

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

declare ptr @StrStr(ptr noundef, ptr noundef) local_unnamed_addr #1

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

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #1

declare void @FreePool(ptr noundef) local_unnamed_addr #1

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

declare i64 @StrSize(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @InsertBlockData(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @InitializeListHead(ptr noundef) local_unnamed_addr #1

declare ptr @RemoveEntryList(ptr noundef) local_unnamed_addr #1

declare zeroext i8 @IsListEmpty(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @GetNameElement(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #2 {
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = tail call ptr @AllocateZeroPool(i64 noundef 48) #3
  %cond = icmp eq ptr %4, null
  br i1 %cond, label %.critedge, label %5

5:                                                ; preds = %2
  %6 = tail call ptr @InitializeListHead(ptr noundef nonnull %4) #3
  %.not42 = icmp eq ptr %0, null
  br i1 %.not42, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %28
  %.02943 = phi ptr [ %.1, %28 ], [ %0, %5 ]
  %7 = load i16, ptr %.02943, align 2, !tbaa !5
  %8 = icmp eq i16 %7, 38
  br i1 %8, label %9, label %.critedge

9:                                                ; preds = %.lr.ph
  store ptr %.02943, ptr %1, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %.02943, i64 2
  %11 = call ptr @StrStr(ptr noundef nonnull %10, ptr noundef nonnull @.str.29) #3
  %.not35 = icmp eq ptr %11, null
  br i1 %.not35, label %12, label %.sink.split

12:                                               ; preds = %9
  %13 = call ptr @StrStr(ptr noundef nonnull %10, ptr noundef nonnull @.str.11) #3
  %.not36 = icmp eq ptr %13, null
  br i1 %.not36, label %14, label %.sink.split

.sink.split:                                      ; preds = %12, %9
  %.sink = phi ptr [ %11, %9 ], [ %13, %12 ]
  store i16 0, ptr %.sink, align 2, !tbaa !5
  br label %14

14:                                               ; preds = %.sink.split, %12
  %.028 = phi ptr [ null, %12 ], [ %.sink, %.sink.split ]
  %15 = call ptr @AllocateZeroPool(i64 noundef 48) #3
  store ptr %15, ptr %3, align 8, !tbaa !9
  %16 = icmp eq ptr %15, null
  br i1 %16, label %.preheader, label %18

.preheader:                                       ; preds = %14
  %17 = call zeroext i8 @IsListEmpty(ptr noundef nonnull %4) #3
  %.not4045 = icmp eq i8 %17, 0
  br i1 %.not4045, label %.lr.ph46, label %._crit_edge

18:                                               ; preds = %14
  %19 = call i64 @StrSize(ptr noundef nonnull %10) #3
  %20 = call ptr @AllocateCopyPool(i64 noundef %19, ptr noundef nonnull %10) #3
  %21 = load ptr, ptr %3, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %21, i64 40
  store ptr %20, ptr %22, align 8, !tbaa !11
  call void @InsertBlockData(ptr noundef nonnull %4, ptr noundef nonnull %3)
  br i1 %.not35, label %26, label %23

23:                                               ; preds = %18
  %24 = getelementptr inbounds i8, ptr %.028, i64 2
  store i16 61, ptr %.028, align 2, !tbaa !5
  %25 = call ptr @StrStr(ptr noundef nonnull %24, ptr noundef nonnull @.str.11) #3
  br label %28

26:                                               ; preds = %18
  %.not38 = icmp eq ptr %.028, null
  br i1 %.not38, label %28, label %27

27:                                               ; preds = %26
  store i16 38, ptr %.028, align 2, !tbaa !5
  br label %28

28:                                               ; preds = %26, %27, %23
  %.1 = phi ptr [ %25, %23 ], [ %.028, %27 ], [ %10, %26 ]
  %.not = icmp eq ptr %.1, null
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !14

.lr.ph46:                                         ; preds = %.preheader, %35
  %29 = load ptr, ptr %4, align 8, !tbaa !16
  store ptr %29, ptr %3, align 8, !tbaa !9
  %30 = call ptr @RemoveEntryList(ptr noundef %29) #3
  %31 = load ptr, ptr %3, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %31, i64 40
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %.not41 = icmp eq ptr %33, null
  br i1 %.not41, label %35, label %34

34:                                               ; preds = %.lr.ph46
  call void @FreePool(ptr noundef nonnull %33) #3
  %.pre = load ptr, ptr %3, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %34, %.lr.ph46
  %36 = phi ptr [ %.pre, %34 ], [ %31, %.lr.ph46 ]
  call void @FreePool(ptr noundef %36) #3
  %37 = call zeroext i8 @IsListEmpty(ptr noundef nonnull %4) #3
  %.not40 = icmp eq i8 %37, 0
  br i1 %.not40, label %.lr.ph46, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %35, %.preheader
  call void @FreePool(ptr noundef nonnull %4) #3
  br label %.critedge

.critedge:                                        ; preds = %28, %.lr.ph, %5, %2, %._crit_edge
  %.027 = phi ptr [ null, %2 ], [ null, %._crit_edge ], [ %4, %5 ], [ %4, %.lr.ph ], [ %4, %28 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret ptr %.027
}

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

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 40}
!12 = !{!"", !13, i64 0, !6, i64 16, !6, i64 18, !6, i64 20, !7, i64 22, !7, i64 23, !13, i64 24, !10, i64 40}
!13 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!12, !10, i64 0}
!17 = distinct !{!17, !15}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass