; LLVM IR from devantler/software-engineering-f22-shared :: IOT/BudgetManagementExcercise-03-28/ESP-Project/components/components/usb/test (report)

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

@mock_hid_process_report.x_pos = external hidden global i32, align 4
@mock_hid_process_report.y_pos = external hidden global i32, align 4
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1

declare i32 @printf(ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
define dso_local void @mock_hid_process_report(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.anon, ptr %5, i32 0, i32 1
  %7 = load i8, ptr %6, align 1, !tbaa !11
  %8 = zext i8 %7 to i32
  %9 = and i32 %8, 128
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %19

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 1
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = zext i8 %14 to i32
  %16 = and i32 %15, 127
  %17 = load i32, ptr @mock_hid_process_report.x_pos, align 4, !tbaa !9
  %18 = add nsw i32 %17, %16
  store i32 %18, ptr @mock_hid_process_report.x_pos, align 4, !tbaa !9
  br label %27

19:                                               ; preds = %2
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 1
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = zext i8 %22 to i32
  %24 = and i32 %23, 127
  %25 = load i32, ptr @mock_hid_process_report.x_pos, align 4, !tbaa !9
  %26 = sub nsw i32 %25, %24
  store i32 %26, ptr @mock_hid_process_report.x_pos, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %19, %11
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.anon, ptr %28, i32 0, i32 2
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = zext i8 %30 to i32
  %32 = and i32 %31, 128
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %42

34:                                               ; preds = %27
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.anon, ptr %35, i32 0, i32 2
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = zext i8 %37 to i32
  %39 = and i32 %38, 127
  %40 = load i32, ptr @mock_hid_process_report.y_pos, align 4, !tbaa !9
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr @mock_hid_process_report.y_pos, align 4, !tbaa !9
  br label %50

42:                                               ; preds = %27
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.anon, ptr %43, i32 0, i32 2
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = zext i8 %45 to i32
  %47 = and i32 %46, 127
  %48 = load i32, ptr @mock_hid_process_report.y_pos, align 4, !tbaa !9
  %49 = sub nsw i32 %48, %47
  store i32 %49, ptr @mock_hid_process_report.y_pos, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %42, %34
  %51 = load i32, ptr @mock_hid_process_report.x_pos, align 4, !tbaa !9
  %52 = load i32, ptr @mock_hid_process_report.y_pos, align 4, !tbaa !9
  %53 = load i32, ptr %4, align 4, !tbaa !9
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %51, i32 noundef %52, i32 noundef %53)
  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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}


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

@mock_hid_process_report.x_pos = external hidden local_unnamed_addr global i32, align 4
@mock_hid_process_report.y_pos = external hidden local_unnamed_addr global i32, align 4
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @mock_hid_process_report(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 1
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = zext i8 %4 to i32
  %.not = icmp sgt i8 %4, -1
  br i1 %.not, label %10, label %6

6:                                                ; preds = %2
  %7 = and i32 %5, 127
  %8 = load i32, ptr @mock_hid_process_report.x_pos, align 4, !tbaa !8
  %9 = add nsw i32 %8, %7
  br label %13

10:                                               ; preds = %2
  %11 = load i32, ptr @mock_hid_process_report.x_pos, align 4, !tbaa !8
  %12 = sub nsw i32 %11, %5
  br label %13

13:                                               ; preds = %10, %6
  %storemerge = phi i32 [ %12, %10 ], [ %9, %6 ]
  store i32 %storemerge, ptr @mock_hid_process_report.x_pos, align 4, !tbaa !8
  %14 = getelementptr inbounds i8, ptr %0, i64 2
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = zext i8 %15 to i32
  %.not6 = icmp sgt i8 %15, -1
  br i1 %.not6, label %21, label %17

17:                                               ; preds = %13
  %18 = and i32 %16, 127
  %19 = load i32, ptr @mock_hid_process_report.y_pos, align 4, !tbaa !8
  %20 = add nsw i32 %19, %18
  br label %24

21:                                               ; preds = %13
  %22 = load i32, ptr @mock_hid_process_report.y_pos, align 4, !tbaa !8
  %23 = sub nsw i32 %22, %16
  br label %24

24:                                               ; preds = %21, %17
  %storemerge7 = phi i32 [ %23, %21 ], [ %20, %17 ]
  store i32 %storemerge7, ptr @mock_hid_process_report.y_pos, align 4, !tbaa !8
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %storemerge, i32 noundef %storemerge7, i32 noundef %1)
  ret void
}

attributes #0 = { nofree nounwind "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 = { nofree 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


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