; 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.7 = external hidden unnamed_addr constant [60 x i8], align 1
@__FUNCTION__.wb_motor_set_force = external hidden unnamed_addr constant [19 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; 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) #3

declare void @robot_mutex_lock(...) #4

declare void @robot_mutex_unlock(...) #4

; Function Attrs: nounwind uwtable
define dso_local void @wb_motor_set_force(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 ptr, align 8
  store i16 %0, ptr %3, align 2, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %8 = load double, ptr %4, align 8, !tbaa !9
  %9 = call i1 @llvm.is.fpclass.f64(double %8, i32 3)
  br i1 %9, label %10, label %13

10:                                               ; preds = %2
  %11 = load ptr, ptr @stderr, align 8, !tbaa !11
  %12 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef @.str.7, ptr noundef @__FUNCTION__.wb_motor_set_force) #5
  br label %63

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

18:                                               ; preds = %13
  %19 = load ptr, ptr %5, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.Motor, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds [9 x i8], ptr %20, i64 0, i64 4
  store i8 1, ptr %21, align 4, !tbaa !13
  %22 = load double, ptr %4, align 8, !tbaa !9
  %23 = load ptr, ptr %5, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct.Motor, ptr %23, i32 0, i32 5
  store double %22, ptr %24, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !17
  br label %25

25:                                               ; preds = %55, %18
  %26 = load i32, ptr %6, align 4, !tbaa !17
  %27 = load ptr, ptr %5, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.Motor, ptr %27, i32 0, i32 26
  %29 = load i32, ptr %28, align 8, !tbaa !18
  %30 = icmp slt i32 %26, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %58

32:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %33 = load ptr, ptr %5, align 8, !tbaa !11
  %34 = getelementptr inbounds %struct.Motor, ptr %33, i32 0, i32 27
  %35 = load ptr, ptr %34, align 8, !tbaa !19
  %36 = load i32, ptr %6, align 4, !tbaa !17
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i16, ptr %35, i64 %37
  %39 = load i16, ptr %38, align 2, !tbaa !5
  %40 = call ptr @motor_get_struct(i16 noundef zeroext %39)
  store ptr %40, ptr %7, align 8, !tbaa !11
  %41 = load ptr, ptr %7, align 8, !tbaa !11
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %51

43:                                               ; preds = %32
  %44 = load double, ptr %4, align 8, !tbaa !9
  %45 = load ptr, ptr %7, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.Motor, ptr %45, i32 0, i32 21
  %47 = load double, ptr %46, align 8, !tbaa !20
  %48 = fmul double %44, %47
  %49 = load ptr, ptr %7, align 8, !tbaa !11
  %50 = getelementptr inbounds %struct.Motor, ptr %49, i32 0, i32 5
  store double %48, ptr %50, align 8, !tbaa !14
  br label %54

51:                                               ; preds = %32
  %52 = load ptr, ptr @stderr, align 8, !tbaa !11
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str, ptr noundef @__FUNCTION__.wb_motor_set_force) #5
  br label %54

54:                                               ; preds = %51, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %6, align 4, !tbaa !17
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %6, align 4, !tbaa !17
  br label %25, !llvm.loop !21

58:                                               ; preds = %31
  br label %62

59:                                               ; preds = %13
  %60 = load ptr, ptr @stderr, align 8, !tbaa !11
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str.1, ptr noundef @__FUNCTION__.wb_motor_set_force) #5
  br label %62

62:                                               ; preds = %59, %58
  call void (...) @robot_mutex_unlock()
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %63

63:                                               ; preds = %62, %10
  ret void
}

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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 }

!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 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 40}
!15 = !{!"", !7, i64 0, !16, 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, !16, i64 180, !16, i64 184, !16, i64 188, !16, i64 192, !12, i64 200}
!16 = !{!"int", !7, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!15, !16, i64 192}
!19 = !{!15, !12, i64 200}
!20 = !{!15, !10, i64 168}
!21 = distinct !{!21, !22}
!22 = !{!"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.7 = external hidden unnamed_addr constant [60 x i8], align 1
@__FUNCTION__.wb_motor_set_force = external hidden unnamed_addr constant [19 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @wb_motor_set_force(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.7, ptr noundef nonnull @__FUNCTION__.wb_motor_set_force) #3
  br label %36

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

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %8, i64 4
  store i8 1, ptr %10, align 4, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %8, i64 40
  store double %1, ptr %11, align 8, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %8, i64 192
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %9
  %15 = getelementptr inbounds i8, ptr %8, i64 200
  br label %16

16:                                               ; preds = %.lr.ph, %29
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %29 ]
  %17 = load ptr, ptr %15, align 8, !tbaa !15
  %18 = getelementptr inbounds i16, ptr %17, i64 %indvars.iv
  %19 = load i16, ptr %18, align 2, !tbaa !16
  %20 = tail call ptr @motor_get_struct(i16 noundef zeroext %19)
  %.not16 = icmp eq ptr %20, null
  br i1 %.not16, label %26, label %21

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %20, i64 168
  %23 = load double, ptr %22, align 8, !tbaa !18
  %24 = fmul double %23, %1
  %25 = getelementptr inbounds i8, ptr %20, i64 40
  store double %24, ptr %25, align 8, !tbaa !10
  br label %29

26:                                               ; preds = %16
  %27 = load ptr, ptr @stderr, align 8, !tbaa !5
  %28 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef nonnull @.str, ptr noundef nonnull @__FUNCTION__.wb_motor_set_force) #3
  br label %29

29:                                               ; preds = %26, %21
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %30 = load i32, ptr %12, align 8, !tbaa !14
  %31 = sext i32 %30 to i64
  %32 = icmp slt i64 %indvars.iv.next, %31
  br i1 %32, label %16, label %.loopexit, !llvm.loop !19

33:                                               ; preds = %7
  %34 = load ptr, ptr @stderr, align 8, !tbaa !5
  %35 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str.1, ptr noundef nonnull @__FUNCTION__.wb_motor_set_force) #3
  br label %.loopexit

.loopexit:                                        ; preds = %29, %9, %33
  tail call void (...) @robot_mutex_unlock() #4
  br label %36

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


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