; LLVM IR from giusenso/Ball-Balancing-PID-System :: pid (pid)

; 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.Point = type { i16, i16 }
%struct.PID_t = type { float, float, float, i16, [2 x i16], float, [2 x i16], float, float, float, i16, i16, i16, i32 }
%struct.Ball = type { i32, [8 x i16], [8 x i16], [8 x i16], [8 x i16], i16, i16 }

; Function Attrs: nounwind uwtable
define dso_local i32 @changeSetpoint(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca %struct.Point, align 2
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store i32 %3, ptr %6, align 2
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.Point, ptr %6, i32 0, i32 0
  %11 = load i16, ptr %10, align 2, !tbaa !9
  %12 = zext i16 %11 to i32
  %13 = icmp sgt i32 %12, 500
  br i1 %13, label %19, label %14

14:                                               ; preds = %4
  %15 = getelementptr inbounds %struct.Point, ptr %6, i32 0, i32 0
  %16 = load i16, ptr %15, align 2, !tbaa !9
  %17 = zext i16 %16 to i32
  %18 = icmp slt i32 %17, 140
  br i1 %18, label %19, label %60

19:                                               ; preds = %14, %4
  %20 = getelementptr inbounds %struct.Point, ptr %6, i32 0, i32 0
  %21 = load i16, ptr %20, align 2, !tbaa !9
  %22 = zext i16 %21 to i32
  %23 = icmp sgt i32 %22, 500
  br i1 %23, label %29, label %24

24:                                               ; preds = %19
  %25 = getelementptr inbounds %struct.Point, ptr %6, i32 0, i32 0
  %26 = load i16, ptr %25, align 2, !tbaa !9
  %27 = zext i16 %26 to i32
  %28 = icmp slt i32 %27, 140
  br i1 %28, label %29, label %60

29:                                               ; preds = %24, %19
  %30 = getelementptr inbounds %struct.Point, ptr %6, i32 0, i32 0
  %31 = load i16, ptr %30, align 2, !tbaa !9
  %32 = zext i16 %31 to i32
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.PID_t, ptr %33, i32 0, i32 3
  %35 = load i16, ptr %34, align 4, !tbaa !12
  %36 = zext i16 %35 to i32
  %37 = sub nsw i32 %32, %36
  %38 = trunc i32 %37 to i16
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Ball, ptr %39, i32 0, i32 5
  store i16 %38, ptr %40, align 4, !tbaa !16
  %41 = getelementptr inbounds %struct.Point, ptr %6, i32 0, i32 0
  %42 = load i16, ptr %41, align 2, !tbaa !9
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.PID_t, ptr %43, i32 0, i32 3
  store i16 %42, ptr %44, align 4, !tbaa !12
  %45 = getelementptr inbounds %struct.Point, ptr %6, i32 0, i32 1
  %46 = load i16, ptr %45, align 2, !tbaa !18
  %47 = zext i16 %46 to i32
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.PID_t, ptr %48, i32 0, i32 3
  %50 = load i16, ptr %49, align 4, !tbaa !12
  %51 = zext i16 %50 to i32
  %52 = sub nsw i32 %47, %51
  %53 = trunc i32 %52 to i16
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Ball, ptr %54, i32 0, i32 6
  store i16 %53, ptr %55, align 2, !tbaa !19
  %56 = getelementptr inbounds %struct.Point, ptr %6, i32 0, i32 1
  %57 = load i16, ptr %56, align 2, !tbaa !18
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.PID_t, ptr %58, i32 0, i32 3
  store i16 %57, ptr %59, align 4, !tbaa !12
  store i32 1, ptr %5, align 4
  br label %61

60:                                               ; preds = %24, %14
  store i32 0, ptr %5, align 4
  br label %61

61:                                               ; preds = %60, %29
  %62 = load i32, ptr %5, align 4
  ret i32 %62
}

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, !11, i64 0}
!10 = !{!"Point", !11, i64 0, !11, i64 2}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !11, i64 12}
!13 = !{!"PID_t", !14, i64 0, !14, i64 4, !14, i64 8, !11, i64 12, !7, i64 14, !14, i64 20, !7, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !11, i64 40, !11, i64 42, !11, i64 44, !15, i64 48}
!14 = !{!"float", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !11, i64 68}
!17 = !{!"Ball", !15, i64 0, !7, i64 4, !7, i64 20, !7, i64 36, !7, i64 52, !11, i64 68, !11, i64 70}
!18 = !{!10, !11, i64 2}
!19 = !{!17, !11, i64 70}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local range(i32 0, 2) i32 @changeSetpoint(ptr nocapture noundef %0, ptr nocapture noundef %1, ptr nocapture noundef writeonly %2, i32 %3) local_unnamed_addr #0 {
  %5 = and i32 %3, 65535
  %6 = add nsw i32 %5, -501
  %or.cond = icmp ult i32 %6, -361
  br i1 %or.cond, label %7, label %16

7:                                                ; preds = %4
  %.sroa.7.0.extract.shift = lshr i32 %3, 16
  %.sroa.7.0.extract.trunc = trunc nuw i32 %.sroa.7.0.extract.shift to i16
  %.sroa.0.0.extract.trunc = trunc i32 %3 to i16
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = load i16, ptr %8, align 4, !tbaa !5
  %10 = sub i16 %.sroa.0.0.extract.trunc, %9
  %11 = getelementptr inbounds i8, ptr %2, i64 68
  store i16 %10, ptr %11, align 4, !tbaa !12
  store i16 %.sroa.0.0.extract.trunc, ptr %8, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %1, i64 12
  %13 = load i16, ptr %12, align 4, !tbaa !5
  %14 = sub i16 %.sroa.7.0.extract.trunc, %13
  %15 = getelementptr inbounds i8, ptr %2, i64 70
  store i16 %14, ptr %15, align 2, !tbaa !14
  store i16 %.sroa.7.0.extract.trunc, ptr %12, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %4, %7
  %.0 = phi i32 [ 1, %7 ], [ 0, %4 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !10, i64 12}
!6 = !{!"PID_t", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 12, !8, i64 14, !7, i64 20, !8, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !10, i64 40, !10, i64 42, !10, i64 44, !11, i64 48}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !10, i64 68}
!13 = !{!"Ball", !11, i64 0, !8, i64 4, !8, i64 20, !8, i64 36, !8, i64 52, !10, i64 68, !10, i64 70}
!14 = !{!13, !10, i64 70}


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