; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/OptionRomPkg (SoftwareReset)

; 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.s_data_instance = type { i16, i16, i8, i8, i16, i16, i16, i16, i16, [32 x i8], [32 x i8], [32 x i8], [64 x i32], [128 x i32], i32, i32, i16, i16, i8, i8, i8, i8, i16, i16, i16, i16, i32, i32, i16, i16, [2 x i16], i8, i8, i16, i32, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64, i64, [64 x i64], i16, i16, i16, i16, i8, i8, i8, i8, i8, [3 x i8], %struct.mc, i64, ptr, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.mc = type { [3 x i16], i16, [8 x [32 x i8]] }

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @InByte(ptr noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @OutByte(ptr noundef, i8 noundef zeroext, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @OutLong(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @DelayIt(ptr noundef, i16 noundef zeroext) #0

; Function Attrs: nounwind uwtable
define dso_local signext i8 @SoftwareReset(ptr noundef %0) #0 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  store i8 0, ptr %4, align 1, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.s_data_instance, ptr %9, i32 0, i32 14
  %11 = load i32, ptr %10, align 8, !tbaa !10
  %12 = add i32 %11, 8
  call void @OutLong(ptr noundef %8, i32 noundef 0, i32 noundef %12)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  call void @DelayIt(ptr noundef %13, i16 noundef zeroext 5000)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.s_data_instance, ptr %14, i32 0, i32 4
  %16 = load i16, ptr %15, align 2, !tbaa !16
  %17 = zext i16 %16 to i32
  %18 = icmp eq i32 %17, 9289
  br i1 %18, label %73, label %19

19:                                               ; preds = %1
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.s_data_instance, ptr %20, i32 0, i32 4
  %22 = load i16, ptr %21, align 2, !tbaa !16
  %23 = zext i16 %22 to i32
  %24 = icmp eq i32 %23, 4145
  br i1 %24, label %73, label %25

25:                                               ; preds = %19
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.s_data_instance, ptr %26, i32 0, i32 4
  %28 = load i16, ptr %27, align 2, !tbaa !16
  %29 = zext i16 %28 to i32
  %30 = icmp eq i32 %29, 4146
  br i1 %30, label %73, label %31

31:                                               ; preds = %25
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.s_data_instance, ptr %32, i32 0, i32 4
  %34 = load i16, ptr %33, align 2, !tbaa !16
  %35 = zext i16 %34 to i32
  %36 = icmp eq i32 %35, 4147
  br i1 %36, label %73, label %37

37:                                               ; preds = %31
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.s_data_instance, ptr %38, i32 0, i32 4
  %40 = load i16, ptr %39, align 2, !tbaa !16
  %41 = zext i16 %40 to i32
  %42 = icmp eq i32 %41, 4148
  br i1 %42, label %73, label %43

43:                                               ; preds = %37
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.s_data_instance, ptr %44, i32 0, i32 4
  %46 = load i16, ptr %45, align 2, !tbaa !16
  %47 = zext i16 %46 to i32
  %48 = icmp eq i32 %47, 4149
  br i1 %48, label %73, label %49

49:                                               ; preds = %43
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.s_data_instance, ptr %50, i32 0, i32 4
  %52 = load i16, ptr %51, align 2, !tbaa !16
  %53 = zext i16 %52 to i32
  %54 = icmp eq i32 %53, 4150
  br i1 %54, label %73, label %55

55:                                               ; preds = %49
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.s_data_instance, ptr %56, i32 0, i32 4
  %58 = load i16, ptr %57, align 2, !tbaa !16
  %59 = zext i16 %58 to i32
  %60 = icmp eq i32 %59, 4151
  br i1 %60, label %73, label %61

61:                                               ; preds = %55
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.s_data_instance, ptr %62, i32 0, i32 4
  %64 = load i16, ptr %63, align 2, !tbaa !16
  %65 = zext i16 %64 to i32
  %66 = icmp eq i32 %65, 4152
  br i1 %66, label %73, label %67

67:                                               ; preds = %61
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.s_data_instance, ptr %68, i32 0, i32 6
  %70 = load i16, ptr %69, align 2, !tbaa !17
  %71 = zext i16 %70 to i32
  %72 = icmp sge i32 %71, 8
  br i1 %72, label %73, label %130

73:                                               ; preds = %67, %61, %55, %49, %43, %37, %31, %25, %19, %1
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.s_data_instance, ptr %75, i32 0, i32 14
  %77 = load i32, ptr %76, align 8, !tbaa !10
  %78 = add i32 %77, 2
  call void @OutByte(ptr noundef %74, i8 noundef zeroext 96, i32 noundef %78)
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #2
  store i16 2000, ptr %6, align 2, !tbaa !18
  br label %79

79:                                               ; preds = %95, %73
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.s_data_instance, ptr %81, i32 0, i32 14
  %83 = load i32, ptr %82, align 8, !tbaa !10
  %84 = add i32 %83, 2
  %85 = call zeroext i8 @InByte(ptr noundef %80, i32 noundef %84)
  %86 = zext i8 %85 to i32
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %93

88:                                               ; preds = %79
  %89 = load i16, ptr %6, align 2, !tbaa !18
  %90 = add i16 %89, -1
  store i16 %90, ptr %6, align 2, !tbaa !18
  %91 = sext i16 %90 to i32
  %92 = icmp sge i32 %91, 0
  br label %93

93:                                               ; preds = %88, %79
  %94 = phi i1 [ false, %79 ], [ %92, %88 ]
  br i1 %94, label %95, label %97

95:                                               ; preds = %93
  %96 = load ptr, ptr %3, align 8, !tbaa !5
  call void @DelayIt(ptr noundef %96, i16 noundef zeroext 10)
  br label %79, !llvm.loop !19

97:                                               ; preds = %93
  %98 = load i16, ptr %6, align 2, !tbaa !18
  %99 = sext i16 %98 to i32
  %100 = icmp eq i32 %99, 0
  br i1 %100, label %101, label %103

101:                                              ; preds = %97
  %102 = load ptr, ptr %3, align 8, !tbaa !5
  call void @DelayIt(ptr noundef %102, i16 noundef zeroext 50)
  br label %103

103:                                              ; preds = %101, %97
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #2
  store i16 5000, ptr %5, align 2, !tbaa !18
  br label %104

104:                                              ; preds = %119, %103
  %105 = load i16, ptr %5, align 2, !tbaa !18
  %106 = icmp ne i16 %105, 0
  br i1 %106, label %107, label %123

107:                                              ; preds = %104
  %108 = load ptr, ptr %3, align 8, !tbaa !5
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.s_data_instance, ptr %109, i32 0, i32 14
  %111 = load i32, ptr %110, align 8, !tbaa !10
  %112 = add i32 %111, 27
  %113 = call zeroext i8 @InByte(ptr noundef %108, i32 noundef %112)
  store i8 %113, ptr %4, align 1, !tbaa !9
  %114 = load i8, ptr %4, align 1, !tbaa !9
  %115 = zext i8 %114 to i32
  %116 = and i32 %115, 2
  %117 = icmp eq i32 %116, 0
  br i1 %117, label %118, label %119

118:                                              ; preds = %107
  br label %123

119:                                              ; preds = %107
  %120 = load i16, ptr %5, align 2, !tbaa !18
  %121 = add i16 %120, -1
  store i16 %121, ptr %5, align 2, !tbaa !18
  %122 = load ptr, ptr %3, align 8, !tbaa !5
  call void @DelayIt(ptr noundef %122, i16 noundef zeroext 1)
  br label %104, !llvm.loop !21

123:                                              ; preds = %118, %104
  %124 = load i8, ptr %4, align 1, !tbaa !9
  %125 = zext i8 %124 to i32
  %126 = and i32 %125, 2
  %127 = icmp ne i32 %126, 0
  br i1 %127, label %128, label %129

128:                                              ; preds = %123
  store i8 -1, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %131

129:                                              ; preds = %123
  br label %130

130:                                              ; preds = %129, %67
  store i8 0, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %131

131:                                              ; preds = %130, %128
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  %132 = load i8, ptr %2, align 1
  ret i8 %132
}

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 = { 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, !13, i64 880}
!11 = !{!"s_data_instance", !12, i64 0, !12, i64 2, !7, i64 4, !7, i64 5, !12, i64 6, !12, i64 8, !12, i64 10, !12, i64 12, !12, i64 14, !7, i64 16, !7, i64 48, !7, i64 80, !7, i64 112, !7, i64 368, !13, i64 880, !13, i64 884, !12, i64 888, !12, i64 890, !7, i64 892, !7, i64 893, !7, i64 894, !7, i64 895, !12, i64 896, !12, i64 898, !12, i64 900, !12, i64 902, !13, i64 904, !13, i64 908, !12, i64 912, !12, i64 914, !7, i64 916, !7, i64 920, !7, i64 921, !12, i64 922, !13, i64 924, !6, i64 928, !6, i64 936, !6, i64 944, !6, i64 952, !6, i64 960, !6, i64 968, !14, i64 976, !14, i64 984, !14, i64 992, !14, i64 1000, !14, i64 1008, !7, i64 1016, !12, i64 1528, !12, i64 1530, !12, i64 1532, !12, i64 1534, !7, i64 1536, !7, i64 1537, !7, i64 1538, !7, i64 1539, !7, i64 1540, !7, i64 1541, !15, i64 1544, !14, i64 1808, !6, i64 1816, !14, i64 1824, !6, i64 1832, !6, i64 1840, !6, i64 1848, !6, i64 1856, !6, i64 1864, !6, i64 1872, !6, i64 1880, !6, i64 1888, !6, i64 1896, !6, i64 1904, !6, i64 1912}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"mc", !7, i64 0, !12, i64 6, !7, i64 8}
!16 = !{!11, !12, i64 6}
!17 = !{!11, !12, i64 10}
!18 = !{!12, !12, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @InByte(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @OutByte(ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @OutLong(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @DelayIt(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local signext range(i8 -1, 1) i8 @SoftwareReset(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 880
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = add i32 %3, 8
  tail call void @OutLong(ptr noundef %0, i32 noundef 0, i32 noundef %4)
  tail call void @DelayIt(ptr noundef %0, i16 noundef zeroext 5000)
  %5 = getelementptr inbounds i8, ptr %0, i64 6
  %6 = load i16, ptr %5, align 2, !tbaa !14
  switch i16 %6, label %7 [
    i16 9289, label %11
    i16 4145, label %11
    i16 4146, label %11
    i16 4147, label %11
    i16 4148, label %11
    i16 4149, label %11
    i16 4150, label %11
    i16 4151, label %11
    i16 4152, label %11
  ]

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 10
  %9 = load i16, ptr %8, align 2, !tbaa !15
  %10 = icmp ugt i16 %9, 7
  br i1 %10, label %11, label %.thread

11:                                               ; preds = %1, %1, %1, %1, %1, %1, %1, %1, %1, %7
  %12 = load i32, ptr %2, align 8, !tbaa !5
  %13 = add i32 %12, 2
  tail call void @OutByte(ptr noundef nonnull %0, i8 noundef zeroext 96, i32 noundef %13)
  %14 = load i32, ptr %2, align 8, !tbaa !5
  %15 = add i32 %14, 2
  %16 = tail call zeroext i8 @InByte(ptr noundef nonnull %0, i32 noundef %15)
  %.not37 = icmp eq i8 %16, 0
  br i1 %.not37, label %.critedge.thread.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %11, %18
  %.038 = phi i16 [ %19, %18 ], [ 2000, %11 ]
  %17 = icmp sgt i16 %.038, 0
  br i1 %17, label %18, label %.critedge.thread.preheader

18:                                               ; preds = %.lr.ph
  %19 = add nsw i16 %.038, -1
  tail call void @DelayIt(ptr noundef nonnull %0, i16 noundef zeroext 10)
  %20 = load i32, ptr %2, align 8, !tbaa !5
  %21 = add i32 %20, 2
  %22 = tail call zeroext i8 @InByte(ptr noundef nonnull %0, i32 noundef %21)
  %.not = icmp eq i8 %22, 0
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !16

.critedge:                                        ; preds = %18
  %23 = icmp eq i16 %19, 0
  br i1 %23, label %24, label %.critedge.thread.preheader

24:                                               ; preds = %.critedge
  tail call void @DelayIt(ptr noundef nonnull %0, i16 noundef zeroext 50)
  br label %.critedge.thread.preheader

.critedge.thread.preheader:                       ; preds = %.lr.ph, %11, %24, %.critedge
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %.critedge.thread.preheader, %30
  %.02839 = phi i16 [ %31, %30 ], [ 5000, %.critedge.thread.preheader ]
  %25 = load i32, ptr %2, align 8, !tbaa !5
  %26 = add i32 %25, 27
  %27 = tail call zeroext i8 @InByte(ptr noundef nonnull %0, i32 noundef %26)
  %28 = and i8 %27, 2
  %29 = icmp eq i8 %28, 0
  br i1 %29, label %.thread, label %30

30:                                               ; preds = %.critedge.thread
  %31 = add nsw i16 %.02839, -1
  tail call void @DelayIt(ptr noundef nonnull %0, i16 noundef zeroext 1)
  %.not33 = icmp eq i16 %31, 0
  br i1 %.not33, label %.thread, label %.critedge.thread, !llvm.loop !18

.thread:                                          ; preds = %.critedge.thread, %30, %7
  %.031 = phi i8 [ 0, %7 ], [ 0, %.critedge.thread ], [ -1, %30 ]
  ret i8 %.031
}

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

!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, !10, i64 880}
!6 = !{!"s_data_instance", !7, i64 0, !7, i64 2, !8, i64 4, !8, i64 5, !7, i64 6, !7, i64 8, !7, i64 10, !7, i64 12, !7, i64 14, !8, i64 16, !8, i64 48, !8, i64 80, !8, i64 112, !8, i64 368, !10, i64 880, !10, i64 884, !7, i64 888, !7, i64 890, !8, i64 892, !8, i64 893, !8, i64 894, !8, i64 895, !7, i64 896, !7, i64 898, !7, i64 900, !7, i64 902, !10, i64 904, !10, i64 908, !7, i64 912, !7, i64 914, !8, i64 916, !8, i64 920, !8, i64 921, !7, i64 922, !10, i64 924, !11, i64 928, !11, i64 936, !11, i64 944, !11, i64 952, !11, i64 960, !11, i64 968, !12, i64 976, !12, i64 984, !12, i64 992, !12, i64 1000, !12, i64 1008, !8, i64 1016, !7, i64 1528, !7, i64 1530, !7, i64 1532, !7, i64 1534, !8, i64 1536, !8, i64 1537, !8, i64 1538, !8, i64 1539, !8, i64 1540, !8, i64 1541, !13, i64 1544, !12, i64 1808, !11, i64 1816, !12, i64 1824, !11, i64 1832, !11, i64 1840, !11, i64 1848, !11, i64 1856, !11, i64 1864, !11, i64 1872, !11, i64 1880, !11, i64 1888, !11, i64 1896, !11, i64 1904, !11, i64 1912}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"mc", !8, i64 0, !7, i64 6, !8, i64 8}
!14 = !{!6, !7, i64 6}
!15 = !{!6, !7, i64 10}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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