; 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.ProcessSlot = type { ptr, %struct.Process }
%struct.Process = type { i32, i32, [30 x i32], i32, i32, [50 x i8], [20 x ptr], i32, ptr, ptr, ptr, [10 x ptr], i32, ptr, ptr }

@font = external dso_local global <{ [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], <{ i8, i8, i8, i8, i8, [8 x i8] }>, [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], <{ i8, i8, [11 x i8] }>, [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [43 x [13 x i8]] }>, align 16
@currentProcess = external global ptr, align 8
@__const.draw_char.mask = external hidden unnamed_addr constant [8 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @draw_pixel(i32 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
define dso_local void @draw_char(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [8 x i32], align 16
  %10 = alloca ptr, align 8
  store i8 %0, ptr %4, align 1, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !8
  store i32 %2, ptr %6, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %9, ptr align 16 @__const.draw_char.mask, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %11 = load i8, ptr %4, align 1, !tbaa !5
  %12 = zext i8 %11 to i32
  %13 = sub nsw i32 %12, 32
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [200 x [13 x i8]], ptr @font, i64 0, i64 %14
  %16 = getelementptr inbounds [13 x i8], ptr %15, i64 0, i64 0
  store ptr %16, ptr %10, align 8, !tbaa !10
  %17 = load ptr, ptr @currentProcess, align 8, !tbaa !10
  %18 = getelementptr inbounds %struct.ProcessSlot, ptr %17, i32 0, i32 1
  %19 = getelementptr inbounds %struct.Process, ptr %18, i32 0, i32 4
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %61

22:                                               ; preds = %3
  store i32 0, ptr %8, align 4, !tbaa !8
  br label %23

23:                                               ; preds = %57, %22
  %24 = load i32, ptr %8, align 4, !tbaa !8
  %25 = icmp slt i32 %24, 13
  br i1 %25, label %26, label %60

26:                                               ; preds = %23
  store i32 0, ptr %7, align 4, !tbaa !8
  br label %27

27:                                               ; preds = %53, %26
  %28 = load i32, ptr %7, align 4, !tbaa !8
  %29 = icmp slt i32 %28, 8
  br i1 %29, label %30, label %56

30:                                               ; preds = %27
  %31 = load ptr, ptr %10, align 8, !tbaa !10
  %32 = load i32, ptr %8, align 4, !tbaa !8
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %36 = zext i8 %35 to i32
  %37 = load i32, ptr %7, align 4, !tbaa !8
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [8 x i32], ptr %9, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !8
  %41 = and i32 %36, %40
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %52

43:                                               ; preds = %30
  %44 = load i32, ptr %5, align 4, !tbaa !8
  %45 = add nsw i32 %44, 8
  %46 = load i32, ptr %7, align 4, !tbaa !8
  %47 = sub nsw i32 %45, %46
  %48 = load i32, ptr %6, align 4, !tbaa !8
  %49 = add nsw i32 %48, 13
  %50 = load i32, ptr %8, align 4, !tbaa !8
  %51 = sub nsw i32 %49, %50
  call void @draw_pixel(i32 noundef %47, i32 noundef %51)
  br label %52

52:                                               ; preds = %43, %30
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %7, align 4, !tbaa !8
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %7, align 4, !tbaa !8
  br label %27, !llvm.loop !15

56:                                               ; preds = %27
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %8, align 4, !tbaa !8
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %8, align 4, !tbaa !8
  br label %23, !llvm.loop !17

60:                                               ; preds = %23
  br label %61

61:                                               ; preds = %60, %3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!13, !9, i64 140}
!13 = !{!"ProcessSlot", !11, i64 0, !14, i64 8}
!14 = !{!"Process", !9, i64 0, !9, i64 4, !6, i64 8, !9, i64 128, !9, i64 132, !6, i64 136, !6, i64 192, !9, i64 352, !11, i64 360, !11, i64 368, !11, i64 376, !6, i64 384, !9, i64 464, !11, i64 472, !11, i64 480}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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

@font = external dso_local local_unnamed_addr global <{ [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], <{ i8, i8, i8, i8, i8, [8 x i8] }>, [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], <{ i8, i8, [11 x i8] }>, [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [13 x i8], [43 x [13 x i8]] }>, align 16
@currentProcess = external local_unnamed_addr global ptr, align 8
@__const.draw_char.mask = external hidden unnamed_addr constant [8 x i32], align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @draw_char(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = zext i8 %0 to i64
  %5 = add nsw i64 %4, -32
  %6 = getelementptr inbounds [200 x [13 x i8]], ptr @font, i64 0, i64 %5
  %7 = load ptr, ptr @currentProcess, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 140
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %.preheader12, label %.loopexit

.preheader12:                                     ; preds = %3
  %11 = add nsw i32 %1, 8
  %12 = add nsw i32 %2, 13
  %.pre = load i32, ptr @__const.draw_char.mask, align 16, !tbaa !13
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @__const.draw_char.mask, i64 4), align 4
  %14 = add nsw i32 %1, 7
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @__const.draw_char.mask, i64 8), align 8
  %16 = add nsw i32 %1, 6
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @__const.draw_char.mask, i64 12), align 4
  %18 = add nsw i32 %1, 5
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @__const.draw_char.mask, i64 16), align 16
  %20 = add nsw i32 %1, 4
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @__const.draw_char.mask, i64 20), align 4
  %22 = add nsw i32 %1, 3
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @__const.draw_char.mask, i64 24), align 8
  %24 = add nsw i32 %1, 2
  %25 = load i32, ptr getelementptr inbounds (i8, ptr @__const.draw_char.mask, i64 28), align 4
  %26 = add nsw i32 %1, 1
  br label %.preheader

.preheader:                                       ; preds = %.preheader12, %55
  %indvars.iv = phi i64 [ 0, %.preheader12 ], [ %indvars.iv.next, %55 ]
  %27 = getelementptr inbounds i8, ptr %6, i64 %indvars.iv
  %28 = trunc nuw nsw i64 %indvars.iv to i32
  %29 = sub i32 %12, %28
  %30 = load i8, ptr %27, align 1, !tbaa !14
  %31 = zext i8 %30 to i32
  %32 = and i32 %.pre, %31
  %.not = icmp eq i32 %32, 0
  br i1 %.not, label %34, label %33

33:                                               ; preds = %.preheader
  tail call void @draw_pixel(i32 noundef %11, i32 noundef %29)
  %.pre17 = load i8, ptr %27, align 1, !tbaa !14
  %.pre24 = zext i8 %.pre17 to i32
  br label %34

34:                                               ; preds = %.preheader, %33
  %.pre-phi = phi i32 [ %31, %.preheader ], [ %.pre24, %33 ]
  %35 = and i32 %13, %.pre-phi
  %.not.1 = icmp eq i32 %35, 0
  br i1 %.not.1, label %37, label %36

36:                                               ; preds = %34
  tail call void @draw_pixel(i32 noundef %14, i32 noundef %29)
  %.pre18 = load i8, ptr %27, align 1, !tbaa !14
  %.pre25 = zext i8 %.pre18 to i32
  br label %37

37:                                               ; preds = %36, %34
  %.pre-phi26 = phi i32 [ %.pre25, %36 ], [ %.pre-phi, %34 ]
  %38 = and i32 %15, %.pre-phi26
  %.not.2 = icmp eq i32 %38, 0
  br i1 %.not.2, label %40, label %39

39:                                               ; preds = %37
  tail call void @draw_pixel(i32 noundef %16, i32 noundef %29)
  %.pre19 = load i8, ptr %27, align 1, !tbaa !14
  %.pre27 = zext i8 %.pre19 to i32
  br label %40

40:                                               ; preds = %39, %37
  %.pre-phi28 = phi i32 [ %.pre27, %39 ], [ %.pre-phi26, %37 ]
  %41 = and i32 %17, %.pre-phi28
  %.not.3 = icmp eq i32 %41, 0
  br i1 %.not.3, label %43, label %42

42:                                               ; preds = %40
  tail call void @draw_pixel(i32 noundef %18, i32 noundef %29)
  %.pre20 = load i8, ptr %27, align 1, !tbaa !14
  %.pre29 = zext i8 %.pre20 to i32
  br label %43

43:                                               ; preds = %42, %40
  %.pre-phi30 = phi i32 [ %.pre29, %42 ], [ %.pre-phi28, %40 ]
  %44 = and i32 %19, %.pre-phi30
  %.not.4 = icmp eq i32 %44, 0
  br i1 %.not.4, label %46, label %45

45:                                               ; preds = %43
  tail call void @draw_pixel(i32 noundef %20, i32 noundef %29)
  %.pre21 = load i8, ptr %27, align 1, !tbaa !14
  %.pre31 = zext i8 %.pre21 to i32
  br label %46

46:                                               ; preds = %45, %43
  %.pre-phi32 = phi i32 [ %.pre31, %45 ], [ %.pre-phi30, %43 ]
  %47 = and i32 %21, %.pre-phi32
  %.not.5 = icmp eq i32 %47, 0
  br i1 %.not.5, label %49, label %48

48:                                               ; preds = %46
  tail call void @draw_pixel(i32 noundef %22, i32 noundef %29)
  %.pre22 = load i8, ptr %27, align 1, !tbaa !14
  %.pre33 = zext i8 %.pre22 to i32
  br label %49

49:                                               ; preds = %48, %46
  %.pre-phi34 = phi i32 [ %.pre33, %48 ], [ %.pre-phi32, %46 ]
  %50 = and i32 %23, %.pre-phi34
  %.not.6 = icmp eq i32 %50, 0
  br i1 %.not.6, label %52, label %51

51:                                               ; preds = %49
  tail call void @draw_pixel(i32 noundef %24, i32 noundef %29)
  %.pre23 = load i8, ptr %27, align 1, !tbaa !14
  %.pre35 = zext i8 %.pre23 to i32
  br label %52

52:                                               ; preds = %51, %49
  %.pre-phi36 = phi i32 [ %.pre35, %51 ], [ %.pre-phi34, %49 ]
  %53 = and i32 %25, %.pre-phi36
  %.not.7 = icmp eq i32 %53, 0
  br i1 %.not.7, label %55, label %54

54:                                               ; preds = %52
  tail call void @draw_pixel(i32 noundef %26, i32 noundef %29)
  br label %55

55:                                               ; preds = %54, %52
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 13
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !15

.loopexit:                                        ; preds = %55, %3
  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 140}
!10 = !{!"ProcessSlot", !6, i64 0, !11, i64 8}
!11 = !{!"Process", !12, i64 0, !12, i64 4, !7, i64 8, !12, i64 128, !12, i64 132, !7, i64 136, !7, i64 192, !12, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !7, i64 384, !12, i64 464, !6, i64 472, !6, i64 480}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass