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

@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_position = external hidden global i32, align 4

; 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

; Function Attrs: nounwind uwtable
declare dso_local void @deleteLine(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @move_screen() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %4 = load i32, ptr @pitch, align 4, !tbaa !5
  %5 = mul nsw i32 15, %4
  store i32 %5, ptr %3, align 4, !tbaa !5
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %52, %0
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = load i32, ptr @xres, align 4, !tbaa !5
  %9 = load i32, ptr @yres, align 4, !tbaa !5
  %10 = mul nsw i32 %8, %9
  %11 = load i32, ptr @buffer_max_per_line, align 4, !tbaa !5
  %12 = sub nsw i32 %10, %11
  %13 = icmp slt i32 %7, %12
  br i1 %13, label %14, label %55

14:                                               ; preds = %6
  %15 = load ptr, ptr @screen, align 8, !tbaa !9
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %15, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !11
  %20 = load ptr, ptr @screen, align 8, !tbaa !9
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  store i8 %19, ptr %23, align 1, !tbaa !11
  %24 = load ptr, ptr @screen, align 8, !tbaa !9
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %24, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = load ptr, ptr @screen, align 8, !tbaa !9
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %30, i64 %33
  store i8 %29, ptr %34, align 1, !tbaa !11
  %35 = load ptr, ptr @screen, align 8, !tbaa !9
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = add nsw i32 %36, 2
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %35, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = load ptr, ptr @screen, align 8, !tbaa !9
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = add nsw i32 %42, 2
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %41, i64 %44
  store i8 %40, ptr %45, align 1, !tbaa !11
  %46 = load i32, ptr @pixel_width, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = add nsw i32 %47, %46
  store i32 %48, ptr %2, align 4, !tbaa !5
  %49 = load i32, ptr @pixel_width, align 4, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, %49
  store i32 %51, ptr %3, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %14
  %53 = load i32, ptr %1, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !12

55:                                               ; preds = %6
  %56 = load i32, ptr @buffer_position, align 4, !tbaa !5
  %57 = load i32, ptr @buffer_max_per_line, align 4, !tbaa !5
  %58 = sdiv i32 %56, %57
  call void @deleteLine(i32 noundef %58)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@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_position = external hidden local_unnamed_addr global i32, align 4

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

; Function Attrs: nounwind uwtable
define dso_local void @move_screen() local_unnamed_addr #0 {
  %1 = load i32, ptr @xres, align 4, !tbaa !5
  %2 = load i32, ptr @yres, align 4, !tbaa !5
  %3 = mul nsw i32 %2, %1
  %4 = load i32, ptr @buffer_max_per_line, align 4, !tbaa !5
  %5 = icmp sgt i32 %3, %4
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %6 = load i32, ptr @pitch, align 4, !tbaa !5
  %7 = mul nsw i32 %6, 15
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.014 = phi i32 [ %28, %.lr.ph ], [ %7, %.lr.ph.preheader ]
  %.01013 = phi i32 [ %27, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.01112 = phi i32 [ %29, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %8 = load ptr, ptr @screen, align 8, !tbaa !9
  %9 = sext i32 %.014 to i64
  %10 = getelementptr inbounds i8, ptr %8, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !11
  %12 = sext i32 %.01013 to i64
  %13 = getelementptr inbounds i8, ptr %8, i64 %12
  store i8 %11, ptr %13, align 1, !tbaa !11
  %14 = load ptr, ptr @screen, align 8, !tbaa !9
  %15 = getelementptr i8, ptr %14, i64 %9
  %16 = getelementptr i8, ptr %15, i64 1
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = getelementptr i8, ptr %14, i64 %12
  %19 = getelementptr i8, ptr %18, i64 1
  store i8 %17, ptr %19, align 1, !tbaa !11
  %20 = load ptr, ptr @screen, align 8, !tbaa !9
  %21 = getelementptr i8, ptr %20, i64 %9
  %22 = getelementptr i8, ptr %21, i64 2
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = getelementptr i8, ptr %20, i64 %12
  %25 = getelementptr i8, ptr %24, i64 2
  store i8 %23, ptr %25, align 1, !tbaa !11
  %26 = load i32, ptr @pixel_width, align 4, !tbaa !5
  %27 = add nsw i32 %26, %.01013
  %28 = add nsw i32 %26, %.014
  %29 = add nuw nsw i32 %.01112, 1
  %30 = load i32, ptr @xres, align 4, !tbaa !5
  %31 = load i32, ptr @yres, align 4, !tbaa !5
  %32 = mul nsw i32 %31, %30
  %33 = load i32, ptr @buffer_max_per_line, align 4, !tbaa !5
  %34 = sub nsw i32 %32, %33
  %35 = icmp slt i32 %29, %34
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i32 [ %4, %0 ], [ %33, %.lr.ph ]
  %36 = load i32, ptr @buffer_position, align 4, !tbaa !5
  %37 = sdiv i32 %36, %.lcssa
  tail call void @deleteLine(i32 noundef %37)
  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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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