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

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

@si7021_read.str = external hidden constant [30 x i8], align 4
@mAddress = external hidden global i32, align 4
@si7021_read.str.1 = external hidden constant [37 x i8], align 4
@si7021_read.str.2 = external hidden constant [32 x i8], align 4
@si7021_read.str.3 = external hidden constant [40 x i8], align 4
@si7021_read.str.4 = external hidden constant [35 x i8], align 4

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

15:                                               ; preds = %4
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = icmp ne i32 %16, -1
  br i1 %17, label %18, label %29

18:                                               ; preds = %15
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = call i32 @dh_i2c_init(i32 noundef %19, i32 noundef %20)
  store i32 %21, ptr %10, align 4, !tbaa !5
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %18
  br label %24

24:                                               ; preds = %23
  call void (ptr, ...) @dhdebug_ram(ptr noundef @si7021_read.str)
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %27, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %91

28:                                               ; preds = %18
  br label %29

29:                                               ; preds = %28, %15, %4
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #4
  %30 = getelementptr inbounds [2 x i8], ptr %12, i64 0, i64 0
  store i8 -27, ptr %30, align 1, !tbaa !11
  %31 = load i32, ptr @mAddress, align 4, !tbaa !5
  %32 = getelementptr inbounds [2 x i8], ptr %12, i64 0, i64 0
  %33 = call i32 @dh_i2c_write(i32 noundef %31, ptr noundef %32, i32 noundef 1, i32 noundef 0)
  store i32 %33, ptr %10, align 4, !tbaa !5
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %40

35:                                               ; preds = %29
  br label %36

36:                                               ; preds = %35
  call void (ptr, ...) @dhdebug_ram(ptr noundef @si7021_read.str.1)
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %39, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %90

40:                                               ; preds = %29
  %41 = load i32, ptr @mAddress, align 4, !tbaa !5
  %42 = getelementptr inbounds [2 x i8], ptr %12, i64 0, i64 0
  %43 = call i32 @dh_i2c_read(i32 noundef %41, ptr noundef %42, i32 noundef 2)
  store i32 %43, ptr %10, align 4, !tbaa !5
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %50

45:                                               ; preds = %40
  br label %46

46:                                               ; preds = %45
  call void (ptr, ...) @dhdebug_ram(ptr noundef @si7021_read.str.2)
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %49, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %90

50:                                               ; preds = %40
  %51 = getelementptr inbounds [2 x i8], ptr %12, i64 0, i64 0
  %52 = call i32 @unsignedInt16be(ptr noundef %51, i32 noundef 0)
  %53 = uitofp i32 %52 to float
  %54 = fmul float %53, 1.250000e+02
  %55 = fdiv float %54, 6.553600e+04
  %56 = fsub float %55, 6.000000e+00
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  store float %56, ptr %57, align 4, !tbaa !12
  %58 = load ptr, ptr %9, align 8, !tbaa !9
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %89

60:                                               ; preds = %50
  %61 = getelementptr inbounds [2 x i8], ptr %12, i64 0, i64 0
  store i8 -32, ptr %61, align 1, !tbaa !11
  %62 = load i32, ptr @mAddress, align 4, !tbaa !5
  %63 = getelementptr inbounds [2 x i8], ptr %12, i64 0, i64 0
  %64 = call i32 @dh_i2c_write(i32 noundef %62, ptr noundef %63, i32 noundef 1, i32 noundef 0)
  store i32 %64, ptr %10, align 4, !tbaa !5
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %71

66:                                               ; preds = %60
  br label %67

67:                                               ; preds = %66
  call void (ptr, ...) @dhdebug_ram(ptr noundef @si7021_read.str.3)
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %70, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %90

71:                                               ; preds = %60
  %72 = load i32, ptr @mAddress, align 4, !tbaa !5
  %73 = getelementptr inbounds [2 x i8], ptr %12, i64 0, i64 0
  %74 = call i32 @dh_i2c_read(i32 noundef %72, ptr noundef %73, i32 noundef 2)
  store i32 %74, ptr %10, align 4, !tbaa !5
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %81

76:                                               ; preds = %71
  br label %77

77:                                               ; preds = %76
  call void (ptr, ...) @dhdebug_ram(ptr noundef @si7021_read.str.4)
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %80, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %90

81:                                               ; preds = %71
  %82 = getelementptr inbounds [2 x i8], ptr %12, i64 0, i64 0
  %83 = call i32 @unsignedInt16be(ptr noundef %82, i32 noundef 0)
  %84 = uitofp i32 %83 to float
  %85 = fmul float %84, 0x4065F70A40000000
  %86 = fdiv float %85, 6.553600e+04
  %87 = fsub float %86, 0x40476CCCC0000000
  %88 = load ptr, ptr %9, align 8, !tbaa !9
  store float %87, ptr %88, align 4, !tbaa !12
  br label %89

89:                                               ; preds = %81, %50
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %90

90:                                               ; preds = %89, %79, %69, %48, %38
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #4
  br label %91

91:                                               ; preds = %90, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %92 = load i32, ptr %5, align 4
  ret i32 %92
}

; 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_write(i32 noundef, ptr noundef, i32 noundef, i32 noundef) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @unsignedInt16be(ptr noundef, i32 noundef) #3

; 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 = { inlinehint 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 #4 = { 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}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !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"

@si7021_read.str = external hidden constant [30 x i8], align 4
@mAddress = external hidden local_unnamed_addr global i32, align 4
@si7021_read.str.1 = external hidden constant [37 x i8], align 4
@si7021_read.str.2 = external hidden constant [32 x i8], align 4
@si7021_read.str.3 = external hidden constant [40 x i8], align 4
@si7021_read.str.4 = external hidden constant [35 x i8], align 4

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

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

10:                                               ; preds = %8
  tail call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @si7021_read.str) #4
  br label %40

11:                                               ; preds = %8, %4
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %5) #4
  store i8 -27, ptr %5, 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 %5, i32 noundef 1, i32 noundef 0) #4
  %.not21 = icmp eq i32 %13, 0
  br i1 %.not21, label %15, label %14

14:                                               ; preds = %11
  call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @si7021_read.str.1) #4
  br label %39

15:                                               ; preds = %11
  %16 = load i32, ptr @mAddress, align 4, !tbaa !8
  %17 = call i32 @dh_i2c_read(i32 noundef %16, ptr noundef nonnull %5, i32 noundef 2) #4
  %.not22 = icmp eq i32 %17, 0
  br i1 %.not22, label %19, label %18

18:                                               ; preds = %15
  call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @si7021_read.str.2) #4
  br label %39

19:                                               ; preds = %15
  %20 = call i32 @unsignedInt16be(ptr noundef nonnull %5, i32 noundef 0)
  %21 = uitofp i32 %20 to float
  %22 = fmul float %21, 1.250000e+02
  %23 = fmul float %22, 0x3EF0000000000000
  %24 = fadd float %23, -6.000000e+00
  store float %24, ptr %2, align 4, !tbaa !10
  %.not23 = icmp eq ptr %3, null
  br i1 %.not23, label %39, label %25

25:                                               ; preds = %19
  store i8 -32, ptr %5, align 1, !tbaa !5
  %26 = load i32, ptr @mAddress, align 4, !tbaa !8
  %27 = call i32 @dh_i2c_write(i32 noundef %26, ptr noundef nonnull %5, i32 noundef 1, i32 noundef 0) #4
  %.not24 = icmp eq i32 %27, 0
  br i1 %.not24, label %29, label %28

28:                                               ; preds = %25
  call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @si7021_read.str.3) #4
  br label %39

29:                                               ; preds = %25
  %30 = load i32, ptr @mAddress, align 4, !tbaa !8
  %31 = call i32 @dh_i2c_read(i32 noundef %30, ptr noundef nonnull %5, i32 noundef 2) #4
  %.not25 = icmp eq i32 %31, 0
  br i1 %.not25, label %33, label %32

32:                                               ; preds = %29
  call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @si7021_read.str.4) #4
  br label %39

33:                                               ; preds = %29
  %34 = call i32 @unsignedInt16be(ptr noundef nonnull %5, i32 noundef 0)
  %35 = uitofp i32 %34 to float
  %36 = fmul float %35, 0x4065F70A40000000
  %37 = fmul float %36, 0x3EF0000000000000
  %38 = fadd float %37, 0xC0476CCCC0000000
  store float %38, ptr %3, align 4, !tbaa !10
  br label %39

39:                                               ; preds = %19, %33, %32, %28, %18, %14
  %.0 = phi i32 [ %13, %14 ], [ %17, %18 ], [ %27, %28 ], [ %31, %32 ], [ 0, %33 ], [ 0, %19 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %5) #4
  br label %40

40:                                               ; preds = %39, %10
  %.1 = phi i32 [ %9, %10 ], [ %.0, %39 ]
  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_write(i32 noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @unsignedInt16be(ptr noundef, i32 noundef) local_unnamed_addr #3

; 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 = { inlinehint 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 #4 = { 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}
!10 = !{!11, !11, i64 0}
!11 = !{!"float", !6, i64 0}


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