; LLVM IR from xing1357/SimpleOS :: src (vesa)

; 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.VBE20_INFOBLOCK = type <{ [4 x i8], i16, ptr, i32, ptr, i16, i16, i32, i32, i32, [222 x i8], [256 x i8] }>
%struct.VBE20_MODEINFOBLOCK = type { i16, i8, i8, i16, i16, i16, i16, ptr, i16, i16, i16, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i32, i16, [206 x i8] }

@g_vbe_infoblock = external dso_local global %struct.VBE20_INFOBLOCK, align 1
@.str.3 = external hidden unnamed_addr constant [24 x i8], align 1

declare void @printf(ptr 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 @get_vbe_mode_info(i16 noundef zeroext, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @vbe_print_available_modes() #2 {
  %1 = alloca %struct.VBE20_MODEINFOBLOCK, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i16, align 2
  call void @llvm.lifetime.start.p0(i64 264, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %4 = load ptr, ptr getelementptr inbounds (%struct.VBE20_INFOBLOCK, ptr @g_vbe_infoblock, i32 0, i32 4), align 1, !tbaa !5
  store ptr %4, ptr %2, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !12
  %6 = getelementptr inbounds i16, ptr %5, i32 1
  store ptr %6, ptr %2, align 8, !tbaa !12
  %7 = load i16, ptr %5, align 2, !tbaa !13
  store i16 %7, ptr %3, align 2, !tbaa !13
  br label %8

8:                                                ; preds = %12, %0
  %9 = load i16, ptr %3, align 2, !tbaa !13
  %10 = zext i16 %9 to i32
  %11 = icmp ne i32 %10, 65535
  br i1 %11, label %12, label %25

12:                                               ; preds = %8
  %13 = load i16, ptr %3, align 2, !tbaa !13
  call void @get_vbe_mode_info(i16 noundef zeroext %13, ptr noundef %1)
  %14 = load i16, ptr %3, align 2, !tbaa !13
  %15 = zext i16 %14 to i32
  %16 = getelementptr inbounds %struct.VBE20_MODEINFOBLOCK, ptr %1, i32 0, i32 9
  %17 = load i16, ptr %16, align 2, !tbaa !14
  %18 = zext i16 %17 to i32
  %19 = getelementptr inbounds %struct.VBE20_MODEINFOBLOCK, ptr %1, i32 0, i32 10
  %20 = load i16, ptr %19, align 4, !tbaa !16
  %21 = zext i16 %20 to i32
  call void (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %15, i32 noundef %18, i32 noundef %21)
  %22 = load ptr, ptr %2, align 8, !tbaa !12
  %23 = getelementptr inbounds i16, ptr %22, i32 1
  store ptr %23, ptr %2, align 8, !tbaa !12
  %24 = load i16, ptr %22, align 2, !tbaa !13
  store i16 %24, ptr %3, align 2, !tbaa !13
  br label %8, !llvm.loop !17

25:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 264, ptr %1) #3
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 18}
!6 = !{!"", !7, i64 0, !9, i64 4, !10, i64 6, !11, i64 14, !10, i64 18, !9, i64 26, !9, i64 28, !11, i64 30, !11, i64 34, !11, i64 38, !7, i64 42, !7, i64 264}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!9, !9, i64 0}
!14 = !{!15, !9, i64 26}
!15 = !{!"", !9, i64 0, !7, i64 2, !7, i64 3, !9, i64 4, !9, i64 6, !9, i64 8, !9, i64 10, !10, i64 16, !9, i64 24, !9, i64 26, !9, i64 28, !7, i64 30, !7, i64 31, !7, i64 32, !7, i64 33, !7, i64 34, !7, i64 35, !7, i64 36, !7, i64 37, !7, i64 38, !7, i64 39, !7, i64 40, !7, i64 41, !7, i64 42, !7, i64 43, !7, i64 44, !7, i64 45, !7, i64 46, !7, i64 47, !11, i64 48, !11, i64 52, !9, i64 56, !7, i64 58}
!16 = !{!15, !9, i64 28}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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.VBE20_INFOBLOCK = type <{ [4 x i8], i16, ptr, i32, ptr, i16, i16, i32, i32, i32, [222 x i8], [256 x i8] }>
%struct.VBE20_MODEINFOBLOCK = type { i16, i8, i8, i16, i16, i16, i16, ptr, i16, i16, i16, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i32, i16, [206 x i8] }

@g_vbe_infoblock = external dso_local local_unnamed_addr global %struct.VBE20_INFOBLOCK, align 1
@.str.3 = external hidden unnamed_addr constant [24 x i8], align 1

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

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

; Function Attrs: mustprogress 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 @get_vbe_mode_info(i16 noundef zeroext, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @vbe_print_available_modes() local_unnamed_addr #2 {
  %1 = alloca %struct.VBE20_MODEINFOBLOCK, align 8
  call void @llvm.lifetime.start.p0(i64 264, ptr nonnull %1) #3
  %2 = load ptr, ptr getelementptr inbounds (i8, ptr @g_vbe_infoblock, i64 18), align 1, !tbaa !5
  %.06 = load i16, ptr %2, align 2, !tbaa !12
  %.not7 = icmp eq i16 %.06, -1
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %3 = getelementptr inbounds i8, ptr %1, i64 26
  %4 = getelementptr inbounds i8, ptr %1, i64 28
  br label %5

5:                                                ; preds = %.lr.ph, %5
  %.09 = phi i16 [ %.06, %.lr.ph ], [ %.0, %5 ]
  %.0.in8 = phi ptr [ %2, %.lr.ph ], [ %.04, %5 ]
  %.04 = getelementptr inbounds i8, ptr %.0.in8, i64 2
  %6 = zext i16 %.09 to i32
  call void @get_vbe_mode_info(i16 noundef zeroext %.09, ptr noundef nonnull %1)
  %7 = load i16, ptr %3, align 2, !tbaa !13
  %8 = zext i16 %7 to i32
  %9 = load i16, ptr %4, align 4, !tbaa !15
  %10 = zext i16 %9 to i32
  call void (ptr, ...) @printf(ptr noundef nonnull @.str.3, i32 noundef %6, i32 noundef %8, i32 noundef %10) #3
  %.0 = load i16, ptr %.04, align 2, !tbaa !12
  %.not = icmp eq i16 %.0, -1
  br i1 %.not, label %._crit_edge, label %5, !llvm.loop !16

._crit_edge:                                      ; preds = %5, %0
  call void @llvm.lifetime.end.p0(i64 264, ptr nonnull %1) #3
  ret void
}

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 18}
!6 = !{!"", !7, i64 0, !9, i64 4, !10, i64 6, !11, i64 14, !10, i64 18, !9, i64 26, !9, i64 28, !11, i64 30, !11, i64 34, !11, i64 38, !7, i64 42, !7, i64 264}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!9, !9, i64 0}
!13 = !{!14, !9, i64 26}
!14 = !{!"", !9, i64 0, !7, i64 2, !7, i64 3, !9, i64 4, !9, i64 6, !9, i64 8, !9, i64 10, !10, i64 16, !9, i64 24, !9, i64 26, !9, i64 28, !7, i64 30, !7, i64 31, !7, i64 32, !7, i64 33, !7, i64 34, !7, i64 35, !7, i64 36, !7, i64 37, !7, i64 38, !7, i64 39, !7, i64 40, !7, i64 41, !7, i64 42, !7, i64 43, !7, i64 44, !7, i64 45, !7, i64 46, !7, i64 47, !11, i64 48, !11, i64 52, !9, i64 56, !7, i64 58}
!15 = !{!14, !9, i64 28}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass