; LLVM IR from cyberbotics/webots_ros2 :: webots_ros2_driver/webots/src/controller/c (motor)

; 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.Motor = type { [9 x i8], i32, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, i8, i32, i32, i32, i32, ptr }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [43 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [62 x i8], align 1
@__FUNCTION__.wb_motor_set_velocity = external hidden unnamed_addr constant [22 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [85 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare hidden ptr @motor_get_struct(i16 noundef zeroext) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i1 @llvm.is.fpclass.f64(double, i32 immarg) #2

declare void @robot_mutex_lock(...) #4

declare void @robot_mutex_unlock(...) #4

; Function Attrs: nounwind uwtable
define dso_local void @wb_motor_set_velocity(i16 noundef zeroext %0, double noundef %1) #1 {
  %3 = alloca i16, align 2
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store i16 %0, ptr %3, align 2, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %9 = load double, ptr %4, align 8, !tbaa !9
  %10 = call i1 @llvm.is.fpclass.f64(double %9, i32 3)
  br i1 %10, label %11, label %14

11:                                               ; preds = %2
  %12 = load ptr, ptr @stderr, align 8, !tbaa !11
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef @.str.3, ptr noundef @__FUNCTION__.wb_motor_set_velocity) #5
  br label %87

14:                                               ; preds = %2
  call void (...) @robot_mutex_lock()
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %15 = load i16, ptr %3, align 2, !tbaa !5
  %16 = call ptr @motor_get_struct(i16 noundef zeroext %15)
  store ptr %16, ptr %5, align 8, !tbaa !11
  %17 = load ptr, ptr %5, align 8, !tbaa !11
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %81

19:                                               ; preds = %14
  %20 = load double, ptr %4, align 8, !tbaa !9
  %21 = fcmp olt double %20, 0.000000e+00
  br i1 %21, label %22, label %40

22:                                               ; preds = %19
  %23 = load ptr, ptr %5, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct.Motor, ptr %23, i32 0, i32 2
  %25 = load double, ptr %24, align 8, !tbaa !13
  %26 = call double @llvm.fabs.f64(double %25) #6
  %27 = fcmp oeq double %26, 0x7FF0000000000000
  %28 = bitcast double %25 to i64
  %29 = icmp slt i64 %28, 0
  %30 = select i1 %29, i32 -1, i32 1
  %31 = select i1 %27, i32 %30, i32 0
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %39, label %33

33:                                               ; preds = %22
  %34 = load ptr, ptr @stderr, align 8, !tbaa !11
  %35 = load ptr, ptr %5, align 8, !tbaa !11
  %36 = getelementptr inbounds %struct.Motor, ptr %35, i32 0, i32 2
  %37 = load double, ptr %36, align 8, !tbaa !13
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef @.str.4, ptr noundef @__FUNCTION__.wb_motor_set_velocity, double noundef %37) #5
  call void (...) @robot_mutex_unlock()
  store i32 1, ptr %6, align 4
  br label %85

39:                                               ; preds = %22
  br label %40

40:                                               ; preds = %39, %19
  %41 = load ptr, ptr %5, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.Motor, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds [9 x i8], ptr %42, i64 0, i64 2
  store i8 1, ptr %43, align 2, !tbaa !16
  %44 = load double, ptr %4, align 8, !tbaa !9
  %45 = load ptr, ptr %5, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.Motor, ptr %45, i32 0, i32 3
  store double %44, ptr %46, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !18
  br label %47

47:                                               ; preds = %77, %40
  %48 = load i32, ptr %7, align 4, !tbaa !18
  %49 = load ptr, ptr %5, align 8, !tbaa !11
  %50 = getelementptr inbounds %struct.Motor, ptr %49, i32 0, i32 26
  %51 = load i32, ptr %50, align 8, !tbaa !19
  %52 = icmp slt i32 %48, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %47
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %80

54:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %55 = load ptr, ptr %5, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.Motor, ptr %55, i32 0, i32 27
  %57 = load ptr, ptr %56, align 8, !tbaa !20
  %58 = load i32, ptr %7, align 4, !tbaa !18
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i16, ptr %57, i64 %59
  %61 = load i16, ptr %60, align 2, !tbaa !5
  %62 = call ptr @motor_get_struct(i16 noundef zeroext %61)
  store ptr %62, ptr %8, align 8, !tbaa !11
  %63 = load ptr, ptr %8, align 8, !tbaa !11
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %73

65:                                               ; preds = %54
  %66 = load double, ptr %4, align 8, !tbaa !9
  %67 = load ptr, ptr %8, align 8, !tbaa !11
  %68 = getelementptr inbounds %struct.Motor, ptr %67, i32 0, i32 21
  %69 = load double, ptr %68, align 8, !tbaa !21
  %70 = fmul double %66, %69
  %71 = load ptr, ptr %8, align 8, !tbaa !11
  %72 = getelementptr inbounds %struct.Motor, ptr %71, i32 0, i32 3
  store double %70, ptr %72, align 8, !tbaa !17
  br label %76

73:                                               ; preds = %54
  %74 = load ptr, ptr @stderr, align 8, !tbaa !11
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef @.str, ptr noundef @__FUNCTION__.wb_motor_set_velocity) #5
  br label %76

76:                                               ; preds = %73, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %7, align 4, !tbaa !18
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %7, align 4, !tbaa !18
  br label %47, !llvm.loop !22

80:                                               ; preds = %53
  br label %84

81:                                               ; preds = %14
  %82 = load ptr, ptr @stderr, align 8, !tbaa !11
  %83 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %82, ptr noundef @.str.1, ptr noundef @__FUNCTION__.wb_motor_set_velocity) #5
  br label %84

84:                                               ; preds = %81, %80
  call void (...) @robot_mutex_unlock()
  store i32 0, ptr %6, align 4
  br label %85

85:                                               ; preds = %84, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  %86 = load i32, ptr %6, align 4
  switch i32 %86, label %88 [
    i32 0, label %87
    i32 1, label %87
  ]

87:                                               ; preds = %85, %85, %11
  ret void

88:                                               ; preds = %85
  unreachable
}

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #4 = { "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 #5 = { nounwind }
attributes #6 = { memory(none) }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !10, i64 16}
!14 = !{!"", !7, i64 0, !15, i64 12, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !7, i64 176, !15, i64 180, !15, i64 184, !15, i64 188, !15, i64 192, !12, i64 200}
!15 = !{!"int", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!14, !10, i64 24}
!18 = !{!15, !15, i64 0}
!19 = !{!14, !15, i64 192}
!20 = !{!14, !12, i64 200}
!21 = !{!14, !10, i64 168}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [43 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [62 x i8], align 1
@__FUNCTION__.wb_motor_set_velocity = external hidden unnamed_addr constant [22 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [85 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden ptr @motor_get_struct(i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

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

declare void @robot_mutex_lock(...) local_unnamed_addr #3

declare void @robot_mutex_unlock(...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @wb_motor_set_velocity(i16 noundef zeroext %0, double noundef %1) local_unnamed_addr #0 {
  %3 = fcmp uno double %1, 0.000000e+00
  br i1 %3, label %4, label %7

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.3, ptr noundef nonnull @__FUNCTION__.wb_motor_set_velocity) #4
  br label %46

7:                                                ; preds = %2
  tail call void (...) @robot_mutex_lock() #5
  %8 = tail call ptr @motor_get_struct(i16 noundef zeroext %0)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %43, label %9

9:                                                ; preds = %7
  %10 = fcmp olt double %1, 0.000000e+00
  br i1 %10, label %11, label %19

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %8, i64 16
  %13 = load double, ptr %12, align 8, !tbaa !9
  %14 = tail call double @llvm.fabs.f64(double %13) #6
  %15 = fcmp oeq double %14, 0x7FF0000000000000
  br i1 %15, label %19, label %16

16:                                               ; preds = %11
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.4, ptr noundef nonnull @__FUNCTION__.wb_motor_set_velocity, double noundef %13) #4
  tail call void (...) @robot_mutex_unlock() #5
  br label %46

19:                                               ; preds = %11, %9
  %20 = getelementptr inbounds i8, ptr %8, i64 2
  store i8 1, ptr %20, align 2, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %8, i64 24
  store double %1, ptr %21, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %8, i64 192
  %23 = load i32, ptr %22, align 8, !tbaa !15
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %19
  %25 = getelementptr inbounds i8, ptr %8, i64 200
  br label %26

26:                                               ; preds = %.lr.ph, %39
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %39 ]
  %27 = load ptr, ptr %25, align 8, !tbaa !16
  %28 = getelementptr inbounds i16, ptr %27, i64 %indvars.iv
  %29 = load i16, ptr %28, align 2, !tbaa !17
  %30 = tail call ptr @motor_get_struct(i16 noundef zeroext %29)
  %.not19 = icmp eq ptr %30, null
  br i1 %.not19, label %36, label %31

31:                                               ; preds = %26
  %32 = getelementptr inbounds i8, ptr %30, i64 168
  %33 = load double, ptr %32, align 8, !tbaa !19
  %34 = fmul double %33, %1
  %35 = getelementptr inbounds i8, ptr %30, i64 24
  store double %34, ptr %35, align 8, !tbaa !14
  br label %39

36:                                               ; preds = %26
  %37 = load ptr, ptr @stderr, align 8, !tbaa !5
  %38 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef nonnull @.str, ptr noundef nonnull @__FUNCTION__.wb_motor_set_velocity) #4
  br label %39

39:                                               ; preds = %36, %31
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %40 = load i32, ptr %22, align 8, !tbaa !15
  %41 = sext i32 %40 to i64
  %42 = icmp slt i64 %indvars.iv.next, %41
  br i1 %42, label %26, label %.loopexit, !llvm.loop !20

43:                                               ; preds = %7
  %44 = load ptr, ptr @stderr, align 8, !tbaa !5
  %45 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef nonnull @.str.1, ptr noundef nonnull @__FUNCTION__.wb_motor_set_velocity) #4
  br label %.loopexit

.loopexit:                                        ; preds = %39, %19, %43
  tail call void (...) @robot_mutex_unlock() #5
  br label %46

46:                                               ; preds = %16, %.loopexit, %4
  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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { "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 #4 = { cold nounwind }
attributes #5 = { nounwind }
attributes #6 = { memory(none) }

!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 16}
!10 = !{!"", !7, i64 0, !11, i64 12, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !7, i64 176, !11, i64 180, !11, i64 184, !11, i64 188, !11, i64 192, !6, i64 200}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !12, i64 24}
!15 = !{!10, !11, i64 192}
!16 = !{!10, !6, i64 200}
!17 = !{!18, !18, i64 0}
!18 = !{!"short", !7, i64 0}
!19 = !{!10, !12, i64 168}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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