; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources/devices (pcf8574)

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

@pcf8574_read.str = external hidden constant [31 x i8], align 4
@mAddress = external hidden global i32, align 4
@pcf8574_read.str.1 = external hidden constant [24 x i8], align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @pcf8574_read(i32 noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = icmp ne i32 %11, -1
  br i1 %12, label %13, label %27

13:                                               ; preds = %3
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = icmp ne i32 %14, -1
  br i1 %15, label %16, label %27

16:                                               ; preds = %13
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = call i32 @dh_i2c_init(i32 noundef %17, i32 noundef %18)
  store i32 %19, ptr %8, align 4, !tbaa !5
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %26

21:                                               ; preds = %16
  br label %22

22:                                               ; preds = %21
  call void (ptr, ...) @dhdebug_ram(ptr noundef @pcf8574_read.str)
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %25, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %41

26:                                               ; preds = %16
  br label %27

27:                                               ; preds = %26, %13, %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %28 = load i32, ptr @mAddress, align 4, !tbaa !5
  %29 = call i32 @dh_i2c_read(i32 noundef %28, ptr noundef %10, i32 noundef 1)
  store i32 %29, ptr %8, align 4, !tbaa !5
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %36

31:                                               ; preds = %27
  br label %32

32:                                               ; preds = %31
  call void (ptr, ...) @dhdebug_ram(ptr noundef @pcf8574_read.str.1)
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %35, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %40

36:                                               ; preds = %27
  %37 = load i8, ptr %10, align 1, !tbaa !11
  %38 = zext i8 %37 to i32
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %38, ptr %39, align 4, !tbaa !5
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %40

40:                                               ; preds = %36, %34
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  br label %41

41:                                               ; preds = %40, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %42 = load i32, ptr %4, align 4
  ret i32 %42
}

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

declare i32 @dh_i2c_init(i32 noundef, i32 noundef) #2

declare void @dhdebug_ram(ptr noundef, ...) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, 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"

@pcf8574_read.str = external hidden constant [31 x i8], align 4
@mAddress = external hidden local_unnamed_addr global i32, align 4
@pcf8574_read.str.1 = external hidden constant [24 x i8], align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @pcf8574_read(i32 noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = alloca i8, align 1
  %5 = icmp ne i32 %0, -1
  %6 = icmp ne i32 %1, -1
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %7, label %10

7:                                                ; preds = %3
  %8 = tail call i32 @dh_i2c_init(i32 noundef %0, i32 noundef %1) #3
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %10, label %9

9:                                                ; preds = %7
  tail call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @pcf8574_read.str) #3
  br label %18

10:                                               ; preds = %7, %3
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  %11 = load i32, ptr @mAddress, align 4, !tbaa !5
  %12 = call i32 @dh_i2c_read(i32 noundef %11, ptr noundef nonnull %4, i32 noundef 1) #3
  %.not12 = icmp eq i32 %12, 0
  br i1 %.not12, label %14, label %13

13:                                               ; preds = %10
  call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @pcf8574_read.str.1) #3
  br label %17

14:                                               ; preds = %10
  %15 = load i8, ptr %4, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  store i32 %16, ptr %2, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %14, %13
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #3
  br label %18

18:                                               ; preds = %17, %9
  %.1 = phi i32 [ %8, %9 ], [ %12, %17 ]
  ret i32 %.1
}

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

declare i32 @dh_i2c_init(i32 noundef, i32 noundef) local_unnamed_addr #2

declare void @dhdebug_ram(ptr noundef, ...) local_unnamed_addr #2

declare i32 @dh_i2c_read(i32 noundef, ptr noundef, 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

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 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass