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

; 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.HMC5883L_XYZ = type { float, float, float }

@hmc5883l_read.str = external hidden constant [32 x i8], align 4
@mAddress = external hidden global i32, align 4
@hmc5883l_read.str.1 = external hidden constant [29 x i8], align 4
@hmc5883l_read.str.2 = external hidden constant [38 x i8], align 4
@hmc5883l_read.str.3 = external hidden constant [25 x i8], align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @hmc5883l_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 [7 x i8], align 1
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  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) #4
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp ne i32 %14, -1
  br i1 %15, label %16, label %30

16:                                               ; preds = %3
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = icmp ne i32 %17, -1
  br i1 %18, label %19, label %30

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

24:                                               ; preds = %19
  br label %25

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

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %28, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %107

29:                                               ; preds = %19
  br label %30

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

37:                                               ; preds = %30
  br label %38

38:                                               ; preds = %37
  call void (ptr, ...) @dhdebug_ram(ptr noundef @hmc5883l_read.str.1)
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %41, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %106

42:                                               ; preds = %30
  call void @delay_ms(i32 noundef 80)
  %43 = getelementptr inbounds [7 x i8], ptr %10, i64 0, i64 0
  store i8 3, ptr %43, align 1, !tbaa !11
  %44 = load i32, ptr @mAddress, align 4, !tbaa !5
  %45 = getelementptr inbounds [7 x i8], ptr %10, i64 0, i64 0
  %46 = call i32 @dh_i2c_write(i32 noundef %44, ptr noundef %45, i32 noundef 1, i32 noundef 0)
  store i32 %46, ptr %8, align 4, !tbaa !5
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %53

48:                                               ; preds = %42
  br label %49

49:                                               ; preds = %48
  call void (ptr, ...) @dhdebug_ram(ptr noundef @hmc5883l_read.str.2)
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %52, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %106

53:                                               ; preds = %42
  %54 = load i32, ptr @mAddress, align 4, !tbaa !5
  %55 = getelementptr inbounds [7 x i8], ptr %10, i64 0, i64 0
  %56 = call i32 @dh_i2c_read(i32 noundef %54, ptr noundef %55, i32 noundef 7)
  store i32 %56, ptr %8, align 4, !tbaa !5
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %63

58:                                               ; preds = %53
  br label %59

59:                                               ; preds = %58
  call void (ptr, ...) @dhdebug_ram(ptr noundef @hmc5883l_read.str.3)
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %62, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %106

63:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %64 = getelementptr inbounds [7 x i8], ptr %10, i64 0, i64 0
  %65 = call i32 @signedInt16be(ptr noundef %64, i32 noundef 0)
  store i32 %65, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %66 = getelementptr inbounds [7 x i8], ptr %10, i64 0, i64 0
  %67 = call i32 @signedInt16be(ptr noundef %66, i32 noundef 4)
  store i32 %67, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %68 = getelementptr inbounds [7 x i8], ptr %10, i64 0, i64 0
  %69 = call i32 @signedInt16be(ptr noundef %68, i32 noundef 2)
  store i32 %69, ptr %13, align 4, !tbaa !5
  %70 = load i32, ptr %11, align 4, !tbaa !5
  %71 = icmp eq i32 %70, -4096
  br i1 %71, label %72, label %73

72:                                               ; preds = %63
  br label %78

73:                                               ; preds = %63
  %74 = load i32, ptr %11, align 4, !tbaa !5
  %75 = sitofp i32 %74 to float
  %76 = fmul float %75, 0x3FF4CCCCC0000000
  %77 = fdiv float %76, 2.048000e+03
  br label %78

78:                                               ; preds = %73, %72
  %79 = phi float [ -1.000000e+08, %72 ], [ %77, %73 ]
  %80 = load ptr, ptr %7, align 8, !tbaa !9
  %81 = getelementptr inbounds %struct.HMC5883L_XYZ, ptr %80, i32 0, i32 0
  store float %79, ptr %81, align 4, !tbaa !12
  %82 = load i32, ptr %12, align 4, !tbaa !5
  %83 = icmp eq i32 %82, -4096
  br i1 %83, label %84, label %85

84:                                               ; preds = %78
  br label %90

85:                                               ; preds = %78
  %86 = load i32, ptr %12, align 4, !tbaa !5
  %87 = sitofp i32 %86 to float
  %88 = fmul float %87, 0x3FF4CCCCC0000000
  %89 = fdiv float %88, 2.048000e+03
  br label %90

90:                                               ; preds = %85, %84
  %91 = phi float [ -1.000000e+08, %84 ], [ %89, %85 ]
  %92 = load ptr, ptr %7, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.HMC5883L_XYZ, ptr %92, i32 0, i32 1
  store float %91, ptr %93, align 4, !tbaa !15
  %94 = load i32, ptr %13, align 4, !tbaa !5
  %95 = icmp eq i32 %94, -4096
  br i1 %95, label %96, label %97

96:                                               ; preds = %90
  br label %102

97:                                               ; preds = %90
  %98 = load i32, ptr %13, align 4, !tbaa !5
  %99 = sitofp i32 %98 to float
  %100 = fmul float %99, 0x3FF4CCCCC0000000
  %101 = fdiv float %100, 2.048000e+03
  br label %102

102:                                              ; preds = %97, %96
  %103 = phi float [ -1.000000e+08, %96 ], [ %101, %97 ]
  %104 = load ptr, ptr %7, align 8, !tbaa !9
  %105 = getelementptr inbounds %struct.HMC5883L_XYZ, ptr %104, i32 0, i32 2
  store float %103, ptr %105, align 4, !tbaa !16
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %106

106:                                              ; preds = %102, %61, %51, %40
  call void @llvm.lifetime.end.p0(i64 7, ptr %10) #4
  br label %107

107:                                              ; preds = %106, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %108 = load i32, ptr %4, align 4
  ret i32 %108
}

; 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 void @delay_ms(i32 noundef) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @signedInt16be(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, !14, i64 0}
!13 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8}
!14 = !{!"float", !7, i64 0}
!15 = !{!13, !14, i64 4}
!16 = !{!13, !14, i64 8}


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

@hmc5883l_read.str = external hidden constant [32 x i8], align 4
@mAddress = external hidden local_unnamed_addr global i32, align 4
@hmc5883l_read.str.1 = external hidden constant [29 x i8], align 4
@hmc5883l_read.str.2 = external hidden constant [38 x i8], align 4
@hmc5883l_read.str.3 = external hidden constant [25 x i8], align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @hmc5883l_read(i32 noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = alloca [7 x 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) #4
  %.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 @hmc5883l_read.str) #4
  br label %41

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

14:                                               ; preds = %10
  call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @hmc5883l_read.str.1) #4
  br label %40

15:                                               ; preds = %10
  call void @delay_ms(i32 noundef 80) #4
  store i8 3, ptr %4, align 1, !tbaa !5
  %16 = load i32, ptr @mAddress, align 4, !tbaa !8
  %17 = call i32 @dh_i2c_write(i32 noundef %16, ptr noundef nonnull %4, i32 noundef 1, i32 noundef 0) #4
  %.not25 = icmp eq i32 %17, 0
  br i1 %.not25, label %19, label %18

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

19:                                               ; preds = %15
  %20 = load i32, ptr @mAddress, align 4, !tbaa !8
  %21 = call i32 @dh_i2c_read(i32 noundef %20, ptr noundef nonnull %4, i32 noundef 7) #4
  %.not26 = icmp eq i32 %21, 0
  br i1 %.not26, label %23, label %22

22:                                               ; preds = %19
  call void (ptr, ...) @dhdebug_ram(ptr noundef nonnull @hmc5883l_read.str.3) #4
  br label %40

23:                                               ; preds = %19
  %24 = call i32 @signedInt16be(ptr noundef nonnull %4, i32 noundef 0)
  %25 = call i32 @signedInt16be(ptr noundef nonnull %4, i32 noundef 4)
  %26 = call i32 @signedInt16be(ptr noundef nonnull %4, i32 noundef 2)
  %27 = insertelement <2 x i32> poison, i32 %24, i64 0
  %28 = insertelement <2 x i32> %27, i32 %25, i64 1
  %29 = icmp eq <2 x i32> %28, <i32 -4096, i32 -4096>
  %30 = sitofp <2 x i32> %28 to <2 x float>
  %31 = fmul <2 x float> %30, <float 0x3FF4CCCCC0000000, float 0x3FF4CCCCC0000000>
  %32 = fmul <2 x float> %31, <float 0x3F40000000000000, float 0x3F40000000000000>
  %33 = select <2 x i1> %29, <2 x float> <float -1.000000e+08, float -1.000000e+08>, <2 x float> %32
  store <2 x float> %33, ptr %2, align 4, !tbaa !10
  %34 = icmp eq i32 %26, -4096
  %35 = sitofp i32 %26 to float
  %36 = fmul float %35, 0x3FF4CCCCC0000000
  %37 = fmul float %36, 0x3F40000000000000
  %38 = select i1 %34, float -1.000000e+08, float %37
  %39 = getelementptr inbounds i8, ptr %2, i64 8
  store float %38, ptr %39, align 4, !tbaa !12
  br label %40

40:                                               ; preds = %23, %22, %18, %14
  %.0 = phi i32 [ %13, %14 ], [ %17, %18 ], [ %21, %22 ], [ 0, %23 ]
  call void @llvm.lifetime.end.p0(i64 7, ptr nonnull %4) #4
  br label %41

41:                                               ; preds = %40, %9
  %.1 = phi i32 [ %8, %9 ], [ %.0, %40 ]
  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 void @delay_ms(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 @signedInt16be(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}
!12 = !{!13, !11, i64 8}
!13 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}


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