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

; 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.SNP_DRIVER = type <{ i32, [4 x i8], %struct.EFI_LOCK, %struct._EFI_SIMPLE_NETWORK_PROTOCOL, %struct.EFI_SIMPLE_NETWORK_MODE, ptr, ptr, ptr, i8, i8, i16, i32, ptr, ptr, ptr, ptr, ptr, ptr, i8, i8, %struct.s_pxe_cdb, [6 x i8], ptr, ptr, ptr, %struct.s_pxe_db_get_init_info, i8, ptr, [100 x %struct.MAP_LIST], ptr, i8, [7 x i8] }>
%struct.EFI_LOCK = type { i64, i64, i32 }
%struct._EFI_SIMPLE_NETWORK_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_SIMPLE_NETWORK_MODE = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x %struct.EFI_MAC_ADDRESS], %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, i8, i8, i8, i8, i8 }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct.s_pxe_cdb = type { i16, i16, i16, i16, i64, i64, i16, i16, i16, i16 }
%struct.s_pxe_db_get_init_info = type <{ i32, i32, [4 x i32], i32, i16, i16, i16, i16, i16, i16, i16, i16, i8, i8, i8 }>
%struct.MAP_LIST = type { i64, ptr }
%struct._EFI_PCI_IO_PROTOCOL = type { ptr, ptr, %struct.EFI_PCI_IO_PROTOCOL_ACCESS, %struct.EFI_PCI_IO_PROTOCOL_ACCESS, %struct.EFI_PCI_IO_PROTOCOL_CONFIG_ACCESS, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr }
%struct.EFI_PCI_IO_PROTOCOL_ACCESS = type { ptr, ptr }
%struct.EFI_PCI_IO_PROTOCOL_CONFIG_ACCESS = type { ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [48 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

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

declare zeroext i8 @DebugPrintEnabled() #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #1

declare void @DebugPrint(i64 noundef, ptr noundef, ...) #1

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

16:                                               ; preds = %32, %5
  %17 = load i16, ptr %12, align 2, !tbaa !13
  %18 = zext i16 %17 to i32
  %19 = icmp slt i32 %18, 100
  br i1 %19, label %20, label %35

20:                                               ; preds = %16
  %21 = load ptr, ptr %11, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.SNP_DRIVER, ptr %21, i32 0, i32 28
  %23 = load i16, ptr %12, align 2, !tbaa !13
  %24 = zext i16 %23 to i64
  %25 = getelementptr inbounds [100 x %struct.MAP_LIST], ptr %22, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.MAP_LIST, ptr %25, i32 0, i32 0
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = load i64, ptr %7, align 8, !tbaa !5
  %29 = icmp eq i64 %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %20
  br label %35

31:                                               ; preds = %20
  br label %32

32:                                               ; preds = %31
  %33 = load i16, ptr %12, align 2, !tbaa !13
  %34 = add i16 %33, 1
  store i16 %34, ptr %12, align 2, !tbaa !13
  br label %16, !llvm.loop !17

35:                                               ; preds = %30, %16
  %36 = load i16, ptr %12, align 2, !tbaa !13
  %37 = zext i16 %36 to i32
  %38 = icmp sge i32 %37, 100
  br i1 %38, label %39, label %54

39:                                               ; preds = %35
  br label %40

40:                                               ; preds = %39
  %41 = call zeroext i8 @DebugPrintEnabled()
  %42 = icmp ne i8 %41, 0
  br i1 %42, label %43, label %51

43:                                               ; preds = %40
  br label %44

44:                                               ; preds = %43
  %45 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %46 = icmp ne i8 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.1)
  br label %48

48:                                               ; preds = %47, %44
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50, %40
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  store i32 1, ptr %13, align 4
  br label %83

54:                                               ; preds = %35
  %55 = load ptr, ptr %11, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.SNP_DRIVER, ptr %55, i32 0, i32 17
  %57 = load ptr, ptr %56, align 8, !tbaa !19
  %58 = getelementptr inbounds %struct._EFI_PCI_IO_PROTOCOL, ptr %57, i32 0, i32 7
  %59 = load ptr, ptr %58, align 8, !tbaa !27
  %60 = load ptr, ptr %11, align 8, !tbaa !11
  %61 = getelementptr inbounds %struct.SNP_DRIVER, ptr %60, i32 0, i32 17
  %62 = load ptr, ptr %61, align 8, !tbaa !19
  %63 = load ptr, ptr %11, align 8, !tbaa !11
  %64 = getelementptr inbounds %struct.SNP_DRIVER, ptr %63, i32 0, i32 28
  %65 = load i16, ptr %12, align 2, !tbaa !13
  %66 = zext i16 %65 to i64
  %67 = getelementptr inbounds [100 x %struct.MAP_LIST], ptr %64, i64 0, i64 %66
  %68 = getelementptr inbounds %struct.MAP_LIST, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !30
  %70 = call i64 %59(ptr noundef %62, ptr noundef %69)
  %71 = load ptr, ptr %11, align 8, !tbaa !11
  %72 = getelementptr inbounds %struct.SNP_DRIVER, ptr %71, i32 0, i32 28
  %73 = load i16, ptr %12, align 2, !tbaa !13
  %74 = zext i16 %73 to i64
  %75 = getelementptr inbounds [100 x %struct.MAP_LIST], ptr %72, i64 0, i64 %74
  %76 = getelementptr inbounds %struct.MAP_LIST, ptr %75, i32 0, i32 0
  store i64 0, ptr %76, align 8, !tbaa !15
  %77 = load ptr, ptr %11, align 8, !tbaa !11
  %78 = getelementptr inbounds %struct.SNP_DRIVER, ptr %77, i32 0, i32 28
  %79 = load i16, ptr %12, align 2, !tbaa !13
  %80 = zext i16 %79 to i64
  %81 = getelementptr inbounds [100 x %struct.MAP_LIST], ptr %78, i64 0, i64 %80
  %82 = getelementptr inbounds %struct.MAP_LIST, ptr %81, i32 0, i32 1
  store ptr null, ptr %82, align 8, !tbaa !30
  store i32 1, ptr %13, align 4
  br label %83

83:                                               ; preds = %54, %53
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"MAP_LIST", !6, i64 0, !12, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !12, i64 888}
!20 = !{!"", !10, i64 0, !21, i64 8, !22, i64 32, !23, i64 160, !12, i64 816, !12, i64 824, !12, i64 832, !7, i64 840, !14, i64 842, !10, i64 844, !12, i64 848, !12, i64 856, !12, i64 864, !12, i64 872, !12, i64 880, !12, i64 888, !7, i64 896, !7, i64 897, !25, i64 898, !12, i64 936, !12, i64 944, !12, i64 952, !26, i64 960, !12, i64 1008, !7, i64 1016, !12, i64 2616, !7, i64 2624}
!21 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16}
!22 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !6, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120}
!23 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40, !24, i64 552, !24, i64 584, !24, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!24 = !{!"", !7, i64 0}
!25 = !{!"s_pxe_cdb", !14, i64 0, !14, i64 2, !14, i64 4, !14, i64 6, !6, i64 8, !6, i64 16, !14, i64 24, !14, i64 26, !14, i64 28, !14, i64 30}
!26 = !{!"s_pxe_db_get_init_info", !10, i64 0, !10, i64 4, !7, i64 8, !10, i64 24, !14, i64 28, !14, i64 30, !14, i64 32, !14, i64 34, !14, i64 36, !14, i64 38, !14, i64 40, !14, i64 42, !7, i64 44, !7, i64 45, !7, i64 46}
!27 = !{!28, !12, i64 80}
!28 = !{!"_EFI_PCI_IO_PROTOCOL", !12, i64 0, !12, i64 8, !29, i64 16, !29, i64 32, !29, i64 48, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !6, i64 144, !12, i64 152}
!29 = !{!"", !12, i64 0, !12, i64 8}
!30 = !{!16, !12, i64 8}


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

@.str.1 = external hidden unnamed_addr constant [48 x i8], align 1

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #0

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @SnpUndi32CallbackUnmap(i64 noundef %0, i64 noundef %1, i32 noundef %2, i32 noundef %3, i64 noundef %4) local_unnamed_addr #1 {
  %6 = inttoptr i64 %0 to ptr
  %7 = getelementptr inbounds i8, ptr %6, i64 1016
  br label %8

8:                                                ; preds = %28, %5
  %indvars.iv = phi i64 [ 0, %5 ], [ %indvars.iv.next.4, %28 ]
  %9 = getelementptr inbounds [100 x %struct.MAP_LIST], ptr %7, i64 0, i64 %indvars.iv
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = icmp eq i64 %10, %1
  br i1 %11, label %34, label %12

12:                                               ; preds = %8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = getelementptr inbounds [100 x %struct.MAP_LIST], ptr %7, i64 0, i64 %indvars.iv.next
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = icmp eq i64 %14, %1
  br i1 %15, label %34, label %16

16:                                               ; preds = %12
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %17 = getelementptr inbounds [100 x %struct.MAP_LIST], ptr %7, i64 0, i64 %indvars.iv.next.1
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = icmp eq i64 %18, %1
  br i1 %19, label %34, label %20

20:                                               ; preds = %16
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %21 = getelementptr inbounds [100 x %struct.MAP_LIST], ptr %7, i64 0, i64 %indvars.iv.next.2
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = icmp eq i64 %22, %1
  br i1 %23, label %34, label %24

24:                                               ; preds = %20
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %25 = getelementptr inbounds [100 x %struct.MAP_LIST], ptr %7, i64 0, i64 %indvars.iv.next.3
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = icmp eq i64 %26, %1
  br i1 %27, label %34, label %28

28:                                               ; preds = %24
  %indvars.iv.next.4 = add nuw nsw i64 %indvars.iv, 5
  %exitcond.not.4 = icmp eq i64 %indvars.iv.next.4, 100
  br i1 %exitcond.not.4, label %29, label %8, !llvm.loop !11

29:                                               ; preds = %28
  %30 = tail call zeroext i8 @DebugPrintEnabled() #3
  %.not = icmp eq i8 %30, 0
  br i1 %.not, label %44, label %31

31:                                               ; preds = %29
  %32 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #3
  %.not14 = icmp eq i8 %32, 0
  br i1 %.not14, label %44, label %33

33:                                               ; preds = %31
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.1) #3
  br label %44

34:                                               ; preds = %24, %20, %16, %12, %8
  %indvars.iv.lcssa = phi i64 [ %indvars.iv, %8 ], [ %indvars.iv.next, %12 ], [ %indvars.iv.next.1, %16 ], [ %indvars.iv.next.2, %20 ], [ %indvars.iv.next.3, %24 ]
  %35 = getelementptr inbounds i8, ptr %6, i64 888
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = getelementptr inbounds i8, ptr %36, i64 80
  %38 = load ptr, ptr %37, align 8, !tbaa !23
  %39 = and i64 %indvars.iv.lcssa, 65535
  %40 = getelementptr inbounds [100 x %struct.MAP_LIST], ptr %7, i64 0, i64 %39
  %41 = getelementptr inbounds i8, ptr %40, i64 8
  %42 = load ptr, ptr %41, align 8, !tbaa !26
  %43 = tail call i64 %38(ptr noundef %36, ptr noundef %42) #3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %40, i8 0, i64 16, i1 false)
  br label %44

44:                                               ; preds = %29, %33, %31, %34
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"MAP_LIST", !7, i64 0, !10, i64 8}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 888}
!14 = !{!"", !15, i64 0, !16, i64 8, !17, i64 32, !18, i64 160, !10, i64 816, !10, i64 824, !10, i64 832, !8, i64 840, !20, i64 842, !15, i64 844, !10, i64 848, !10, i64 856, !10, i64 864, !10, i64 872, !10, i64 880, !10, i64 888, !8, i64 896, !8, i64 897, !21, i64 898, !10, i64 936, !10, i64 944, !10, i64 952, !22, i64 960, !10, i64 1008, !8, i64 1016, !10, i64 2616, !8, i64 2624}
!15 = !{!"int", !8, i64 0}
!16 = !{!"", !7, i64 0, !7, i64 8, !15, i64 16}
!17 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120}
!18 = !{!"", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20, !15, i64 24, !15, i64 28, !15, i64 32, !15, i64 36, !8, i64 40, !19, i64 552, !19, i64 584, !19, i64 616, !8, i64 648, !8, i64 649, !8, i64 650, !8, i64 651, !8, i64 652}
!19 = !{!"", !8, i64 0}
!20 = !{!"short", !8, i64 0}
!21 = !{!"s_pxe_cdb", !20, i64 0, !20, i64 2, !20, i64 4, !20, i64 6, !7, i64 8, !7, i64 16, !20, i64 24, !20, i64 26, !20, i64 28, !20, i64 30}
!22 = !{!"s_pxe_db_get_init_info", !15, i64 0, !15, i64 4, !8, i64 8, !15, i64 24, !20, i64 28, !20, i64 30, !20, i64 32, !20, i64 34, !20, i64 36, !20, i64 38, !20, i64 40, !20, i64 42, !8, i64 44, !8, i64 45, !8, i64 46}
!23 = !{!24, !10, i64 80}
!24 = !{!"_EFI_PCI_IO_PROTOCOL", !10, i64 0, !10, i64 8, !25, i64 16, !25, i64 32, !25, i64 48, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !7, i64 144, !10, i64 152}
!25 = !{!"", !10, i64 0, !10, i64 8}
!26 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass