; LLVM IR from zephyrproject-rtos/zephyr :: drivers/sensor/ntc_thermistor (ntc_thermistor_calc)

; 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.ntc_config = type { i8, i32, i32, i32, %struct.ntc_type }
%struct.ntc_type = type { ptr, i32 }

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

12:                                               ; preds = %3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ntc_config, ptr %13, i32 0, i32 0
  %15 = load i8, ptr %14, align 8, !tbaa !11, !range !15, !noundef !16
  %16 = trunc i8 %15 to i1
  %17 = zext i1 %16 to i64
  %18 = select i1 %16, i32 2147483647, i32 0
  store i32 %18, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %57

19:                                               ; preds = %3
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = icmp sge i32 %20, %21
  br i1 %22, label %23, label %30

23:                                               ; preds = %19
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ntc_config, ptr %24, i32 0, i32 0
  %26 = load i8, ptr %25, align 8, !tbaa !11, !range !15, !noundef !16
  %27 = trunc i8 %26 to i1
  %28 = zext i1 %27 to i64
  %29 = select i1 %27, i32 0, i32 2147483647
  store i32 %29, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %57

30:                                               ; preds = %19
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ntc_config, ptr %31, i32 0, i32 0
  %33 = load i8, ptr %32, align 8, !tbaa !11, !range !15, !noundef !16
  %34 = trunc i8 %33 to i1
  br i1 %34, label %35, label %45

35:                                               ; preds = %30
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ntc_config, ptr %36, i32 0, i32 3
  %38 = load i32, ptr %37, align 4, !tbaa !17
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = sub nsw i32 %39, %40
  %42 = mul i32 %38, %41
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = udiv i32 %42, %43
  store i32 %44, ptr %8, align 4, !tbaa !9
  br label %55

45:                                               ; preds = %30
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ntc_config, ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 8, !tbaa !18
  %49 = load i32, ptr %6, align 4, !tbaa !9
  %50 = mul i32 %48, %49
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = sub nsw i32 %51, %52
  %54 = udiv i32 %50, %53
  store i32 %54, ptr %8, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %45, %35
  %56 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %56, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %57

57:                                               ; preds = %55, %23, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %58 = load i32, ptr %4, align 4
  ret i32 %58
}

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

; 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"ntc_config", !13, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !14, i64 16}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"ntc_type", !6, i64 0, !10, i64 8}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!12, !10, i64 12}
!18 = !{!12, !10, 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local i32 @ntc_get_ohm_of_thermistor(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp slt i32 %1, 1
  br i1 %4, label %5, label %9

5:                                                ; preds = %3
  %6 = load i8, ptr %0, align 8, !tbaa !5, !range !13, !noundef !14
  %7 = trunc nuw i8 %6 to i1
  %8 = select i1 %7, i32 2147483647, i32 0
  br label %27

9:                                                ; preds = %3
  %.not = icmp slt i32 %1, %2
  %10 = load i8, ptr %0, align 8, !tbaa !5, !range !13, !noundef !14
  %11 = trunc nuw i8 %10 to i1
  br i1 %.not, label %14, label %12

12:                                               ; preds = %9
  %13 = select i1 %11, i32 0, i32 2147483647
  br label %27

14:                                               ; preds = %9
  br i1 %11, label %15, label %21

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %0, i64 12
  %17 = load i32, ptr %16, align 4, !tbaa !15
  %18 = sub nsw i32 %2, %1
  %19 = mul i32 %17, %18
  %20 = udiv i32 %19, %1
  br label %27

21:                                               ; preds = %14
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = load i32, ptr %22, align 8, !tbaa !16
  %24 = mul i32 %23, %1
  %25 = sub nsw i32 %2, %1
  %26 = udiv i32 %24, %25
  br label %27

27:                                               ; preds = %15, %21, %12, %5
  %.015 = phi i32 [ %8, %5 ], [ %13, %12 ], [ %20, %15 ], [ %26, %21 ]
  ret i32 %.015
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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" }

!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, !7, i64 0}
!6 = !{!"ntc_config", !7, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !11, i64 16}
!7 = !{!"_Bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"ntc_type", !12, i64 0, !10, i64 8}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!6, !10, i64 12}
!16 = !{!6, !10, i64 8}


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