; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources/commands (pcf8574_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] }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [1 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

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

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

declare void @pcf8574_set_address(i32 noundef) #1

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

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

declare i32 @pcf8574_write(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

declare ptr @dh_i2c_error_string(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @dh_handle_devices_pcf8574_write(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %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
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = call ptr @parse_params_pins_set(ptr noundef %14, i32 noundef %15, ptr noundef %9, i32 noundef 255, i32 noundef 0, i32 noundef 3670019, ptr noundef %10)
  store ptr %16, ptr %11, align 8, !tbaa !5
  %17 = load ptr, ptr %11, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %22

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

22:                                               ; preds = %4
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = and i32 %23, 3
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %28, label %26

26:                                               ; preds = %22
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %27, ptr noundef @.str)
  store i32 1, ptr %12, align 4
  br label %75

28:                                               ; preds = %22
  %29 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 0
  %30 = load i16, ptr %29, align 4, !tbaa !11
  %31 = zext i16 %30 to i32
  %32 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 1
  %33 = load i16, ptr %32, align 2, !tbaa !15
  %34 = zext i16 %33 to i32
  %35 = or i32 %31, %34
  %36 = and i32 %35, -256
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %28
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %39, ptr noundef @.str.1)
  store i32 1, ptr %12, align 4
  br label %75

40:                                               ; preds = %28
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = and i32 %43, 524288
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %49

46:                                               ; preds = %42
  %47 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 22
  %48 = load i32, ptr %47, align 4, !tbaa !16
  call void @pcf8574_set_address(i32 noundef %48)
  br label %49

49:                                               ; preds = %46, %42
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = or i32 %50, 524288
  store i32 %51, ptr %10, align 4, !tbaa !9
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = call i32 @dh_i2c_init_helper(ptr noundef %52, i32 noundef %53, ptr noundef %9)
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %49
  store i32 1, ptr %12, align 4
  br label %75

57:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %58 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 0
  %59 = load i16, ptr %58, align 4, !tbaa !11
  %60 = zext i16 %59 to i32
  %61 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 1
  %62 = load i16, ptr %61, align 2, !tbaa !15
  %63 = zext i16 %62 to i32
  %64 = call i32 @pcf8574_write(i32 noundef -1, i32 noundef -1, i32 noundef %60, i32 noundef %63)
  store i32 %64, ptr %13, align 4, !tbaa !9
  %65 = load i32, ptr %13, align 4, !tbaa !9
  %66 = call ptr @dh_i2c_error_string(i32 noundef %65)
  store ptr %66, ptr %11, align 8, !tbaa !5
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %72

69:                                               ; preds = %57
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %70, ptr noundef %71)
  br label %74

72:                                               ; preds = %57
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  call void @dh_command_done(ptr noundef %73, ptr noundef @.str.2)
  br label %74

74:                                               ; preds = %72, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  store i32 0, ptr %12, align 4
  br label %75

75:                                               ; preds = %74, %56, %38, %26, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 408, ptr %9) #3
  %76 = load i32, ptr %12, align 4
  switch i32 %76, label %78 [
    i32 0, label %77
    i32 1, label %77
  ]

77:                                               ; preds = %75, %75
  ret void

78:                                               ; preds = %75
  unreachable
}

declare void @dh_command_done(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !13, i64 0}
!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, !13, i64 2}
!16 = !{!12, !10, i64 380}


; 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 [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [1 x i8], align 1

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

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

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

declare void @pcf8574_set_address(i32 noundef) local_unnamed_addr #1

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

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

declare i32 @pcf8574_write(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare ptr @dh_i2c_error_string(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @dh_handle_devices_pcf8574_write(ptr noundef %0, ptr nocapture noundef readnone %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.gpio_command_params, align 4
  %6 = alloca i32, 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
  %7 = call ptr @parse_params_pins_set(ptr noundef %2, i32 noundef %3, ptr noundef nonnull %5, i32 noundef 255, i32 noundef 0, i32 noundef 3670019, ptr noundef nonnull %6) #3
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %9, label %8

8:                                                ; preds = %4
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull %7) #3
  br label %37

9:                                                ; preds = %4
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = and i32 %10, 3
  %.not13 = icmp eq i32 %11, 0
  br i1 %.not13, label %12, label %13

12:                                               ; preds = %9
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull @.str) #3
  br label %37

13:                                               ; preds = %9
  %14 = load i16, ptr %5, align 4, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %5, i64 2
  %16 = load i16, ptr %15, align 2, !tbaa !13
  %17 = or i16 %16, %14
  %.not14 = icmp ult i16 %17, 256
  br i1 %.not14, label %19, label %18

18:                                               ; preds = %13
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull @.str.1) #3
  br label %37

19:                                               ; preds = %13
  %20 = and i32 %10, 524288
  %.not15 = icmp eq i32 %20, 0
  br i1 %.not15, label %24, label %21

21:                                               ; preds = %19
  %22 = getelementptr inbounds i8, ptr %5, i64 380
  %23 = load i32, ptr %22, align 4, !tbaa !14
  call void @pcf8574_set_address(i32 noundef %23) #3
  %.pre = load i32, ptr %6, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %21, %19
  %25 = phi i32 [ %.pre, %21 ], [ %10, %19 ]
  %26 = or i32 %25, 524288
  store i32 %26, ptr %6, align 4, !tbaa !5
  %27 = call i32 @dh_i2c_init_helper(ptr noundef %0, i32 noundef %26, ptr noundef nonnull %5) #3
  %.not16 = icmp eq i32 %27, 0
  br i1 %.not16, label %28, label %37

28:                                               ; preds = %24
  %29 = load i16, ptr %5, align 4, !tbaa !9
  %30 = zext i16 %29 to i32
  %31 = load i16, ptr %15, align 2, !tbaa !13
  %32 = zext i16 %31 to i32
  %33 = call i32 @pcf8574_write(i32 noundef -1, i32 noundef -1, i32 noundef %30, i32 noundef %32) #3
  %34 = call ptr @dh_i2c_error_string(i32 noundef %33) #3
  %.not17 = icmp eq ptr %34, null
  br i1 %.not17, label %36, label %35

35:                                               ; preds = %28
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull %34) #3
  br label %37

36:                                               ; preds = %28
  call void @dh_command_done(ptr noundef %0, ptr noundef nonnull @.str.2) #3
  br label %37

37:                                               ; preds = %35, %36, %24, %18, %12, %8
  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
}

declare void @dh_command_done(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !11, i64 0}
!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, !11, i64 2}
!14 = !{!10, !6, i64 380}


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