; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources/commands (mpu6050_cmd)

; 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.gpio_command_params = type { i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i32, i32, %union.anon, i16, i32, i8, i8, i8, [264 x i8], i32, i32, i32, i32, i32, i32, i32, i32, float }
%union.anon = type { [16 x i32] }
%struct.MPU6050_XYZ = type { float, float, float }
%struct.COMMAND_RESULT = type { ptr, %union.CommandResultArgument }
%union.CommandResultArgument = type { ptr }

@.str = external hidden unnamed_addr constant [97 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @dh_handle_devices_mpu6050_read(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.gpio_command_params, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca %struct.MPU6050_XYZ, align 4
  %14 = alloca %struct.MPU6050_XYZ, align 4
  %15 = alloca float, align 4
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 408, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %40

20:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = call ptr @parse_params_pins_set(ptr noundef %21, i32 noundef %22, ptr noundef %9, i32 noundef 1, i32 noundef 0, i32 noundef 3670016, ptr noundef %10)
  store ptr %23, ptr %11, align 8, !tbaa !5
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %29

26:                                               ; preds = %20
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %27, ptr noundef %28)
  store i32 1, ptr %12, align 4
  br label %37

29:                                               ; preds = %20
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = and i32 %30, 524288
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %36

33:                                               ; preds = %29
  %34 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 22
  %35 = load i32, ptr %34, align 4, !tbaa !11
  call void @mpu6050_set_address(i32 noundef %35)
  br label %36

36:                                               ; preds = %33, %29
  store i32 0, ptr %12, align 4
  br label %37

37:                                               ; preds = %36, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %38 = load i32, ptr %12, align 4
  switch i32 %38, label %86 [
    i32 0, label %39
  ]

39:                                               ; preds = %37
  br label %40

40:                                               ; preds = %39, %4
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = or i32 %41, 524288
  store i32 %42, ptr %10, align 4, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = call i32 @dh_i2c_init_helper(ptr noundef %43, i32 noundef %44, ptr noundef %9)
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %40
  store i32 1, ptr %12, align 4
  br label %86

48:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 12, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 12, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %49 = call i32 @mpu6050_read(i32 noundef -1, i32 noundef -1, ptr noundef %13, ptr noundef %14, ptr noundef %15)
  store i32 %49, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %50 = load i32, ptr %16, align 4, !tbaa !9
  %51 = call ptr @dh_i2c_error_string(i32 noundef %50)
  store ptr %51, ptr %17, align 8, !tbaa !5
  %52 = load ptr, ptr %17, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %57

54:                                               ; preds = %48
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %17, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %55, ptr noundef %56)
  br label %85

57:                                               ; preds = %48
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.COMMAND_RESULT, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.COMMAND_RESULT, ptr %61, i32 0, i32 1
  %63 = load float, ptr %15, align 4, !tbaa !17
  %64 = fpext float %63 to double
  %65 = getelementptr inbounds %struct.MPU6050_XYZ, ptr %13, i32 0, i32 0
  %66 = load float, ptr %65, align 4, !tbaa !18
  %67 = fpext float %66 to double
  %68 = getelementptr inbounds %struct.MPU6050_XYZ, ptr %13, i32 0, i32 1
  %69 = load float, ptr %68, align 4, !tbaa !20
  %70 = fpext float %69 to double
  %71 = getelementptr inbounds %struct.MPU6050_XYZ, ptr %13, i32 0, i32 2
  %72 = load float, ptr %71, align 4, !tbaa !21
  %73 = fpext float %72 to double
  %74 = getelementptr inbounds %struct.MPU6050_XYZ, ptr %14, i32 0, i32 0
  %75 = load float, ptr %74, align 4, !tbaa !18
  %76 = fpext float %75 to double
  %77 = getelementptr inbounds %struct.MPU6050_XYZ, ptr %14, i32 0, i32 1
  %78 = load float, ptr %77, align 4, !tbaa !20
  %79 = fpext float %78 to double
  %80 = getelementptr inbounds %struct.MPU6050_XYZ, ptr %14, i32 0, i32 2
  %81 = load float, ptr %80, align 4, !tbaa !21
  %82 = fpext float %81 to double
  %83 = getelementptr inbounds %union.CommandResultArgument, ptr %62, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8
  call void (ptr, i32, i32, ...) %60(ptr %84, i32 noundef 1, i32 noundef 5, ptr noundef @.str, double noundef %64, double noundef %67, double noundef %70, double noundef %73, double noundef %76, double noundef %79, double noundef %82)
  br label %85

85:                                               ; preds = %57, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %13) #3
  store i32 0, ptr %12, align 4
  br label %86

86:                                               ; preds = %85, %47, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 408, ptr %9) #3
  %87 = load i32, ptr %12, align 4
  switch i32 %87, label %89 [
    i32 0, label %88
    i32 1, label %88
  ]

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

89:                                               ; preds = %86
  unreachable
}

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

declare ptr @parse_params_pins_set(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #2

declare void @dh_command_fail(ptr noundef, ptr noundef) #2

declare void @mpu6050_set_address(i32 noundef) #2

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

declare i32 @dh_i2c_init_helper(ptr noundef, i32 noundef, ptr noundef) #2

declare i32 @mpu6050_read(i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @dh_i2c_error_string(i32 noundef) #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 = { 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 = !{!"any pointer", !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, !10, i64 380}
!12 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !13, i64 8, !13, i64 10, !13, i64 12, !13, i64 14, !13, i64 16, !13, i64 18, !13, i64 20, !10, i64 24, !10, i64 28, !7, i64 32, !13, i64 96, !10, i64 100, !7, i64 104, !7, i64 105, !7, i64 106, !7, i64 107, !10, i64 372, !10, i64 376, !10, i64 380, !10, i64 384, !10, i64 388, !10, i64 392, !10, i64 396, !10, i64 400, !14, i64 404}
!13 = !{!"short", !7, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"", !6, i64 0, !7, i64 8}
!17 = !{!14, !14, i64 0}
!18 = !{!19, !14, i64 0}
!19 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8}
!20 = !{!19, !14, i64 4}
!21 = !{!19, !14, i64 8}


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

%struct.gpio_command_params = type { i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i32, i32, %union.anon, i16, i32, i8, i8, i8, [264 x i8], i32, i32, i32, i32, i32, i32, i32, i32, float }
%union.anon = type { [16 x i32] }
%struct.MPU6050_XYZ = type { float, float, float }

@.str = external hidden unnamed_addr constant [97 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @dh_handle_devices_mpu6050_read(ptr noundef %0, ptr nocapture noundef readnone %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.gpio_command_params, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.MPU6050_XYZ, align 4
  %8 = alloca %struct.MPU6050_XYZ, align 4
  %9 = alloca float, align 4
  call void @llvm.lifetime.start.p0(i64 408, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.thread, label %10

10:                                               ; preds = %4
  %11 = call ptr @parse_params_pins_set(ptr noundef %2, i32 noundef %3, ptr noundef nonnull %5, i32 noundef 1, i32 noundef 0, i32 noundef 3670016, ptr noundef nonnull %6) #3
  %.not16 = icmp eq ptr %11, null
  br i1 %.not16, label %12, label %18

12:                                               ; preds = %10
  %13 = load i32, ptr %6, align 4, !tbaa !5
  %14 = and i32 %13, 524288
  %.not17 = icmp eq i32 %14, 0
  br i1 %.not17, label %.thread, label %15

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %5, i64 380
  %17 = load i32, ptr %16, align 4, !tbaa !9
  call void @mpu6050_set_address(i32 noundef %17) #3
  %.pre = load i32, ptr %6, align 4, !tbaa !5
  br label %.thread

18:                                               ; preds = %10
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull %11) #3
  br label %49

.thread:                                          ; preds = %15, %12, %4
  %19 = phi i32 [ %.pre, %15 ], [ %13, %12 ], [ 0, %4 ]
  %20 = or i32 %19, 524288
  store i32 %20, ptr %6, align 4, !tbaa !5
  %21 = call i32 @dh_i2c_init_helper(ptr noundef %0, i32 noundef %20, ptr noundef nonnull %5) #3
  %.not18 = icmp eq i32 %21, 0
  br i1 %.not18, label %22, label %49

22:                                               ; preds = %.thread
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #3
  %23 = call i32 @mpu6050_read(i32 noundef -1, i32 noundef -1, ptr noundef nonnull %7, ptr noundef nonnull %8, ptr noundef nonnull %9) #3
  %24 = call ptr @dh_i2c_error_string(i32 noundef %23) #3
  %.not19 = icmp eq ptr %24, null
  br i1 %.not19, label %26, label %25

25:                                               ; preds = %22
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull %24) #3
  br label %48

26:                                               ; preds = %22
  %27 = load ptr, ptr %0, align 8, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  %29 = load float, ptr %9, align 4, !tbaa !16
  %30 = fpext float %29 to double
  %31 = load float, ptr %7, align 4, !tbaa !17
  %32 = fpext float %31 to double
  %33 = getelementptr inbounds i8, ptr %7, i64 4
  %34 = load float, ptr %33, align 4, !tbaa !19
  %35 = fpext float %34 to double
  %36 = getelementptr inbounds i8, ptr %7, i64 8
  %37 = load float, ptr %36, align 4, !tbaa !20
  %38 = fpext float %37 to double
  %39 = load float, ptr %8, align 4, !tbaa !17
  %40 = fpext float %39 to double
  %41 = getelementptr inbounds i8, ptr %8, i64 4
  %42 = load float, ptr %41, align 4, !tbaa !19
  %43 = fpext float %42 to double
  %44 = getelementptr inbounds i8, ptr %8, i64 8
  %45 = load float, ptr %44, align 4, !tbaa !20
  %46 = fpext float %45 to double
  %47 = load ptr, ptr %28, align 8
  call void (ptr, i32, i32, ...) %27(ptr %47, i32 noundef 1, i32 noundef 5, ptr noundef nonnull @.str, double noundef %30, double noundef %32, double noundef %35, double noundef %38, double noundef %40, double noundef %43, double noundef %46) #3
  br label %48

48:                                               ; preds = %26, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %7) #3
  br label %49

49:                                               ; preds = %18, %.thread, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 408, ptr nonnull %5) #3
  ret void
}

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

declare ptr @parse_params_pins_set(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare void @dh_command_fail(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @mpu6050_set_address(i32 noundef) local_unnamed_addr #2

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

declare i32 @dh_i2c_init_helper(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @mpu6050_read(i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @dh_i2c_error_string(i32 noundef) 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 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"}
!9 = !{!10, !6, i64 380}
!10 = !{!"", !11, i64 0, !11, i64 2, !11, i64 4, !11, i64 6, !11, i64 8, !11, i64 10, !11, i64 12, !11, i64 14, !11, i64 16, !11, i64 18, !11, i64 20, !6, i64 24, !6, i64 28, !7, i64 32, !11, i64 96, !6, i64 100, !7, i64 104, !7, i64 105, !7, i64 106, !7, i64 107, !6, i64 372, !6, i64 376, !6, i64 380, !6, i64 384, !6, i64 388, !6, i64 392, !6, i64 396, !6, i64 400, !12, i64 404}
!11 = !{!"short", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"", !15, i64 0, !7, i64 8}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!12, !12, i64 0}
!17 = !{!18, !12, i64 0}
!18 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!19 = !{!18, !12, i64 4}
!20 = !{!18, !12, i64 8}


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