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

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

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @ds18b20_read(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [8 x i8], align 1
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp ne i32 %9, -1
  br i1 %10, label %11, label %17

11:                                               ; preds = %2
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = call i32 @dh_onewire_set_pin(i32 noundef %12)
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  store ptr @.str, ptr %3, align 8
  br label %45

16:                                               ; preds = %11
  br label %17

17:                                               ; preds = %16, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %18 = getelementptr inbounds [8 x i8], ptr %6, i64 0, i64 0
  store i8 -52, ptr %18, align 1, !tbaa !11
  %19 = getelementptr inbounds [8 x i8], ptr %6, i64 0, i64 1
  store i8 68, ptr %19, align 1, !tbaa !11
  %20 = getelementptr inbounds [8 x i8], ptr %6, i64 0, i64 0
  %21 = call i32 @dh_onewire_write(ptr noundef %20, i32 noundef 2)
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %17
  store ptr @.str.1, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %44

24:                                               ; preds = %17
  call void @delay_ms(i32 noundef 750)
  %25 = getelementptr inbounds [8 x i8], ptr %6, i64 0, i64 1
  store i8 -66, ptr %25, align 1, !tbaa !11
  %26 = getelementptr inbounds [8 x i8], ptr %6, i64 0, i64 0
  %27 = call i32 @dh_onewire_write(ptr noundef %26, i32 noundef 2)
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  store ptr @.str.2, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %44

30:                                               ; preds = %24
  %31 = getelementptr inbounds [8 x i8], ptr %6, i64 0, i64 0
  %32 = call i32 @dh_onewire_read(ptr noundef %31, i32 noundef 8)
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  store ptr @.str.3, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %44

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %36 = getelementptr inbounds [8 x i8], ptr %6, i64 0, i64 0
  store ptr %36, ptr %8, align 8, !tbaa !9
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = getelementptr inbounds i16, ptr %37, i64 0
  %39 = load i16, ptr %38, align 2, !tbaa !12
  %40 = sext i16 %39 to i32
  %41 = sitofp i32 %40 to float
  %42 = fdiv float %41, 1.600000e+01
  %43 = load ptr, ptr %5, align 8, !tbaa !9
  store float %42, ptr %43, align 4, !tbaa !14
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %44

44:                                               ; preds = %35, %34, %29, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %45

45:                                               ; preds = %44, %15
  %46 = load ptr, ptr %3, align 8
  ret ptr %46
}

declare i32 @dh_onewire_set_pin(i32 noundef) #1

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

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

declare void @delay_ms(i32 noundef) #1

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

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

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 = !{!"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 = !{!"short", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"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"

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @ds18b20_read(i32 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = alloca [8 x i8], align 1
  %.not = icmp eq i32 %0, -1
  br i1 %.not, label %6, label %4

4:                                                ; preds = %2
  %5 = tail call i32 @dh_onewire_set_pin(i32 noundef %0) #3
  %.not5 = icmp eq i32 %5, 0
  br i1 %.not5, label %6, label %18

6:                                                ; preds = %4, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i8 -52, ptr %3, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 68, ptr %7, align 1, !tbaa !5
  %8 = call i32 @dh_onewire_write(ptr noundef nonnull %3, i32 noundef 2) #3
  %.not6 = icmp eq i32 %8, 0
  br i1 %.not6, label %9, label %17

9:                                                ; preds = %6
  call void @delay_ms(i32 noundef 750) #3
  store i8 -66, ptr %7, align 1, !tbaa !5
  %10 = call i32 @dh_onewire_write(ptr noundef nonnull %3, i32 noundef 2) #3
  %.not7 = icmp eq i32 %10, 0
  br i1 %.not7, label %11, label %17

11:                                               ; preds = %9
  %12 = call i32 @dh_onewire_read(ptr noundef nonnull %3, i32 noundef 8) #3
  %.not8 = icmp eq i32 %12, 0
  br i1 %.not8, label %13, label %17

13:                                               ; preds = %11
  %14 = load i16, ptr %3, align 2, !tbaa !8
  %15 = sitofp i16 %14 to float
  %16 = fmul float %15, 6.250000e-02
  store float %16, ptr %1, align 4, !tbaa !10
  br label %17

17:                                               ; preds = %11, %9, %6, %13
  %.0 = phi ptr [ null, %13 ], [ @.str.1, %6 ], [ @.str.2, %9 ], [ @.str.3, %11 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %18

18:                                               ; preds = %4, %17
  %.1 = phi ptr [ %.0, %17 ], [ @.str, %4 ]
  ret ptr %.1
}

declare i32 @dh_onewire_set_pin(i32 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 i32 @dh_onewire_write(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @delay_ms(i32 noundef) local_unnamed_addr #1

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

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


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