; 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
@__FUNCTION__.wb_motor_set_position_no_mutex = external hidden unnamed_addr constant [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @wb_motor_set_position_no_mutex(i16 noundef zeroext %0, double noundef %1) #0 {
  %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
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %8 = load i16, ptr %3, align 2, !tbaa !5
  %9 = call ptr @motor_get_struct(i16 noundef zeroext %8)
  store ptr %9, ptr %5, align 8, !tbaa !11
  %10 = load ptr, ptr %5, align 8, !tbaa !11
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %66

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

19:                                               ; preds = %62, %12
  %20 = load i32, ptr %6, align 4, !tbaa !17
  %21 = load ptr, ptr %5, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.Motor, ptr %21, i32 0, i32 26
  %23 = load i32, ptr %22, align 8, !tbaa !18
  %24 = icmp slt i32 %20, %23
  br i1 %24, label %26, label %25

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

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

37:                                               ; preds = %26
  %38 = load double, ptr %4, align 8, !tbaa !9
  %39 = call double @llvm.fabs.f64(double %38) #5
  %40 = fcmp oeq double %39, 0x7FF0000000000000
  %41 = bitcast double %38 to i64
  %42 = icmp slt i64 %41, 0
  %43 = select i1 %42, i32 -1, i32 1
  %44 = select i1 %40, i32 %43, i32 0
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %48

46:                                               ; preds = %37
  %47 = load double, ptr %4, align 8, !tbaa !9
  br label %54

48:                                               ; preds = %37
  %49 = load double, ptr %4, align 8, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.Motor, ptr %50, i32 0, i32 21
  %52 = load double, ptr %51, align 8, !tbaa !20
  %53 = fmul double %49, %52
  br label %54

54:                                               ; preds = %48, %46
  %55 = phi double [ %47, %46 ], [ %53, %48 ]
  %56 = load ptr, ptr %7, align 8, !tbaa !11
  %57 = getelementptr inbounds %struct.Motor, ptr %56, i32 0, i32 2
  store double %55, ptr %57, align 8, !tbaa !14
  br label %61

58:                                               ; preds = %26
  %59 = load ptr, ptr @stderr, align 8, !tbaa !11
  %60 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %59, ptr noundef @.str, ptr noundef @__FUNCTION__.wb_motor_set_position_no_mutex) #4
  br label %61

61:                                               ; preds = %58, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %6, align 4, !tbaa !17
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %6, align 4, !tbaa !17
  br label %19, !llvm.loop !21

65:                                               ; preds = %25
  br label %69

66:                                               ; preds = %2
  %67 = load ptr, ptr @stderr, align 8, !tbaa !11
  %68 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str.1, ptr noundef @__FUNCTION__.wb_motor_set_position_no_mutex) #4
  br label %69

69:                                               ; preds = %66, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

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

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

; 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) #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 = { 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 = { nounwind }
attributes #5 = { 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 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 16}
!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
@__FUNCTION__.wb_motor_set_position_no_mutex = external hidden unnamed_addr constant [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @wb_motor_set_position_no_mutex(i16 noundef zeroext %0, double noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @motor_get_struct(i16 noundef zeroext %0)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %42, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 1, ptr %5, align 1, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 16
  store double %1, ptr %6, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %3, i64 192
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %4
  %10 = getelementptr inbounds i8, ptr %3, i64 200
  %11 = tail call double @llvm.fabs.f64(double %1) #3
  %12 = fcmp oeq double %11, 0x7FF0000000000000
  br i1 %12, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %22
  %indvars.iv21 = phi i64 [ %indvars.iv.next22, %22 ], [ 0, %.lr.ph ]
  %13 = load ptr, ptr %10, align 8, !tbaa !14
  %14 = getelementptr inbounds i16, ptr %13, i64 %indvars.iv21
  %15 = load i16, ptr %14, align 2, !tbaa !15
  %16 = tail call ptr @motor_get_struct(i16 noundef zeroext %15)
  %.not17.us = icmp eq ptr %16, null
  br i1 %.not17.us, label %19, label %17

17:                                               ; preds = %.lr.ph.split.us
  %18 = getelementptr inbounds i8, ptr %16, i64 16
  store double %1, ptr %18, align 8, !tbaa !8
  br label %22

19:                                               ; preds = %.lr.ph.split.us
  %20 = load ptr, ptr @stderr, align 8, !tbaa !17
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str, ptr noundef nonnull @__FUNCTION__.wb_motor_set_position_no_mutex) #4
  br label %22

22:                                               ; preds = %19, %17
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %23 = load i32, ptr %7, align 8, !tbaa !13
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %indvars.iv.next22, %24
  br i1 %25, label %.lr.ph.split.us, label %.loopexit, !llvm.loop !18

.lr.ph.split:                                     ; preds = %.lr.ph, %38
  %indvars.iv = phi i64 [ %indvars.iv.next, %38 ], [ 0, %.lr.ph ]
  %26 = load ptr, ptr %10, align 8, !tbaa !14
  %27 = getelementptr inbounds i16, ptr %26, i64 %indvars.iv
  %28 = load i16, ptr %27, align 2, !tbaa !15
  %29 = tail call ptr @motor_get_struct(i16 noundef zeroext %28)
  %.not17 = icmp eq ptr %29, null
  br i1 %.not17, label %35, label %30

30:                                               ; preds = %.lr.ph.split
  %31 = getelementptr inbounds i8, ptr %29, i64 168
  %32 = load double, ptr %31, align 8, !tbaa !20
  %33 = fmul double %32, %1
  %34 = getelementptr inbounds i8, ptr %29, i64 16
  store double %33, ptr %34, align 8, !tbaa !8
  br label %38

35:                                               ; preds = %.lr.ph.split
  %36 = load ptr, ptr @stderr, align 8, !tbaa !17
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str, ptr noundef nonnull @__FUNCTION__.wb_motor_set_position_no_mutex) #4
  br label %38

38:                                               ; preds = %35, %30
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = load i32, ptr %7, align 8, !tbaa !13
  %40 = sext i32 %39 to i64
  %41 = icmp slt i64 %indvars.iv.next, %40
  br i1 %41, label %.lr.ph.split, label %.loopexit, !llvm.loop !18

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

.loopexit:                                        ; preds = %38, %22, %4, %42
  ret void
}

; 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

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


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