; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources/commands (i2c_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.2 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @dh_i2c_init_helper(ptr noundef, i32 noundef, ptr noundef) #0

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

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

declare ptr @dh_i2c_error_string(i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @dh_handle_i2c_master_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 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
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = call ptr @parse_params_pins_set(ptr noundef %15, i32 noundef %16, ptr noundef %9, i32 noundef 1, i32 noundef 0, i32 noundef 3739648, ptr noundef %10)
  store ptr %17, ptr %11, align 8, !tbaa !5
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %23

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

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

27:                                               ; preds = %23
  %28 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 12
  store i32 2, ptr %28, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %27, %23
  %30 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 12
  %31 = load i32, ptr %30, align 4, !tbaa !11
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %37, label %33

33:                                               ; preds = %29
  %34 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 12
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = icmp ugt i32 %35, 264
  br i1 %36, label %37, label %39

37:                                               ; preds = %33, %29
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %38, ptr noundef @.str.2)
  store i32 1, ptr %12, align 4
  br label %90

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

44:                                               ; preds = %39
  store i32 1, ptr %12, align 4
  br label %90

45:                                               ; preds = %39
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = and i32 %46, 65536
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %68

49:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %50 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 22
  %51 = load i32, ptr %50, align 4, !tbaa !15
  %52 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 19
  %53 = getelementptr inbounds [264 x i8], ptr %52, i64 0, i64 0
  %54 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 20
  %55 = load i32, ptr %54, align 4, !tbaa !16
  %56 = call i32 @dh_i2c_write(i32 noundef %51, ptr noundef %53, i32 noundef %55, i32 noundef 0)
  store i32 %56, ptr %13, align 4, !tbaa !9
  %57 = load i32, ptr %13, align 4, !tbaa !9
  %58 = call ptr @dh_i2c_error_string(i32 noundef %57)
  store ptr %58, ptr %11, align 8, !tbaa !5
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %64

61:                                               ; preds = %49
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %62, ptr noundef %63)
  store i32 1, ptr %12, align 4
  br label %65

64:                                               ; preds = %49
  store i32 0, ptr %12, align 4
  br label %65

65:                                               ; preds = %64, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  %66 = load i32, ptr %12, align 4
  switch i32 %66, label %90 [
    i32 0, label %67
  ]

67:                                               ; preds = %65
  br label %68

68:                                               ; preds = %67, %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %69 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 22
  %70 = load i32, ptr %69, align 4, !tbaa !15
  %71 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 19
  %72 = getelementptr inbounds [264 x i8], ptr %71, i64 0, i64 0
  %73 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 12
  %74 = load i32, ptr %73, align 4, !tbaa !11
  %75 = call i32 @dh_i2c_read(i32 noundef %70, ptr noundef %72, i32 noundef %74)
  store i32 %75, ptr %14, align 4, !tbaa !9
  %76 = load i32, ptr %14, align 4, !tbaa !9
  %77 = call ptr @dh_i2c_error_string(i32 noundef %76)
  store ptr %77, ptr %11, align 8, !tbaa !5
  %78 = load ptr, ptr %11, align 8, !tbaa !5
  %79 = icmp ne ptr %78, null
  br i1 %79, label %80, label %83

80:                                               ; preds = %68
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load ptr, ptr %11, align 8, !tbaa !5
  call void @dh_command_fail(ptr noundef %81, ptr noundef %82)
  br label %89

83:                                               ; preds = %68
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 19
  %86 = getelementptr inbounds [264 x i8], ptr %85, i64 0, i64 0
  %87 = getelementptr inbounds %struct.gpio_command_params, ptr %9, i32 0, i32 12
  %88 = load i32, ptr %87, align 4, !tbaa !11
  call void @dh_command_done_buf(ptr noundef %84, ptr noundef %86, i32 noundef %88)
  br label %89

89:                                               ; preds = %83, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  store i32 0, ptr %12, align 4
  br label %90

90:                                               ; preds = %89, %65, %44, %37, %20
  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
  %91 = load i32, ptr %12, align 4
  switch i32 %91, label %93 [
    i32 0, label %92
    i32 1, label %92
  ]

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

93:                                               ; preds = %90
  unreachable
}

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

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

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

declare void @dh_command_done_buf(ptr noundef, ptr noundef, i32 noundef) #1

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 28}
!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, !10, i64 380}
!16 = !{!12, !10, i64 372}


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

; Function Attrs: nounwind uwtable
declare dso_local i32 @dh_i2c_init_helper(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

declare ptr @dh_i2c_error_string(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) #2

; Function Attrs: nounwind uwtable
define dso_local void @dh_handle_i2c_master_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
  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 1, i32 noundef 0, i32 noundef 3739648, 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 %43

9:                                                ; preds = %4
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = and i32 %10, 4096
  %.not21 = icmp eq i32 %11, 0
  %12 = getelementptr inbounds i8, ptr %5, i64 28
  br i1 %.not21, label %.thread, label %14

.thread:                                          ; preds = %9
  store i32 2, ptr %12, align 4, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %5, i64 28
  br label %19

14:                                               ; preds = %9
  %.pre = load i32, ptr %12, align 4
  %15 = add i32 %.pre, -265
  %16 = icmp ult i32 %15, -264
  %17 = getelementptr inbounds i8, ptr %5, i64 28
  br i1 %16, label %18, label %19

18:                                               ; preds = %14
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull @.str.2) #3
  br label %43

19:                                               ; preds = %.thread, %14
  %20 = phi ptr [ %13, %.thread ], [ %17, %14 ]
  %21 = call i32 @dh_i2c_init_helper(ptr noundef %0, i32 noundef %10, ptr noundef nonnull %5)
  %.not22 = icmp eq i32 %21, 0
  br i1 %.not22, label %22, label %43

22:                                               ; preds = %19
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = and i32 %23, 65536
  %.not23 = icmp eq i32 %24, 0
  br i1 %.not23, label %.critedge, label %25

25:                                               ; preds = %22
  %26 = getelementptr inbounds i8, ptr %5, i64 380
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %5, i64 107
  %29 = getelementptr inbounds i8, ptr %5, i64 372
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %31 = call i32 @dh_i2c_write(i32 noundef %27, ptr noundef nonnull %28, i32 noundef %30, i32 noundef 0) #3
  %32 = call ptr @dh_i2c_error_string(i32 noundef %31) #3
  %.not24 = icmp eq ptr %32, null
  br i1 %.not24, label %.critedge, label %33

33:                                               ; preds = %25
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull %32) #3
  br label %43

.critedge:                                        ; preds = %25, %22
  %34 = getelementptr inbounds i8, ptr %5, i64 380
  %35 = load i32, ptr %34, align 4, !tbaa !13
  %36 = getelementptr inbounds i8, ptr %5, i64 107
  %37 = load i32, ptr %20, align 4, !tbaa !9
  %38 = call i32 @dh_i2c_read(i32 noundef %35, ptr noundef nonnull %36, i32 noundef %37) #3
  %39 = call ptr @dh_i2c_error_string(i32 noundef %38) #3
  %.not25 = icmp eq ptr %39, null
  br i1 %.not25, label %41, label %40

40:                                               ; preds = %.critedge
  call void @dh_command_fail(ptr noundef %0, ptr noundef nonnull %39) #3
  br label %43

41:                                               ; preds = %.critedge
  %42 = load i32, ptr %20, align 4, !tbaa !9
  call void @dh_command_done_buf(ptr noundef %0, ptr noundef nonnull %36, i32 noundef %42) #3
  br label %43

43:                                               ; preds = %33, %40, %41, %19, %18, %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 ptr @parse_params_pins_set(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

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

declare void @dh_command_done_buf(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 28}
!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, !6, i64 380}
!14 = !{!10, !6, i64 372}


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