; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources/commands (pcf8591_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 [33 x i8], align 1

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

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

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

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

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

35:                                               ; preds = %32, %28
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = and i32 %36, 33554432
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %54

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

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

50:                                               ; preds = %39
  store i32 0, ptr %12, align 4
  br label %51

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

53:                                               ; preds = %51
  br label %54

54:                                               ; preds = %53, %35
  store i32 0, ptr %12, align 4
  br label %55

55:                                               ; preds = %54, %51, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %56 = load i32, ptr %12, align 4
  switch i32 %56, label %97 [
    i32 0, label %57
  ]

57:                                               ; preds = %55
  br label %58

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

65:                                               ; preds = %58
  store i32 1, ptr %12, align 4
  br label %97

66:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %67 = getelementptr inbounds [4 x float], ptr %14, i64 0, i64 0
  %68 = call i32 @pcf8591_read(i32 noundef -1, i32 noundef -1, ptr noundef %67)
  store i32 %68, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %69 = load i32, ptr %15, align 4, !tbaa !9
  %70 = call ptr @dh_i2c_error_string(i32 noundef %69)
  store ptr %70, ptr %16, align 8, !tbaa !5
  %71 = load ptr, ptr %16, align 8, !tbaa !5
  %72 = icmp ne ptr %71, null
  br i1 %72, label %73, label %76

73:                                               ; preds = %66
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = load ptr, ptr %16, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %74, ptr noundef %75)
  br label %96

76:                                               ; preds = %66
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.COMMAND_RESULT, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !16
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.COMMAND_RESULT, ptr %80, i32 0, i32 1
  %82 = getelementptr inbounds [4 x float], ptr %14, i64 0, i64 0
  %83 = load float, ptr %82, align 16, !tbaa !18
  %84 = fpext float %83 to double
  %85 = getelementptr inbounds [4 x float], ptr %14, i64 0, i64 1
  %86 = load float, ptr %85, align 4, !tbaa !18
  %87 = fpext float %86 to double
  %88 = getelementptr inbounds [4 x float], ptr %14, i64 0, i64 2
  %89 = load float, ptr %88, align 8, !tbaa !18
  %90 = fpext float %89 to double
  %91 = getelementptr inbounds [4 x float], ptr %14, i64 0, i64 3
  %92 = load float, ptr %91, align 4, !tbaa !18
  %93 = fpext float %92 to double
  %94 = getelementptr inbounds %union.CommandResultArgument, ptr %81, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8
  call void (ptr, i32, i32, ...) %79(ptr %95, i32 noundef 1, i32 noundef 5, ptr noundef @.str, double noundef %84, double noundef %87, double noundef %90, double noundef %93)
  br label %96

96:                                               ; preds = %76, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #3
  store i32 0, ptr %12, align 4
  br label %97

97:                                               ; preds = %96, %65, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 408, ptr %9) #3
  %98 = load i32, ptr %12, align 4
  switch i32 %98, label %100 [
    i32 0, label %99
    i32 1, label %99
  ]

99:                                               ; preds = %97, %97
  ret void

100:                                              ; preds = %97
  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 @pcf8591_set_address(i32 noundef) #2

declare i32 @pcf8591_set_vref(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 @pcf8591_read(i32 noundef, i32 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 [33 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @dh_handle_devices_pcf8591_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 [4 x float], align 16
  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 %8

8:                                                ; preds = %4
  %9 = 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 %9, null
  br i1 %.not23, label %11, label %10

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

11:                                               ; preds = %8
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = and i32 %12, 524288
  %.not24 = icmp eq i32 %13, 0
  br i1 %.not24, label %17, label %14

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

17:                                               ; preds = %14, %11
  %18 = phi i32 [ %.pre, %14 ], [ %12, %11 ]
  %19 = and i32 %18, 33554432
  %.not25 = icmp eq i32 %19, 0
  br i1 %.not25, label %.critedge, label %20

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

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

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

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

29:                                               ; preds = %.critedge
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #3
  %30 = call i32 @pcf8591_read(i32 noundef -1, i32 noundef -1, ptr noundef nonnull %7) #3
  %31 = call ptr @dh_i2c_error_string(i32 noundef %30) #3
  %.not28 = icmp eq ptr %31, null
  br i1 %.not28, label %33, label %32

32:                                               ; preds = %29
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull %31) #3
  br label %48

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

48:                                               ; preds = %33, %32
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #3
  br label %.critedge30

.critedge30:                                      ; preds = %25, %10, %.critedge, %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 @pcf8591_set_address(i32 noundef) local_unnamed_addr #2

declare i32 @pcf8591_set_vref(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 @pcf8591_read(i32 noundef, i32 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