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

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

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [29 x i8], align 1

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

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 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

; Function Attrs: nounwind uwtable
define dso_local void @HiiToLower(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  br label %5

5:                                                ; preds = %1
  %6 = call zeroext i8 @DebugAssertEnabled()
  %7 = icmp ne i8 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @DebugAssert(ptr noundef @.str, i64 noundef 183, ptr noundef @.str.6)
  br label %12

12:                                               ; preds = %11, %8
  br label %13

13:                                               ; preds = %12, %5
  br label %14

14:                                               ; preds = %13
  br label %15

15:                                               ; preds = %14
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %16, ptr %3, align 8, !tbaa !5
  store i8 0, ptr %4, align 1, !tbaa !9
  br label %17

17:                                               ; preds = %59, %15
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i16, ptr %18, align 2, !tbaa !10
  %20 = zext i16 %19 to i32
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %62

22:                                               ; preds = %17
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i16, ptr %23, align 2, !tbaa !10
  %25 = zext i16 %24 to i32
  %26 = icmp eq i32 %25, 61
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  store i8 1, ptr %4, align 1, !tbaa !9
  br label %58

28:                                               ; preds = %22
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i16, ptr %29, align 2, !tbaa !10
  %31 = zext i16 %30 to i32
  %32 = icmp eq i32 %31, 38
  br i1 %32, label %33, label %34

33:                                               ; preds = %28
  store i8 0, ptr %4, align 1, !tbaa !9
  br label %57

34:                                               ; preds = %28
  %35 = load i8, ptr %4, align 1, !tbaa !9
  %36 = zext i8 %35 to i32
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %56

38:                                               ; preds = %34
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load i16, ptr %39, align 2, !tbaa !10
  %41 = zext i16 %40 to i32
  %42 = icmp sge i32 %41, 65
  br i1 %42, label %43, label %56

43:                                               ; preds = %38
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load i16, ptr %44, align 2, !tbaa !10
  %46 = zext i16 %45 to i32
  %47 = icmp sle i32 %46, 70
  br i1 %47, label %48, label %56

48:                                               ; preds = %43
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load i16, ptr %49, align 2, !tbaa !10
  %51 = zext i16 %50 to i32
  %52 = sub nsw i32 %51, 65
  %53 = add nsw i32 %52, 97
  %54 = trunc i32 %53 to i16
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  store i16 %54, ptr %55, align 2, !tbaa !10
  br label %56

56:                                               ; preds = %48, %43, %38, %34
  br label %57

57:                                               ; preds = %56, %33
  br label %58

58:                                               ; preds = %57, %27
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds i16, ptr %60, i32 1
  store ptr %61, ptr %3, align 8, !tbaa !5
  br label %17, !llvm.loop !12

62:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [29 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @HiiToLower(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call zeroext i8 @DebugAssertEnabled() #2
  %3 = icmp eq i8 %2, 0
  %4 = icmp ne ptr %0, null
  %or.cond = or i1 %4, %3
  br i1 %or.cond, label %.preheader, label %5

5:                                                ; preds = %1
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 183, ptr noundef nonnull @.str.6) #2
  br label %.preheader

.preheader:                                       ; preds = %5, %1
  br label %6

6:                                                ; preds = %.preheader, %13
  %.011 = phi ptr [ %14, %13 ], [ %0, %.preheader ]
  %.0 = phi i8 [ %.1, %13 ], [ 0, %.preheader ]
  %7 = load i16, ptr %.011, align 2, !tbaa !5
  switch i16 %7, label %9 [
    i16 0, label %15
    i16 61, label %13
    i16 38, label %8
  ]

8:                                                ; preds = %6
  br label %13

9:                                                ; preds = %6
  %.not13 = icmp ne i8 %.0, 0
  %10 = add i16 %7, -65
  %11 = icmp ult i16 %10, 6
  %or.cond15 = and i1 %.not13, %11
  br i1 %or.cond15, label %12, label %13

12:                                               ; preds = %9
  %narrow = or disjoint i16 %7, 32
  store i16 %narrow, ptr %.011, align 2, !tbaa !5
  br label %13

13:                                               ; preds = %6, %9, %12, %8
  %.1 = phi i8 [ 0, %8 ], [ %.0, %12 ], [ %.0, %9 ], [ 1, %6 ]
  %14 = getelementptr inbounds i8, ptr %.011, i64 2
  br label %6, !llvm.loop !9

15:                                               ; preds = %6
  ret void
}

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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass