; LLVM IR from Rangobotics/differential-robot :: src (UnitTests)

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

@.str = external hidden unnamed_addr constant [38 x i8], align 1
@LeftEncoderValue = external global i32, align 4
@RightEncoderValue = external global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @CalculatePulses(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %5 = load i32, ptr %2, align 4, !tbaa !5
  switch i32 %5, label %16 [
    i32 0, label %6
    i32 1, label %7
    i32 2, label %8
    i32 3, label %9
    i32 4, label %10
    i32 5, label %11
    i32 6, label %12
    i32 7, label %13
    i32 8, label %14
    i32 9, label %15
  ]

6:                                                ; preds = %1
  store i32 0, ptr %3, align 4, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %18

7:                                                ; preds = %1
  store i32 100, ptr %3, align 4, !tbaa !5
  store i32 100, ptr %4, align 4, !tbaa !5
  br label %18

8:                                                ; preds = %1
  store i32 300, ptr %3, align 4, !tbaa !5
  store i32 200, ptr %4, align 4, !tbaa !5
  br label %18

9:                                                ; preds = %1
  store i32 500, ptr %3, align 4, !tbaa !5
  store i32 300, ptr %4, align 4, !tbaa !5
  br label %18

10:                                               ; preds = %1
  store i32 700, ptr %3, align 4, !tbaa !5
  store i32 400, ptr %4, align 4, !tbaa !5
  br label %18

11:                                               ; preds = %1
  store i32 900, ptr %3, align 4, !tbaa !5
  store i32 500, ptr %4, align 4, !tbaa !5
  br label %18

12:                                               ; preds = %1
  store i32 1000, ptr %3, align 4, !tbaa !5
  store i32 600, ptr %4, align 4, !tbaa !5
  br label %18

13:                                               ; preds = %1
  store i32 1100, ptr %3, align 4, !tbaa !5
  store i32 700, ptr %4, align 4, !tbaa !5
  br label %18

14:                                               ; preds = %1
  store i32 1200, ptr %3, align 4, !tbaa !5
  store i32 800, ptr %4, align 4, !tbaa !5
  br label %18

15:                                               ; preds = %1
  store i32 1200, ptr %3, align 4, !tbaa !5
  store i32 800, ptr %4, align 4, !tbaa !5
  br label %18

16:                                               ; preds = %1
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %18

18:                                               ; preds = %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = load i32, ptr @LeftEncoderValue, align 4, !tbaa !5
  %21 = icmp ne i32 %19, %20
  br i1 %21, label %22, label %26

22:                                               ; preds = %18
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr @LeftEncoderValue, align 4, !tbaa !5
  %25 = sub nsw i32 %23, %24
  store i32 %25, ptr @LeftEncoderValue, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %22, %18
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr @RightEncoderValue, align 4, !tbaa !5
  %29 = icmp ne i32 %27, %28
  br i1 %29, label %30, label %34

30:                                               ; preds = %26
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = load i32, ptr @RightEncoderValue, align 4, !tbaa !5
  %33 = sub nsw i32 %31, %32
  store i32 %33, ptr @RightEncoderValue, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %30, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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


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

@.str = external hidden unnamed_addr constant [38 x i8], align 1
@LeftEncoderValue = external local_unnamed_addr global i32, align 4
@RightEncoderValue = external local_unnamed_addr global i32, align 4
@switch.table.CalculatePulses = private unnamed_addr constant [10 x i32] [i32 0, i32 100, i32 300, i32 500, i32 700, i32 900, i32 1000, i32 1100, i32 1200, i32 1200], align 4
@switch.table.CalculatePulses.1 = private unnamed_addr constant [10 x i32] [i32 0, i32 100, i32 200, i32 300, i32 400, i32 500, i32 600, i32 700, i32 800, i32 800], align 4

; Function Attrs: nofree nounwind uwtable
define dso_local void @CalculatePulses(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp ult i32 %0, 10
  br i1 %2, label %switch.lookup, label %.thread

.thread:                                          ; preds = %1
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %4 = load i32, ptr @LeftEncoderValue, align 4, !tbaa !5
  br label %8

switch.lookup:                                    ; preds = %1
  %5 = zext nneg i32 %0 to i64
  %switch.gep = getelementptr inbounds [10 x i32], ptr @switch.table.CalculatePulses, i64 0, i64 %5
  %switch.load = load i32, ptr %switch.gep, align 4
  %6 = zext nneg i32 %0 to i64
  %switch.gep15 = getelementptr inbounds [10 x i32], ptr @switch.table.CalculatePulses.1, i64 0, i64 %6
  %switch.load16 = load i32, ptr %switch.gep15, align 4
  %7 = load i32, ptr @LeftEncoderValue, align 4, !tbaa !5
  %.not = icmp eq i32 %switch.load, %7
  br i1 %.not, label %11, label %8

8:                                                ; preds = %.thread, %switch.lookup
  %9 = phi i32 [ %4, %.thread ], [ %7, %switch.lookup ]
  %.013 = phi i32 [ undef, %.thread ], [ %switch.load16, %switch.lookup ]
  %.0512 = phi i32 [ undef, %.thread ], [ %switch.load, %switch.lookup ]
  %10 = sub nsw i32 %.0512, %9
  store i32 %10, ptr @LeftEncoderValue, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %8, %switch.lookup
  %.014 = phi i32 [ %.013, %8 ], [ %switch.load16, %switch.lookup ]
  %12 = load i32, ptr @RightEncoderValue, align 4, !tbaa !5
  %.not8 = icmp eq i32 %.014, %12
  br i1 %.not8, label %15, label %13

13:                                               ; preds = %11
  %14 = sub nsw i32 %.014, %12
  store i32 %14, ptr @RightEncoderValue, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %13, %11
  ret void
}

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

attributes #0 = { 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" }
attributes #1 = { 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" }

!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"}


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