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

; 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.ICMP_ERROR_INFO = type { i8, i8 }

@mIcmpErrMap = external dso_local global [10 x %struct.ICMP_ERROR_INFO], align 16
@mIcmp6ErrMap = external dso_local global [10 x %struct.ICMP_ERROR_INFO], align 16
@.str = external hidden unnamed_addr constant [146 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [18 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @IpIoGetIcmpErrStatus(i8 noundef zeroext %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store i8 %0, ptr %6, align 1, !tbaa !5
  store i8 %1, ptr %7, align 1, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !8
  store ptr %3, ptr %9, align 8, !tbaa !8
  %10 = load i8, ptr %7, align 1, !tbaa !5
  %11 = zext i8 %10 to i32
  %12 = icmp eq i32 %11, 4
  br i1 %12, label %13, label %59

13:                                               ; preds = %4
  br label %14

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

17:                                               ; preds = %14
  %18 = load i8, ptr %6, align 1, !tbaa !5
  %19 = zext i8 %18 to i32
  %20 = icmp sle i32 %19, 9
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @DebugAssert(ptr noundef @.str, i64 noundef 2024, ptr noundef @.str.11)
  br label %22

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

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

24:                                               ; preds = %23
  %25 = load ptr, ptr %8, align 8, !tbaa !8
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %34

27:                                               ; preds = %24
  %28 = load i8, ptr %6, align 1, !tbaa !5
  %29 = zext i8 %28 to i64
  %30 = getelementptr inbounds [10 x %struct.ICMP_ERROR_INFO], ptr @mIcmpErrMap, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.ICMP_ERROR_INFO, ptr %30, i32 0, i32 0
  %32 = load i8, ptr %31, align 2, !tbaa !10
  %33 = load ptr, ptr %8, align 8, !tbaa !8
  store i8 %32, ptr %33, align 1, !tbaa !5
  br label %34

34:                                               ; preds = %27, %24
  %35 = load ptr, ptr %9, align 8, !tbaa !8
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %44

37:                                               ; preds = %34
  %38 = load i8, ptr %6, align 1, !tbaa !5
  %39 = zext i8 %38 to i64
  %40 = getelementptr inbounds [10 x %struct.ICMP_ERROR_INFO], ptr @mIcmpErrMap, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.ICMP_ERROR_INFO, ptr %40, i32 0, i32 1
  %42 = load i8, ptr %41, align 1, !tbaa !12
  %43 = load ptr, ptr %9, align 8, !tbaa !8
  store i8 %42, ptr %43, align 1, !tbaa !5
  br label %44

44:                                               ; preds = %37, %34
  %45 = load i8, ptr %6, align 1, !tbaa !5
  %46 = zext i8 %45 to i32
  switch i32 %46, label %52 [
    i32 0, label %47
    i32 6, label %48
    i32 7, label %48
    i32 1, label %48
    i32 2, label %49
    i32 3, label %50
    i32 4, label %51
    i32 5, label %51
    i32 8, label %51
    i32 9, label %51
  ]

47:                                               ; preds = %44
  store i64 -9223372036854775708, ptr %5, align 8
  br label %116

48:                                               ; preds = %44, %44, %44
  store i64 -9223372036854775707, ptr %5, align 8
  br label %116

49:                                               ; preds = %44
  store i64 -9223372036854775706, ptr %5, align 8
  br label %116

50:                                               ; preds = %44
  store i64 -9223372036854775705, ptr %5, align 8
  br label %116

51:                                               ; preds = %44, %44, %44, %44
  store i64 -9223372036854775786, ptr %5, align 8
  br label %116

52:                                               ; preds = %44
  br label %53

53:                                               ; preds = %52
  %54 = call zeroext i8 @DebugAssertEnabled()
  %55 = icmp ne i8 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %53
  call void @DebugAssert(ptr noundef @.str, i64 noundef 2056, ptr noundef @.str.12)
  br label %57

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

58:                                               ; preds = %57
  store i64 -9223372036854775805, ptr %5, align 8
  br label %116

59:                                               ; preds = %4
  %60 = load i8, ptr %7, align 1, !tbaa !5
  %61 = zext i8 %60 to i32
  %62 = icmp eq i32 %61, 6
  br i1 %62, label %63, label %109

63:                                               ; preds = %59
  br label %64

64:                                               ; preds = %63
  %65 = call zeroext i8 @DebugAssertEnabled()
  %66 = icmp ne i8 %65, 0
  br i1 %66, label %67, label %73

67:                                               ; preds = %64
  %68 = load i8, ptr %6, align 1, !tbaa !5
  %69 = zext i8 %68 to i32
  %70 = icmp sle i32 %69, 9
  br i1 %70, label %72, label %71

71:                                               ; preds = %67
  call void @DebugAssert(ptr noundef @.str, i64 noundef 2062, ptr noundef @.str.11)
  br label %72

72:                                               ; preds = %71, %67
  br label %73

73:                                               ; preds = %72, %64
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr %8, align 8, !tbaa !8
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %84

77:                                               ; preds = %74
  %78 = load i8, ptr %6, align 1, !tbaa !5
  %79 = zext i8 %78 to i64
  %80 = getelementptr inbounds [10 x %struct.ICMP_ERROR_INFO], ptr @mIcmp6ErrMap, i64 0, i64 %79
  %81 = getelementptr inbounds %struct.ICMP_ERROR_INFO, ptr %80, i32 0, i32 0
  %82 = load i8, ptr %81, align 2, !tbaa !10
  %83 = load ptr, ptr %8, align 8, !tbaa !8
  store i8 %82, ptr %83, align 1, !tbaa !5
  br label %84

84:                                               ; preds = %77, %74
  %85 = load ptr, ptr %9, align 8, !tbaa !8
  %86 = icmp ne ptr %85, null
  br i1 %86, label %87, label %94

87:                                               ; preds = %84
  %88 = load i8, ptr %6, align 1, !tbaa !5
  %89 = zext i8 %88 to i64
  %90 = getelementptr inbounds [10 x %struct.ICMP_ERROR_INFO], ptr @mIcmp6ErrMap, i64 0, i64 %89
  %91 = getelementptr inbounds %struct.ICMP_ERROR_INFO, ptr %90, i32 0, i32 1
  %92 = load i8, ptr %91, align 1, !tbaa !12
  %93 = load ptr, ptr %9, align 8, !tbaa !8
  store i8 %92, ptr %93, align 1, !tbaa !5
  br label %94

94:                                               ; preds = %87, %84
  %95 = load i8, ptr %6, align 1, !tbaa !5
  %96 = zext i8 %95 to i32
  switch i32 %96, label %102 [
    i32 0, label %97
    i32 1, label %98
    i32 5, label %98
    i32 6, label %98
    i32 2, label %99
    i32 3, label %100
    i32 4, label %101
    i32 7, label %101
    i32 8, label %101
    i32 9, label %101
  ]

97:                                               ; preds = %94
  store i64 -9223372036854775708, ptr %5, align 8
  br label %116

98:                                               ; preds = %94, %94, %94
  store i64 -9223372036854775707, ptr %5, align 8
  br label %116

99:                                               ; preds = %94
  store i64 -9223372036854775706, ptr %5, align 8
  br label %116

100:                                              ; preds = %94
  store i64 -9223372036854775705, ptr %5, align 8
  br label %116

101:                                              ; preds = %94, %94, %94, %94
  store i64 -9223372036854775786, ptr %5, align 8
  br label %116

102:                                              ; preds = %94
  br label %103

103:                                              ; preds = %102
  %104 = call zeroext i8 @DebugAssertEnabled()
  %105 = icmp ne i8 %104, 0
  br i1 %105, label %106, label %107

106:                                              ; preds = %103
  call void @DebugAssert(ptr noundef @.str, i64 noundef 2094, ptr noundef @.str.12)
  br label %107

107:                                              ; preds = %106, %103
  br label %108

108:                                              ; preds = %107
  store i64 -9223372036854775805, ptr %5, align 8
  br label %116

109:                                              ; preds = %59
  br label %110

110:                                              ; preds = %109
  %111 = call zeroext i8 @DebugAssertEnabled()
  %112 = icmp ne i8 %111, 0
  br i1 %112, label %113, label %114

113:                                              ; preds = %110
  call void @DebugAssert(ptr noundef @.str, i64 noundef 2102, ptr noundef @.str.12)
  br label %114

114:                                              ; preds = %113, %110
  br label %115

115:                                              ; preds = %114
  store i64 -9223372036854775805, ptr %5, align 8
  br label %116

116:                                              ; preds = %115, %108, %101, %100, %99, %98, %97, %58, %51, %50, %49, %48, %47
  %117 = load i64, ptr %5, align 8
  ret i64 %117
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"", !6, i64 0, !6, i64 1}
!12 = !{!11, !6, i64 1}


; 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.ICMP_ERROR_INFO = type { i8, i8 }

@mIcmpErrMap = external dso_local local_unnamed_addr global [10 x %struct.ICMP_ERROR_INFO], align 16
@mIcmp6ErrMap = external dso_local local_unnamed_addr global [10 x %struct.ICMP_ERROR_INFO], align 16
@.str = external hidden unnamed_addr constant [146 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [18 x i8], align 1
@switch.table.IpIoGetIcmpErrStatus = private unnamed_addr constant [10 x i64] [i64 -9223372036854775708, i64 -9223372036854775707, i64 -9223372036854775706, i64 -9223372036854775705, i64 -9223372036854775786, i64 -9223372036854775786, i64 -9223372036854775707, i64 -9223372036854775707, i64 -9223372036854775786, i64 -9223372036854775786], align 8
@switch.table.IpIoGetIcmpErrStatus.1 = private unnamed_addr constant [10 x i64] [i64 -9223372036854775708, i64 -9223372036854775707, i64 -9223372036854775706, i64 -9223372036854775705, i64 -9223372036854775786, i64 -9223372036854775707, i64 -9223372036854775707, i64 -9223372036854775786, i64 -9223372036854775786, i64 -9223372036854775786], align 8

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 range(i64 -9223372036854775805, -9223372036854775704) i64 @IpIoGetIcmpErrStatus(i8 noundef zeroext %0, i8 noundef zeroext %1, ptr noundef writeonly %2, ptr noundef writeonly %3) local_unnamed_addr #1 {
  %5 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %5, 0
  switch i8 %1, label %42 [
    i8 4, label %6
    i8 6, label %24
  ]

6:                                                ; preds = %4
  %7 = icmp ult i8 %0, 10
  %or.cond = or i1 %7, %.not
  br i1 %or.cond, label %9, label %8

8:                                                ; preds = %6
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 2024, ptr noundef nonnull @.str.11) #2
  br label %9

9:                                                ; preds = %6, %8
  %.not30 = icmp eq ptr %2, null
  br i1 %.not30, label %14, label %10

10:                                               ; preds = %9
  %11 = zext i8 %0 to i64
  %12 = getelementptr inbounds [10 x %struct.ICMP_ERROR_INFO], ptr @mIcmpErrMap, i64 0, i64 %11
  %13 = load i8, ptr %12, align 2, !tbaa !5
  store i8 %13, ptr %2, align 1, !tbaa !9
  br label %14

14:                                               ; preds = %10, %9
  %.not31 = icmp eq ptr %3, null
  br i1 %.not31, label %19, label %15

15:                                               ; preds = %14
  %16 = zext i8 %0 to i64
  %17 = getelementptr inbounds [10 x %struct.ICMP_ERROR_INFO], ptr @mIcmpErrMap, i64 0, i64 %16, i32 1
  %18 = load i8, ptr %17, align 1, !tbaa !10
  store i8 %18, ptr %3, align 1, !tbaa !9
  br label %19

19:                                               ; preds = %15, %14
  %20 = icmp ult i8 %0, 10
  br i1 %20, label %switch.lookup, label %21

21:                                               ; preds = %19
  %22 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not32 = icmp eq i8 %22, 0
  br i1 %.not32, label %46, label %23

23:                                               ; preds = %21
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 2056, ptr noundef nonnull @.str.12) #2
  br label %46

24:                                               ; preds = %4
  %25 = icmp ult i8 %0, 10
  %or.cond5 = or i1 %25, %.not
  br i1 %or.cond5, label %27, label %26

26:                                               ; preds = %24
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 2062, ptr noundef nonnull @.str.11) #2
  br label %27

27:                                               ; preds = %24, %26
  %.not27 = icmp eq ptr %2, null
  br i1 %.not27, label %32, label %28

28:                                               ; preds = %27
  %29 = zext i8 %0 to i64
  %30 = getelementptr inbounds [10 x %struct.ICMP_ERROR_INFO], ptr @mIcmp6ErrMap, i64 0, i64 %29
  %31 = load i8, ptr %30, align 2, !tbaa !5
  store i8 %31, ptr %2, align 1, !tbaa !9
  br label %32

32:                                               ; preds = %28, %27
  %.not28 = icmp eq ptr %3, null
  br i1 %.not28, label %37, label %33

33:                                               ; preds = %32
  %34 = zext i8 %0 to i64
  %35 = getelementptr inbounds [10 x %struct.ICMP_ERROR_INFO], ptr @mIcmp6ErrMap, i64 0, i64 %34, i32 1
  %36 = load i8, ptr %35, align 1, !tbaa !10
  store i8 %36, ptr %3, align 1, !tbaa !9
  br label %37

37:                                               ; preds = %33, %32
  %38 = icmp ult i8 %0, 10
  br i1 %38, label %switch.lookup33, label %39

39:                                               ; preds = %37
  %40 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not29 = icmp eq i8 %40, 0
  br i1 %.not29, label %46, label %41

41:                                               ; preds = %39
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 2094, ptr noundef nonnull @.str.12) #2
  br label %46

42:                                               ; preds = %4
  br i1 %.not, label %46, label %43

43:                                               ; preds = %42
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 2102, ptr noundef nonnull @.str.12) #2
  br label %46

switch.lookup:                                    ; preds = %19
  %44 = zext nneg i8 %0 to i64
  %switch.gep = getelementptr inbounds [10 x i64], ptr @switch.table.IpIoGetIcmpErrStatus, i64 0, i64 %44
  %switch.load = load i64, ptr %switch.gep, align 8
  br label %46

switch.lookup33:                                  ; preds = %37
  %45 = zext nneg i8 %0 to i64
  %switch.gep34 = getelementptr inbounds [10 x i64], ptr @switch.table.IpIoGetIcmpErrStatus.1, i64 0, i64 %45
  %switch.load35 = load i64, ptr %switch.gep34, align 8
  br label %46

46:                                               ; preds = %switch.lookup33, %switch.lookup, %43, %42, %41, %39, %23, %21
  %.0 = phi i64 [ -9223372036854775805, %21 ], [ -9223372036854775805, %23 ], [ -9223372036854775805, %39 ], [ -9223372036854775805, %41 ], [ -9223372036854775805, %42 ], [ -9223372036854775805, %43 ], [ %switch.load, %switch.lookup ], [ %switch.load35, %switch.lookup33 ]
  ret i64 %.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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 1}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!6, !7, i64 1}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass