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

; 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.Skin = type { ptr, ptr, i32, ptr, ptr, ptr }
%struct.BoneRequest = type { i32, i32, [4 x double], i8, ptr }

@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [38 x i8], align 1
@__FUNCTION__.wb_skin_set_bone_position = external hidden unnamed_addr constant [26 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i1 @llvm.is.fpclass.f64(double, i32 immarg) #1

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

declare void @robot_mutex_lock(...) #3

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

declare void @robot_mutex_unlock(...) #3

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #5

; Function Attrs: nounwind uwtable
declare hidden void @add_request(ptr noundef, ptr noundef) #4

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

declare void @wb_robot_flush_unlocked(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @wb_skin_set_bone_position(i16 noundef zeroext %0, i32 noundef %1, ptr noundef %2, i8 noundef signext %3) #4 {
  %5 = alloca i16, align 2
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store i16 %0, ptr %5, align 2, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !11
  store i8 %3, ptr %8, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %27, %4
  %14 = load i32, ptr %9, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 3
  br i1 %15, label %16, label %30

16:                                               ; preds = %13
  %17 = load ptr, ptr %7, align 8, !tbaa !11
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds double, ptr %17, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !14
  %22 = call i1 @llvm.is.fpclass.f64(double %21, i32 3)
  br i1 %22, label %23, label %26

23:                                               ; preds = %16
  %24 = load ptr, ptr @stderr, align 8, !tbaa !11
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef @.str.4, ptr noundef @__FUNCTION__.wb_skin_set_bone_position) #6
  store i32 1, ptr %10, align 4
  br label %84

26:                                               ; preds = %16
  br label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %9, align 4, !tbaa !9
  br label %13, !llvm.loop !16

30:                                               ; preds = %13
  call void (...) @robot_mutex_lock()
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %31 = load i16, ptr %5, align 2, !tbaa !5
  %32 = call ptr @skin_get_struct(i16 noundef zeroext %31)
  store ptr %32, ptr %11, align 8, !tbaa !11
  %33 = load ptr, ptr %11, align 8, !tbaa !11
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %79

35:                                               ; preds = %30
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %44, label %38

38:                                               ; preds = %35
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = load ptr, ptr %11, align 8, !tbaa !11
  %41 = getelementptr inbounds %struct.Skin, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !18
  %43 = icmp sge i32 %39, %42
  br i1 %43, label %44, label %47

44:                                               ; preds = %38, %35
  %45 = load ptr, ptr @stderr, align 8, !tbaa !11
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.2, ptr noundef @__FUNCTION__.wb_skin_set_bone_position) #6
  call void (...) @robot_mutex_unlock()
  store i32 1, ptr %10, align 4
  br label %83

47:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %48 = call noalias ptr @malloc(i64 noundef 56) #7
  store ptr %48, ptr %12, align 8, !tbaa !11
  %49 = load ptr, ptr %12, align 8, !tbaa !11
  %50 = getelementptr inbounds %struct.BoneRequest, ptr %49, i32 0, i32 0
  store i32 2, ptr %50, align 8, !tbaa !20
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = load ptr, ptr %12, align 8, !tbaa !11
  %53 = getelementptr inbounds %struct.BoneRequest, ptr %52, i32 0, i32 1
  store i32 %51, ptr %53, align 4, !tbaa !22
  %54 = load ptr, ptr %7, align 8, !tbaa !11
  %55 = getelementptr inbounds double, ptr %54, i64 0
  %56 = load double, ptr %55, align 8, !tbaa !14
  %57 = load ptr, ptr %12, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.BoneRequest, ptr %57, i32 0, i32 2
  %59 = getelementptr inbounds [4 x double], ptr %58, i64 0, i64 0
  store double %56, ptr %59, align 8, !tbaa !14
  %60 = load ptr, ptr %7, align 8, !tbaa !11
  %61 = getelementptr inbounds double, ptr %60, i64 1
  %62 = load double, ptr %61, align 8, !tbaa !14
  %63 = load ptr, ptr %12, align 8, !tbaa !11
  %64 = getelementptr inbounds %struct.BoneRequest, ptr %63, i32 0, i32 2
  %65 = getelementptr inbounds [4 x double], ptr %64, i64 0, i64 1
  store double %62, ptr %65, align 8, !tbaa !14
  %66 = load ptr, ptr %7, align 8, !tbaa !11
  %67 = getelementptr inbounds double, ptr %66, i64 2
  %68 = load double, ptr %67, align 8, !tbaa !14
  %69 = load ptr, ptr %12, align 8, !tbaa !11
  %70 = getelementptr inbounds %struct.BoneRequest, ptr %69, i32 0, i32 2
  %71 = getelementptr inbounds [4 x double], ptr %70, i64 0, i64 2
  store double %68, ptr %71, align 8, !tbaa !14
  %72 = load i8, ptr %8, align 1, !tbaa !13
  %73 = load ptr, ptr %12, align 8, !tbaa !11
  %74 = getelementptr inbounds %struct.BoneRequest, ptr %73, i32 0, i32 3
  store i8 %72, ptr %74, align 8, !tbaa !23
  %75 = load ptr, ptr %12, align 8, !tbaa !11
  %76 = getelementptr inbounds %struct.BoneRequest, ptr %75, i32 0, i32 4
  store ptr null, ptr %76, align 8, !tbaa !24
  %77 = load ptr, ptr %11, align 8, !tbaa !11
  %78 = load ptr, ptr %12, align 8, !tbaa !11
  call void @add_request(ptr noundef %77, ptr noundef %78)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %82

79:                                               ; preds = %30
  %80 = load ptr, ptr @stderr, align 8, !tbaa !11
  %81 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %80, ptr noundef @.str.3, ptr noundef @__FUNCTION__.wb_skin_set_bone_position) #6
  br label %82

82:                                               ; preds = %79, %47
  call void @wb_robot_flush_unlocked(ptr noundef @__FUNCTION__.wb_skin_set_bone_position)
  call void (...) @robot_mutex_unlock()
  store i32 0, ptr %10, align 4
  br label %83

83:                                               ; preds = %82, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  br label %84

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

86:                                               ; preds = %84, %84
  ret void

87:                                               ; preds = %84
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { "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 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 #5 = { nounwind allocsize(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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !10, i64 16}
!19 = !{!"", !12, i64 0, !12, i64 8, !10, i64 16, !12, i64 24, !12, i64 32, !12, i64 40}
!20 = !{!21, !10, i64 0}
!21 = !{!"BoneRequest", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 40, !12, i64 48}
!22 = !{!21, !10, i64 4}
!23 = !{!21, !7, i64 40}
!24 = !{!21, !12, i64 48}


; 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.2 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [38 x i8], align 1
@__FUNCTION__.wb_skin_set_bone_position = external hidden unnamed_addr constant [26 x i8], align 1

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

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @add_request(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @wb_robot_flush_unlocked(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @wb_skin_set_bone_position(i16 noundef zeroext %0, i32 noundef %1, ptr nocapture noundef readonly %2, i8 noundef signext %3) local_unnamed_addr #2 {
  %5 = load double, ptr %2, align 8, !tbaa !5
  %6 = fcmp uno double %5, 0.000000e+00
  br i1 %6, label %17, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = fcmp uno double %9, 0.000000e+00
  br i1 %10, label %17, label %11

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %2, i64 16
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = fcmp uno double %13, 0.000000e+00
  br i1 %14, label %17, label %15

15:                                               ; preds = %11
  tail call void (...) @robot_mutex_lock() #4
  %16 = tail call ptr @skin_get_struct(i16 noundef zeroext %0)
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %37, label %20

17:                                               ; preds = %11, %7, %4
  %18 = load ptr, ptr @stderr, align 8, !tbaa !9
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.4, ptr noundef nonnull @__FUNCTION__.wb_skin_set_bone_position) #5
  br label %41

20:                                               ; preds = %15
  %21 = icmp slt i32 %1, 0
  br i1 %21, label %25, label %22

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %16, i64 16
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %.not24 = icmp sgt i32 %24, %1
  br i1 %.not24, label %28, label %25

25:                                               ; preds = %22, %20
  %26 = load ptr, ptr @stderr, align 8, !tbaa !9
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str.2, ptr noundef nonnull @__FUNCTION__.wb_skin_set_bone_position) #5
  tail call void (...) @robot_mutex_unlock() #4
  br label %41

28:                                               ; preds = %22
  %29 = tail call noalias dereferenceable_or_null(56) ptr @malloc(i64 noundef 56) #6
  store i32 2, ptr %29, align 8, !tbaa !14
  %30 = getelementptr inbounds i8, ptr %29, i64 4
  store i32 %1, ptr %30, align 4, !tbaa !16
  %31 = getelementptr inbounds i8, ptr %29, i64 8
  %32 = load <2 x double>, ptr %2, align 8, !tbaa !5
  store <2 x double> %32, ptr %31, align 8, !tbaa !5
  %33 = load double, ptr %12, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %29, i64 24
  store double %33, ptr %34, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %29, i64 40
  store i8 %3, ptr %35, align 8, !tbaa !17
  %36 = getelementptr inbounds i8, ptr %29, i64 48
  store ptr null, ptr %36, align 8, !tbaa !18
  tail call void @add_request(ptr noundef nonnull %16, ptr noundef nonnull %29)
  br label %40

37:                                               ; preds = %15
  %38 = load ptr, ptr @stderr, align 8, !tbaa !9
  %39 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef nonnull @.str.3, ptr noundef nonnull @__FUNCTION__.wb_skin_set_bone_position) #5
  br label %40

40:                                               ; preds = %37, %28
  tail call void @wb_robot_flush_unlocked(ptr noundef nonnull @__FUNCTION__.wb_skin_set_bone_position) #4
  tail call void (...) @robot_mutex_unlock() #4
  br label %41

41:                                               ; preds = %25, %40, %17
  ret void
}

attributes #0 = { 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 #1 = { "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 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 #3 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { cold nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 16}
!12 = !{!"", !10, i64 0, !10, i64 8, !13, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"BoneRequest", !13, i64 0, !13, i64 4, !7, i64 8, !7, i64 40, !10, i64 48}
!16 = !{!15, !13, i64 4}
!17 = !{!15, !7, i64 40}
!18 = !{!15, !10, i64 48}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass