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

; 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_pxe_cdb = type { i16, i16, i16, i16, i64, i64, i16, i16, i16, i16 }

; Function Attrs: nounwind uwtable
define dso_local void @UNDI_Reset(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.s_pxe_cdb, ptr %5, i32 0, i32 1
  %7 = load i16, ptr %6, align 1, !tbaa !9
  %8 = zext i16 %7 to i32
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %27

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.s_pxe_cdb, ptr %11, i32 0, i32 1
  %13 = load i16, ptr %12, align 1, !tbaa !9
  %14 = zext i16 %13 to i32
  %15 = icmp ne i32 %14, 1
  br i1 %15, label %16, label %27

16:                                               ; preds = %10
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.s_pxe_cdb, ptr %17, i32 0, i32 1
  %19 = load i16, ptr %18, align 1, !tbaa !9
  %20 = zext i16 %19 to i32
  %21 = icmp ne i32 %20, 2
  br i1 %21, label %22, label %27

22:                                               ; preds = %16
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.s_pxe_cdb, ptr %23, i32 0, i32 7
  store i16 -32768, ptr %24, align 1, !tbaa !13
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.s_pxe_cdb, ptr %25, i32 0, i32 6
  store i16 1, ptr %26, align 1, !tbaa !14
  br label %45

27:                                               ; preds = %16, %10, %2
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.s_pxe_cdb, ptr %29, i32 0, i32 1
  %31 = load i16, ptr %30, align 1, !tbaa !9
  %32 = zext i16 %31 to i32
  %33 = call i64 @E100bReset(ptr noundef %28, i32 noundef %32)
  %34 = trunc i64 %33 to i16
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.s_pxe_cdb, ptr %35, i32 0, i32 6
  store i16 %34, ptr %36, align 1, !tbaa !14
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.s_pxe_cdb, ptr %37, i32 0, i32 6
  %39 = load i16, ptr %38, align 1, !tbaa !14
  %40 = zext i16 %39 to i32
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %45

42:                                               ; preds = %27
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.s_pxe_cdb, ptr %43, i32 0, i32 7
  store i16 -32768, ptr %44, align 1, !tbaa !13
  br label %45

45:                                               ; preds = %42, %27, %22
  ret void
}

declare i64 @E100bReset(ptr noundef, i32 noundef) #1

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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 2}
!10 = !{!"s_pxe_cdb", !11, i64 0, !11, i64 2, !11, i64 4, !11, i64 6, !12, i64 8, !12, i64 16, !11, i64 24, !11, i64 26, !11, i64 28, !11, i64 30}
!11 = !{!"short", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!10, !11, i64 26}
!14 = !{!10, !11, i64 24}


; 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
define dso_local void @UNDI_Reset(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 2
  %4 = load i16, ptr %3, align 1, !tbaa !5
  %switch = icmp ult i16 %4, 3
  br i1 %switch, label %7, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 26
  store i16 -32768, ptr %6, align 1, !tbaa !11
  br label %.sink.split

7:                                                ; preds = %2
  %8 = zext nneg i16 %4 to i32
  %9 = tail call i64 @E100bReset(ptr noundef %1, i32 noundef %8) #2
  %10 = trunc i64 %9 to i16
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  store i16 %10, ptr %11, align 1, !tbaa !12
  %12 = and i64 %9, 65535
  %.not12 = icmp eq i64 %12, 0
  br i1 %.not12, label %14, label %.sink.split

.sink.split:                                      ; preds = %7, %5
  %.sink14 = phi i64 [ 24, %5 ], [ 26, %7 ]
  %.sink = phi i16 [ 1, %5 ], [ -32768, %7 ]
  %13 = getelementptr inbounds i8, ptr %0, i64 %.sink14
  store i16 %.sink, ptr %13, align 1, !tbaa !13
  br label %14

14:                                               ; preds = %.sink.split, %7
  ret void
}

declare i64 @E100bReset(ptr noundef, i32 noundef) local_unnamed_addr #1

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 = { "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 2}
!6 = !{!"s_pxe_cdb", !7, i64 0, !7, i64 2, !7, i64 4, !7, i64 6, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 26, !7, i64 28, !7, i64 30}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!6, !7, i64 26}
!12 = !{!6, !7, i64 24}
!13 = !{!7, !7, i64 0}


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