; LLVM IR from Stephane-D/SGDK :: src (bmp)

; 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.Line = type { %struct.Vect2D_s16, %struct.Vect2D_s16, i16 }
%struct.Vect2D_s16 = type { i16, i16 }

; 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
define dso_local void @BMP_drawLine_old(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i16, align 2
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca i16, align 2
  %8 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call zeroext i16 @BMP_clipLine(ptr noundef %9)
  %11 = icmp ne i16 %10, 0
  br i1 %11, label %12, label %69

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Line, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.Vect2D_s16, ptr %14, i32 0, i32 0
  %16 = load i16, ptr %15, align 2, !tbaa !9
  store i16 %16, ptr %7, align 2, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #3
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Line, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.Vect2D_s16, ptr %18, i32 0, i32 1
  %20 = load i16, ptr %19, align 2, !tbaa !14
  store i16 %20, ptr %8, align 2, !tbaa !13
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Line, ptr %21, i32 0, i32 1
  %23 = getelementptr inbounds %struct.Vect2D_s16, ptr %22, i32 0, i32 0
  %24 = load i16, ptr %23, align 2, !tbaa !15
  %25 = sext i16 %24 to i32
  %26 = load i16, ptr %7, align 2, !tbaa !13
  %27 = sext i16 %26 to i32
  %28 = sub nsw i32 %25, %27
  %29 = trunc i32 %28 to i16
  store i16 %29, ptr %3, align 2, !tbaa !13
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Line, ptr %30, i32 0, i32 1
  %32 = getelementptr inbounds %struct.Vect2D_s16, ptr %31, i32 0, i32 1
  %33 = load i16, ptr %32, align 2, !tbaa !16
  %34 = sext i16 %33 to i32
  %35 = load i16, ptr %8, align 2, !tbaa !13
  %36 = sext i16 %35 to i32
  %37 = sub nsw i32 %34, %36
  %38 = trunc i32 %37 to i16
  store i16 %38, ptr %4, align 2, !tbaa !13
  %39 = load i16, ptr %3, align 2, !tbaa !13
  %40 = sext i16 %39 to i32
  %41 = icmp slt i32 %40, 0
  br i1 %41, label %42, label %47

42:                                               ; preds = %12
  %43 = load i16, ptr %3, align 2, !tbaa !13
  %44 = sext i16 %43 to i32
  %45 = sub nsw i32 0, %44
  %46 = trunc i32 %45 to i16
  store i16 %46, ptr %3, align 2, !tbaa !13
  store i16 -1, ptr %5, align 2, !tbaa !13
  br label %48

47:                                               ; preds = %12
  store i16 1, ptr %5, align 2, !tbaa !13
  br label %48

48:                                               ; preds = %47, %42
  %49 = load i16, ptr %4, align 2, !tbaa !13
  %50 = sext i16 %49 to i32
  %51 = icmp slt i32 %50, 0
  br i1 %51, label %52, label %57

52:                                               ; preds = %48
  %53 = load i16, ptr %4, align 2, !tbaa !13
  %54 = sext i16 %53 to i32
  %55 = sub nsw i32 0, %54
  %56 = trunc i32 %55 to i16
  store i16 %56, ptr %4, align 2, !tbaa !13
  store i16 -128, ptr %6, align 2, !tbaa !13
  br label %58

57:                                               ; preds = %48
  store i16 128, ptr %6, align 2, !tbaa !13
  br label %58

58:                                               ; preds = %57, %52
  %59 = load i16, ptr %7, align 2, !tbaa !13
  %60 = load i16, ptr %8, align 2, !tbaa !13
  %61 = load i16, ptr %3, align 2, !tbaa !13
  %62 = load i16, ptr %4, align 2, !tbaa !13
  %63 = load i16, ptr %5, align 2, !tbaa !13
  %64 = load i16, ptr %6, align 2, !tbaa !13
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.Line, ptr %65, i32 0, i32 2
  %67 = load i16, ptr %66, align 2, !tbaa !17
  %68 = trunc i16 %67 to i8
  call void @drawLine_old(i16 noundef zeroext %59, i16 noundef zeroext %60, i16 noundef signext %61, i16 noundef signext %62, i16 noundef signext %63, i16 noundef signext %64, i8 noundef zeroext %68)
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #3
  br label %69

69:                                               ; preds = %58, %1
  ret void
}

declare zeroext i16 @BMP_clipLine(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @drawLine_old(i16 noundef zeroext, i16 noundef zeroext, i16 noundef signext, i16 noundef signext, i16 noundef signext, i16 noundef signext, i8 noundef zeroext) #1

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


; 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 @BMP_drawLine_old(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call zeroext i16 @BMP_clipLine(ptr noundef %0) #3
  %.not = icmp eq i16 %2, 0
  br i1 %.not, label %17, label %3

3:                                                ; preds = %1
  %4 = load i16, ptr %0, align 2, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 2
  %6 = load i16, ptr %5, align 2, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i16, ptr %7, align 2, !tbaa !12
  %9 = sub i16 %8, %4
  %10 = getelementptr inbounds i8, ptr %0, i64 6
  %11 = load i16, ptr %10, align 2, !tbaa !13
  %12 = sub i16 %11, %6
  %.inv = icmp sgt i16 %9, -1
  %.019 = select i1 %.inv, i16 1, i16 -1
  %.0 = tail call i16 @llvm.abs.i16(i16 %9, i1 false)
  %13 = icmp slt i16 %12, 0
  %.018 = select i1 %13, i16 -128, i16 128
  %.017 = tail call i16 @llvm.abs.i16(i16 %12, i1 false)
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load i16, ptr %14, align 2, !tbaa !14
  %16 = trunc i16 %15 to i8
  tail call void @drawLine_old(i16 noundef zeroext %4, i16 noundef zeroext %6, i16 noundef signext %.0, i16 noundef signext %.017, i16 noundef signext %.019, i16 noundef signext %.018, i8 noundef zeroext %16)
  br label %17

17:                                               ; preds = %3, %1
  ret void
}

declare zeroext i16 @BMP_clipLine(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @drawLine_old(i16 noundef zeroext, i16 noundef zeroext, i16 noundef signext, i16 noundef signext, i16 noundef signext, i16 noundef signext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.abs.i16(i16, 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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !8, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !8, i64 8}
!7 = !{!"", !8, i64 0, !8, i64 2}
!8 = !{!"short", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!6, !8, i64 2}
!12 = !{!6, !8, i64 4}
!13 = !{!6, !8, i64 6}
!14 = !{!6, !8, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass