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

; 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._EFI_HII_STRING_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [145 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1
@gHiiString = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @HiiSetString(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i16 %1, ptr %7, align 2, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  br label %15

15:                                               ; preds = %4
  %16 = call zeroext i8 @DebugAssertEnabled()
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %18, label %23

18:                                               ; preds = %15
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  call void @DebugAssert(ptr noundef @.str, i64 noundef 70, ptr noundef @.str.1)
  br label %22

22:                                               ; preds = %21, %18
  br label %23

23:                                               ; preds = %22, %15
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = call zeroext i8 @DebugAssertEnabled()
  %28 = icmp ne i8 %27, 0
  br i1 %28, label %29, label %34

29:                                               ; preds = %26
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  call void @DebugAssert(ptr noundef @.str, i64 noundef 71, ptr noundef @.str.2)
  br label %33

33:                                               ; preds = %32, %29
  br label %34

34:                                               ; preds = %33, %26
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %42

39:                                               ; preds = %36
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = call ptr @HiiGetSupportedLanguages(ptr noundef %40)
  store ptr %41, ptr %11, align 8, !tbaa !5
  br label %47

42:                                               ; preds = %36
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = call i64 @AsciiStrSize(ptr noundef %43)
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = call ptr @AllocateCopyPool(i64 noundef %44, ptr noundef %45)
  store ptr %46, ptr %11, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %42, %39
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %51

50:                                               ; preds = %47
  store i16 0, ptr %5, align 2
  store i32 1, ptr %14, align 4
  br label %119

51:                                               ; preds = %47
  store i64 -9223372036854775806, ptr %10, align 8, !tbaa !11
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %52, ptr %12, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %111, %51
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = load i8, ptr %54, align 1, !tbaa !13
  %56 = sext i8 %55 to i32
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %112

58:                                               ; preds = %53
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %59, ptr %13, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %73, %58
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = load i8, ptr %61, align 1, !tbaa !13
  %63 = sext i8 %62 to i32
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %70

65:                                               ; preds = %60
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  %67 = load i8, ptr %66, align 1, !tbaa !13
  %68 = sext i8 %67 to i32
  %69 = icmp ne i32 %68, 59
  br label %70

70:                                               ; preds = %65, %60
  %71 = phi i1 [ false, %60 ], [ %69, %65 ]
  br i1 %71, label %72, label %76

72:                                               ; preds = %70
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i32 1
  store ptr %75, ptr %12, align 8, !tbaa !5
  br label %60, !llvm.loop !14

76:                                               ; preds = %70
  %77 = load ptr, ptr %12, align 8, !tbaa !5
  %78 = load i8, ptr %77, align 1, !tbaa !13
  %79 = sext i8 %78 to i32
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %84

81:                                               ; preds = %76
  %82 = load ptr, ptr %12, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i32 1
  store ptr %83, ptr %12, align 8, !tbaa !5
  store i8 0, ptr %82, align 1, !tbaa !13
  br label %84

84:                                               ; preds = %81, %76
  %85 = load i16, ptr %7, align 2, !tbaa !9
  %86 = zext i16 %85 to i32
  %87 = icmp eq i32 %86, 0
  br i1 %87, label %88, label %97

88:                                               ; preds = %84
  %89 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct._EFI_HII_STRING_PROTOCOL, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !16
  %92 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = load ptr, ptr %13, align 8, !tbaa !5
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = call i64 %91(ptr noundef %92, ptr noundef %93, ptr noundef %7, ptr noundef %94, ptr noundef null, ptr noundef %95, ptr noundef null)
  store i64 %96, ptr %10, align 8, !tbaa !11
  br label %107

97:                                               ; preds = %84
  %98 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct._EFI_HII_STRING_PROTOCOL, ptr %98, i32 0, i32 2
  %100 = load ptr, ptr %99, align 8, !tbaa !18
  %101 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = load i16, ptr %7, align 2, !tbaa !9
  %104 = load ptr, ptr %13, align 8, !tbaa !5
  %105 = load ptr, ptr %8, align 8, !tbaa !5
  %106 = call i64 %100(ptr noundef %101, ptr noundef %102, i16 noundef zeroext %103, ptr noundef %104, ptr noundef %105, ptr noundef null)
  store i64 %106, ptr %10, align 8, !tbaa !11
  br label %107

107:                                              ; preds = %97, %88
  %108 = load i64, ptr %10, align 8, !tbaa !11
  %109 = icmp slt i64 %108, 0
  br i1 %109, label %110, label %111

110:                                              ; preds = %107
  br label %112

111:                                              ; preds = %107
  br label %53, !llvm.loop !19

112:                                              ; preds = %110, %53
  %113 = load ptr, ptr %11, align 8, !tbaa !5
  call void @FreePool(ptr noundef %113)
  %114 = load i64, ptr %10, align 8, !tbaa !11
  %115 = icmp slt i64 %114, 0
  br i1 %115, label %116, label %117

116:                                              ; preds = %112
  store i16 0, ptr %5, align 2
  store i32 1, ptr %14, align 4
  br label %119

117:                                              ; preds = %112
  %118 = load i16, ptr %7, align 2, !tbaa !9
  store i16 %118, ptr %5, align 2
  store i32 1, ptr %14, align 4
  br label %119

119:                                              ; preds = %117, %116, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %120 = load i16, ptr %5, align 2
  ret i16 %120
}

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

declare zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #2

declare ptr @HiiGetSupportedLanguages(ptr noundef) #2

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

declare i64 @AsciiStrSize(ptr noundef) #2

declare void @FreePool(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"_EFI_HII_STRING_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!18 = !{!17, !6, i64 16}
!19 = distinct !{!19, !15}


; 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 = external hidden unnamed_addr constant [145 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1
@gHiiString = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @HiiSetString(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca i16, align 2
  store i16 %1, ptr %5, align 2, !tbaa !5
  %6 = tail call zeroext i8 @DebugAssertEnabled() #2
  %7 = icmp eq i8 %6, 0
  %8 = icmp ne ptr %0, null
  %or.cond = or i1 %8, %7
  br i1 %or.cond, label %10, label %9

9:                                                ; preds = %4
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 70, ptr noundef nonnull @.str.1) #2
  br label %10

10:                                               ; preds = %4, %9
  %11 = tail call zeroext i8 @DebugAssertEnabled() #2
  %12 = icmp eq i8 %11, 0
  %13 = icmp ne ptr %2, null
  %or.cond3 = or i1 %13, %12
  br i1 %or.cond3, label %15, label %14

14:                                               ; preds = %10
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 71, ptr noundef nonnull @.str.2) #2
  br label %15

15:                                               ; preds = %14, %10
  %16 = icmp eq ptr %3, null
  br i1 %16, label %17, label %19

17:                                               ; preds = %15
  %18 = tail call ptr @HiiGetSupportedLanguages(ptr noundef %0) #2
  br label %22

19:                                               ; preds = %15
  %20 = tail call i64 @AsciiStrSize(ptr noundef nonnull %3) #2
  %21 = tail call ptr @AllocateCopyPool(i64 noundef %20, ptr noundef nonnull %3) #2
  br label %22

22:                                               ; preds = %19, %17
  %.028 = phi ptr [ %18, %17 ], [ %21, %19 ]
  %23 = icmp eq ptr %.028, null
  br i1 %23, label %47, label %.preheader37

.preheader37:                                     ; preds = %22
  %24 = load i8, ptr %.028, align 1, !tbaa !9
  %.not39 = icmp eq i8 %24, 0
  br i1 %.not39, label %.loopexit45, label %.preheader

25:                                               ; preds = %44
  %26 = load i8, ptr %.2, align 1, !tbaa !9
  %.not = icmp eq i8 %26, 0
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !10

.preheader:                                       ; preds = %.preheader37, %25
  %27 = phi i8 [ %26, %25 ], [ %24, %.preheader37 ]
  %.02740 = phi ptr [ %.2, %25 ], [ %.028, %.preheader37 ]
  br label %28

28:                                               ; preds = %.preheader, %30
  %29 = phi i8 [ %.pr, %30 ], [ %27, %.preheader ]
  %.1 = phi ptr [ %31, %30 ], [ %.02740, %.preheader ]
  switch i8 %29, label %30 [
    i8 0, label %.loopexit
    i8 59, label %32
  ]

30:                                               ; preds = %28
  %31 = getelementptr inbounds i8, ptr %.1, i64 1
  %.pr = load i8, ptr %31, align 1, !tbaa !9
  br label %28, !llvm.loop !12

32:                                               ; preds = %28
  %33 = getelementptr inbounds i8, ptr %.1, i64 1
  store i8 0, ptr %.1, align 1, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %28, %32
  %.2 = phi ptr [ %33, %32 ], [ %.1, %28 ]
  %34 = load i16, ptr %5, align 2, !tbaa !5
  %35 = icmp eq i16 %34, 0
  %36 = load ptr, ptr @gHiiString, align 8, !tbaa !13
  br i1 %35, label %37, label %40

37:                                               ; preds = %.loopexit
  %38 = load ptr, ptr %36, align 8, !tbaa !15
  %39 = call i64 %38(ptr noundef nonnull %36, ptr noundef %0, ptr noundef nonnull %5, ptr noundef nonnull %.02740, ptr noundef null, ptr noundef %2, ptr noundef null) #2
  br label %44

40:                                               ; preds = %.loopexit
  %41 = getelementptr inbounds i8, ptr %36, i64 16
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = call i64 %42(ptr noundef %36, ptr noundef %0, i16 noundef zeroext %34, ptr noundef nonnull %.02740, ptr noundef %2, ptr noundef null) #2
  br label %44

44:                                               ; preds = %40, %37
  %.130 = phi i64 [ %39, %37 ], [ %43, %40 ]
  %45 = icmp slt i64 %.130, 0
  br i1 %45, label %.loopexit45, label %25, !llvm.loop !10

._crit_edge:                                      ; preds = %25
  call void @FreePool(ptr noundef nonnull %.028) #2
  %46 = load i16, ptr %5, align 2
  br label %47

.loopexit45:                                      ; preds = %44, %.preheader37
  call void @FreePool(ptr noundef nonnull %.028) #2
  br label %47

47:                                               ; preds = %.loopexit45, %._crit_edge, %22
  %.0 = phi i16 [ 0, %22 ], [ 0, %.loopexit45 ], [ %46, %._crit_edge ]
  ret i16 %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare ptr @HiiGetSupportedLanguages(ptr noundef) local_unnamed_addr #1

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

declare i64 @AsciiStrSize(ptr noundef) local_unnamed_addr #1

declare void @FreePool(ptr 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 = { "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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!16, !14, i64 0}
!16 = !{!"_EFI_HII_STRING_PROTOCOL", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!17 = !{!16, !14, i64 16}


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