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

; 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.HEFI_EDITOR_GLOBAL_EDITOR = type { ptr, %union.HEFI_EDITOR_COLOR_UNION, %struct.HEFI_EDITOR_POSITION, i8, ptr, i32, i32, i64, i64 }
%union.HEFI_EDITOR_COLOR_UNION = type { i64 }
%struct.HEFI_EDITOR_POSITION = type { i64, i64 }
%struct._EFI_SIMPLE_POINTER_PROTOCOL = type { ptr, ptr, ptr, ptr }
%struct.EFI_SIMPLE_POINTER_MODE = type { i64, i64, i64, i8, i8 }

@HMainEditor = external global %struct.HEFI_EDITOR_GLOBAL_EDITOR, align 8

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

; 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 i32 @HGetTextX(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 5), align 8, !tbaa !9
  %6 = add nsw i32 %5, %4
  store i32 %6, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 5), align 8, !tbaa !9
  %7 = load i32, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 5), align 8, !tbaa !9
  %8 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 2), i32 0, i32 1), align 8, !tbaa !14
  %9 = trunc i64 %8 to i32
  %10 = mul nsw i32 %7, %9
  %11 = load ptr, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 4), align 8, !tbaa !15
  %12 = getelementptr inbounds %struct._EFI_SIMPLE_POINTER_PROTOCOL, ptr %11, i32 0, i32 3
  %13 = load ptr, ptr %12, align 8, !tbaa !16
  %14 = getelementptr inbounds %struct.EFI_SIMPLE_POINTER_MODE, ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !18
  %16 = trunc i64 %15 to i32
  %17 = mul nsw i32 50, %16
  %18 = sdiv i32 %10, %17
  store i32 %18, ptr %3, align 4, !tbaa !5
  %19 = load i32, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 5), align 8, !tbaa !9
  %20 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 2), i32 0, i32 1), align 8, !tbaa !14
  %21 = trunc i64 %20 to i32
  %22 = mul nsw i32 %19, %21
  %23 = load ptr, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 4), align 8, !tbaa !15
  %24 = getelementptr inbounds %struct._EFI_SIMPLE_POINTER_PROTOCOL, ptr %23, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = getelementptr inbounds %struct.EFI_SIMPLE_POINTER_MODE, ptr %25, i32 0, i32 0
  %27 = load i64, ptr %26, align 8, !tbaa !18
  %28 = trunc i64 %27 to i32
  %29 = mul nsw i32 50, %28
  %30 = srem i32 %22, %29
  store i32 %30, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 5), align 8, !tbaa !9
  %31 = load i32, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 5), align 8, !tbaa !9
  %32 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 2), i32 0, i32 1), align 8, !tbaa !14
  %33 = trunc i64 %32 to i32
  %34 = sdiv i32 %31, %33
  store i32 %34, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 5), align 8, !tbaa !9
  %35 = load i32, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %35
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 48}
!10 = !{!"", !11, i64 0, !7, i64 8, !12, i64 16, !7, i64 32, !11, i64 40, !6, i64 48, !6, i64 52, !13, i64 56, !13, i64 64}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8}
!13 = !{!"long long", !7, i64 0}
!14 = !{!10, !13, i64 24}
!15 = !{!10, !11, i64 40}
!16 = !{!17, !11, i64 24}
!17 = !{!"_EFI_SIMPLE_POINTER_PROTOCOL", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!18 = !{!19, !13, i64 0}
!19 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !7, i64 24, !7, i64 25}


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

%struct.HEFI_EDITOR_GLOBAL_EDITOR = type { ptr, %union.HEFI_EDITOR_COLOR_UNION, %struct.HEFI_EDITOR_POSITION, i8, ptr, i32, i32, i64, i64 }
%union.HEFI_EDITOR_COLOR_UNION = type { i64 }
%struct.HEFI_EDITOR_POSITION = type { i64, i64 }

@HMainEditor = external local_unnamed_addr global %struct.HEFI_EDITOR_GLOBAL_EDITOR, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local i32 @HGetTextX(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @HMainEditor, i64 48), align 8, !tbaa !5
  %3 = add nsw i32 %2, %0
  %4 = load i64, ptr getelementptr inbounds (i8, ptr @HMainEditor, i64 24), align 8, !tbaa !13
  %5 = trunc i64 %4 to i32
  %6 = mul nsw i32 %3, %5
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @HMainEditor, i64 40), align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %7, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = load i64, ptr %9, align 8, !tbaa !17
  %11 = trunc i64 %10 to i32
  %12 = mul nsw i32 %11, 50
  %13 = sdiv i32 %6, %12
  %14 = srem i32 %6, %12
  %15 = sdiv i32 %14, %5
  store i32 %15, ptr getelementptr inbounds (i8, ptr @HMainEditor, i64 48), align 8, !tbaa !5
  ret i32 %13
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none) 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" }

!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, !12, i64 48}
!6 = !{!"", !7, i64 0, !8, i64 8, !10, i64 16, !8, i64 32, !7, i64 40, !12, i64 48, !12, i64 52, !11, i64 56, !11, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !11, i64 24}
!14 = !{!6, !7, i64 40}
!15 = !{!16, !7, i64 24}
!16 = !{!"_EFI_SIMPLE_POINTER_PROTOCOL", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!17 = !{!18, !11, i64 0}
!18 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !8, i64 24, !8, i64 25}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass