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

@mAddress = external hidden global i32, align 4
@pcf8574_set.str = external hidden constant [31 x i8], align 4
@pcf8574_set.str.2 = external hidden constant [25 x i8], align 4

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

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

declare void @dhdebug_ram(ptr 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_write(i32 noundef, ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @pcf8574_set(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %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 i32 %2, ptr %7, align 4, !tbaa !5
  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_set.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 %7, align 4, !tbaa !5
  %29 = and i32 %28, 255
  %30 = trunc i32 %29 to i8
  store i8 %30, ptr %10, align 1, !tbaa !9
  %31 = load i32, ptr @mAddress, align 4, !tbaa !5
  %32 = call i32 @dh_i2c_write(i32 noundef %31, ptr noundef %10, i32 noundef 1, i32 noundef 1)
  store i32 %32, ptr %8, align 4, !tbaa !5
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %39

34:                                               ; preds = %27
  br label %35

35:                                               ; preds = %34
  call void (ptr, ...) @dhdebug_ram(ptr noundef @pcf8574_set.str.2)
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %38, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %40

39:                                               ; preds = %27
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %40

40:                                               ; preds = %39, %37
  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
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!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"

@mAddress = external hidden local_unnamed_addr global i32, align 4
@pcf8574_set.str = external hidden constant [31 x i8], align 4
@pcf8574_set.str.2 = external hidden constant [25 x i8], align 4

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

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

declare void @dhdebug_ram(ptr 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_write(i32 noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @pcf8574_set(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %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_set.str) #3
  br label %16

10:                                               ; preds = %7, %3
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  %11 = trunc i32 %2 to i8
  store i8 %11, ptr %4, align 1, !tbaa !5
  %12 = load i32, ptr @mAddress, align 4, !tbaa !8
  %13 = call i32 @dh_i2c_write(i32 noundef %12, ptr noundef nonnull %4, i32 noundef 1, i32 noundef 1) #3
  %.not13 = icmp eq i32 %13, 0
  br i1 %.not13, label %15, label %14

14:                                               ; preds = %10
  call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @pcf8574_set.str.2) #3
  br label %15

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

16:                                               ; preds = %15, %9
  %.1 = phi i32 [ %8, %9 ], [ %13, %15 ]
  ret i32 %.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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


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