; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources/commands (ina219_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.COMMAND_RESULT = type { ptr, %union.CommandResultArgument }
%union.CommandResultArgument = type { ptr }

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

; Function Attrs: nounwind uwtable
define dso_local void @dh_handle_devices_ina219_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 i32, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  %16 = alloca float, align 4
  %17 = alloca i32, align 4
  %18 = 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
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %60

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

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

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

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

37:                                               ; preds = %34, %30
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = and i32 %38, 33554432
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %56

41:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %42 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 28
  %43 = load float, ptr %42, align 4, !tbaa !15
  %44 = call i32 @ina219_set_shunt(float noundef %43)
  store i32 %44, ptr %13, align 4, !tbaa !9
  %45 = load i32, ptr %13, align 4, !tbaa !9
  %46 = call ptr @dh_i2c_error_string(i32 noundef %45)
  store ptr %46, ptr %11, align 8, !tbaa !5
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %52

49:                                               ; preds = %41
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %50, ptr noundef %51)
  store i32 1, ptr %12, align 4
  br label %53

52:                                               ; preds = %41
  store i32 0, ptr %12, align 4
  br label %53

53:                                               ; preds = %52, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  %54 = load i32, ptr %12, align 4
  switch i32 %54, label %57 [
    i32 0, label %55
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55, %37
  store i32 0, ptr %12, align 4
  br label %57

57:                                               ; preds = %56, %53, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %58 = load i32, ptr %12, align 4
  switch i32 %58, label %92 [
    i32 0, label %59
  ]

59:                                               ; preds = %57
  br label %60

60:                                               ; preds = %59, %4
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = or i32 %61, 524288
  store i32 %62, ptr %10, align 4, !tbaa !9
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load i32, ptr %10, align 4, !tbaa !9
  %65 = call i32 @dh_i2c_init_helper(ptr noundef %63, i32 noundef %64, ptr noundef %9)
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %60
  store i32 1, ptr %12, align 4
  br label %92

68:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 4, 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %69 = call i32 @ina219_read(i32 noundef -1, i32 noundef -1, ptr noundef %14, ptr noundef %15, ptr noundef %16)
  store i32 %69, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %70 = load i32, ptr %17, align 4, !tbaa !9
  %71 = call ptr @dh_i2c_error_string(i32 noundef %70)
  store ptr %71, ptr %18, align 8, !tbaa !5
  %72 = load ptr, ptr %18, align 8, !tbaa !5
  %73 = icmp ne ptr %72, null
  br i1 %73, label %74, label %77

74:                                               ; preds = %68
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = load ptr, ptr %18, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %75, ptr noundef %76)
  br label %91

77:                                               ; preds = %68
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.COMMAND_RESULT, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !16
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.COMMAND_RESULT, ptr %81, i32 0, i32 1
  %83 = load float, ptr %14, align 4, !tbaa !18
  %84 = fpext float %83 to double
  %85 = load float, ptr %15, align 4, !tbaa !18
  %86 = fpext float %85 to double
  %87 = load float, ptr %16, align 4, !tbaa !18
  %88 = fpext float %87 to double
  %89 = getelementptr inbounds %union.CommandResultArgument, ptr %82, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8
  call void (ptr, i32, i32, ...) %80(ptr %90, i32 noundef 1, i32 noundef 5, ptr noundef @.str, double noundef %84, double noundef %86, double noundef %88)
  br label %91

91:                                               ; preds = %77, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, 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 4, ptr %14) #3
  store i32 0, ptr %12, align 4
  br label %92

92:                                               ; preds = %91, %67, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 408, ptr %9) #3
  %93 = load i32, ptr %12, align 4
  switch i32 %93, label %95 [
    i32 0, label %94
    i32 1, label %94
  ]

94:                                               ; preds = %92, %92
  ret void

95:                                               ; preds = %92
  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 @ina219_set_address(i32 noundef) #2

declare i32 @ina219_set_shunt(float noundef) #2

declare ptr @dh_i2c_error_string(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 @ina219_read(i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr 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 = !{!12, !14, i64 404}
!16 = !{!17, !6, i64 0}
!17 = !{!"", !6, i64 0, !7, i64 8}
!18 = !{!14, !14, i64 0}


; 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] }

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

; Function Attrs: nounwind uwtable
define dso_local void @dh_handle_devices_ina219_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 float, align 4
  %8 = alloca float, 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 %.critedge, 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 37224448, ptr noundef nonnull %6) #3
  %.not23 = icmp eq ptr %11, null
  br i1 %.not23, label %13, label %12

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

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

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

19:                                               ; preds = %16, %13
  %20 = phi i32 [ %.pre, %16 ], [ %14, %13 ]
  %21 = and i32 %20, 33554432
  %.not25 = icmp eq i32 %21, 0
  br i1 %.not25, label %.critedge, label %22

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %5, i64 404
  %24 = load float, ptr %23, align 4, !tbaa !13
  %25 = call i32 @ina219_set_shunt(float noundef %24) #3
  %26 = call ptr @dh_i2c_error_string(i32 noundef %25) #3
  %.not26 = icmp eq ptr %26, null
  br i1 %.not26, label %..critedge_crit_edge, label %27

..critedge_crit_edge:                             ; preds = %22
  %.pre31 = load i32, ptr %6, align 4, !tbaa !5
  br label %.critedge

27:                                               ; preds = %22
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull %26) #3
  br label %.critedge30

.critedge:                                        ; preds = %..critedge_crit_edge, %19, %4
  %28 = phi i32 [ %.pre31, %..critedge_crit_edge ], [ %20, %19 ], [ 0, %4 ]
  %29 = or i32 %28, 524288
  store i32 %29, ptr %6, align 4, !tbaa !5
  %30 = call i32 @dh_i2c_init_helper(ptr noundef %0, i32 noundef %29, ptr noundef nonnull %5) #3
  %.not27 = icmp eq i32 %30, 0
  br i1 %.not27, label %31, label %.critedge30

31:                                               ; preds = %.critedge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #3
  %32 = call i32 @ina219_read(i32 noundef -1, i32 noundef -1, ptr noundef nonnull %7, ptr noundef nonnull %8, ptr noundef nonnull %9) #3
  %33 = call ptr @dh_i2c_error_string(i32 noundef %32) #3
  %.not28 = icmp eq ptr %33, null
  br i1 %.not28, label %35, label %34

34:                                               ; preds = %31
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull %33) #3
  br label %45

35:                                               ; preds = %31
  %36 = load ptr, ptr %0, align 8, !tbaa !14
  %37 = getelementptr inbounds i8, ptr %0, i64 8
  %38 = load float, ptr %7, align 4, !tbaa !17
  %39 = fpext float %38 to double
  %40 = load float, ptr %8, align 4, !tbaa !17
  %41 = fpext float %40 to double
  %42 = load float, ptr %9, align 4, !tbaa !17
  %43 = fpext float %42 to double
  %44 = load ptr, ptr %37, align 8
  call void (ptr, i32, i32, ...) %36(ptr %44, i32 noundef 1, i32 noundef 5, ptr noundef nonnull @.str, double noundef %39, double noundef %41, double noundef %43) #3
  br label %45

45:                                               ; preds = %35, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  br label %.critedge30

.critedge30:                                      ; preds = %27, %12, %.critedge, %45
  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 @ina219_set_address(i32 noundef) local_unnamed_addr #2

declare i32 @ina219_set_shunt(float noundef) local_unnamed_addr #2

declare ptr @dh_i2c_error_string(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 @ina219_read(i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr 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 = !{!10, !12, i64 404}
!14 = !{!15, !16, i64 0}
!15 = !{!"", !16, i64 0, !7, i64 8}
!16 = !{!"any pointer", !7, i64 0}
!17 = !{!12, !12, i64 0}


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