; LLVM IR from rociodellasala/TP3_SO :: Kernel (video_driver)

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

@screen_info = external hidden global ptr, align 8
@screen = external hidden global ptr, align 8
@pitch = external hidden global i32, align 4
@pixel_width = external hidden global i32, align 4
@xres = external hidden global i32, align 4
@yres = external hidden global i32, align 4
@buffer_max_per_line = external hidden global i32, align 4
@buffer_max_per_column = external hidden global i32, align 4
@currColor = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @start_video_mode() #0 {
  %1 = load ptr, ptr @screen_info, align 8, !tbaa !5
  %2 = getelementptr inbounds %struct.ModeInfoBlock, ptr %1, i32 0, i32 29
  %3 = load i32, ptr %2, align 1, !tbaa !9
  %4 = zext i32 %3 to i64
  %5 = inttoptr i64 %4 to ptr
  store ptr %5, ptr @screen, align 8, !tbaa !5
  %6 = load ptr, ptr @screen_info, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ModeInfoBlock, ptr %6, i32 0, i32 8
  %8 = load i16, ptr %7, align 1, !tbaa !13
  %9 = zext i16 %8 to i32
  store i32 %9, ptr @pitch, align 4, !tbaa !14
  %10 = load ptr, ptr @screen_info, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ModeInfoBlock, ptr %10, i32 0, i32 14
  %12 = load i8, ptr %11, align 1, !tbaa !15
  %13 = zext i8 %12 to i32
  %14 = sdiv i32 %13, 8
  store i32 %14, ptr @pixel_width, align 4, !tbaa !14
  %15 = load ptr, ptr @screen_info, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ModeInfoBlock, ptr %15, i32 0, i32 9
  %17 = load i16, ptr %16, align 1, !tbaa !16
  %18 = zext i16 %17 to i32
  store i32 %18, ptr @xres, align 4, !tbaa !14
  %19 = load ptr, ptr @screen_info, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ModeInfoBlock, ptr %19, i32 0, i32 10
  %21 = load i16, ptr %20, align 1, !tbaa !17
  %22 = zext i16 %21 to i32
  store i32 %22, ptr @yres, align 4, !tbaa !14
  %23 = load i32, ptr @xres, align 4, !tbaa !14
  %24 = sdiv i32 %23, 10
  store i32 %24, ptr @buffer_max_per_line, align 4, !tbaa !14
  %25 = load i32, ptr @yres, align 4, !tbaa !14
  %26 = sdiv i32 %25, 15
  store i32 %26, ptr @buffer_max_per_column, align 4, !tbaa !14
  store i32 16777215, ptr @currColor, align 4, !tbaa !14
  ret void
}

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 40}
!10 = !{!"", !11, i64 0, !7, i64 2, !7, i64 3, !11, i64 4, !11, i64 6, !11, i64 8, !11, i64 10, !12, i64 12, !11, i64 16, !11, i64 18, !11, i64 20, !7, i64 22, !7, i64 23, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !7, i64 28, !7, i64 29, !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, !12, i64 40, !12, i64 44, !11, i64 48}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 16}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !7, i64 25}
!16 = !{!10, !11, i64 18}
!17 = !{!10, !11, i64 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"

@screen_info = external hidden local_unnamed_addr global ptr, align 8
@screen = external hidden local_unnamed_addr global ptr, align 8
@pitch = external hidden local_unnamed_addr global i32, align 4
@pixel_width = external hidden local_unnamed_addr global i32, align 4
@xres = external hidden local_unnamed_addr global i32, align 4
@yres = external hidden local_unnamed_addr global i32, align 4
@buffer_max_per_line = external hidden local_unnamed_addr global i32, align 4
@buffer_max_per_column = external hidden local_unnamed_addr global i32, align 4
@currColor = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local void @start_video_mode() local_unnamed_addr #0 {
  %1 = load ptr, ptr @screen_info, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %1, i64 40
  %3 = load i32, ptr %2, align 1, !tbaa !9
  %4 = zext i32 %3 to i64
  %5 = inttoptr i64 %4 to ptr
  store ptr %5, ptr @screen, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = load i16, ptr %6, align 1, !tbaa !13
  %8 = zext i16 %7 to i32
  store i32 %8, ptr @pitch, align 4, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %1, i64 25
  %10 = load i8, ptr %9, align 1, !tbaa !15
  %11 = lshr i8 %10, 3
  %12 = zext nneg i8 %11 to i32
  store i32 %12, ptr @pixel_width, align 4, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %1, i64 18
  %14 = load i16, ptr %13, align 1, !tbaa !16
  %15 = zext i16 %14 to i32
  store i32 %15, ptr @xres, align 4, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %1, i64 20
  %17 = load i16, ptr %16, align 1, !tbaa !17
  %18 = zext i16 %17 to i32
  store i32 %18, ptr @yres, align 4, !tbaa !14
  %19 = udiv i16 %14, 10
  %.zext = zext nneg i16 %19 to i32
  store i32 %.zext, ptr @buffer_max_per_line, align 4, !tbaa !14
  %20 = udiv i16 %17, 15
  %.zext2 = zext nneg i16 %20 to i32
  store i32 %.zext2, ptr @buffer_max_per_column, align 4, !tbaa !14
  store i32 16777215, ptr @currColor, align 4, !tbaa !14
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none) 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 40}
!10 = !{!"", !11, i64 0, !7, i64 2, !7, i64 3, !11, i64 4, !11, i64 6, !11, i64 8, !11, i64 10, !12, i64 12, !11, i64 16, !11, i64 18, !11, i64 20, !7, i64 22, !7, i64 23, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !7, i64 28, !7, i64 29, !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, !12, i64 40, !12, i64 44, !11, i64 48}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 16}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !7, i64 25}
!16 = !{!10, !11, i64 18}
!17 = !{!10, !11, i64 20}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass