; LLVM IR from hans-ob1/neural_cam_ros :: src/detector/image.ll_stbiw (linear_to_rgbe)

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @stbiw__linear_to_rgbe(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds float, ptr %8, i64 0
  %10 = load float, ptr %9, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds float, ptr %11, i64 1
  %13 = load float, ptr %12, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds float, ptr %14, i64 2
  %16 = load float, ptr %15, align 4, !tbaa !9
  %17 = fcmp ogt float %13, %16
  br i1 %17, label %18, label %22

18:                                               ; preds = %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds float, ptr %19, i64 1
  %21 = load float, ptr %20, align 4, !tbaa !9
  br label %26

22:                                               ; preds = %2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds float, ptr %23, i64 2
  %25 = load float, ptr %24, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %22, %18
  %27 = phi float [ %21, %18 ], [ %25, %22 ]
  %28 = fcmp ogt float %10, %27
  br i1 %28, label %29, label %33

29:                                               ; preds = %26
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds float, ptr %30, i64 0
  %32 = load float, ptr %31, align 4, !tbaa !9
  br label %51

33:                                               ; preds = %26
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds float, ptr %34, i64 1
  %36 = load float, ptr %35, align 4, !tbaa !9
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds float, ptr %37, i64 2
  %39 = load float, ptr %38, align 4, !tbaa !9
  %40 = fcmp ogt float %36, %39
  br i1 %40, label %41, label %45

41:                                               ; preds = %33
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds float, ptr %42, i64 1
  %44 = load float, ptr %43, align 4, !tbaa !9
  br label %49

45:                                               ; preds = %33
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds float, ptr %46, i64 2
  %48 = load float, ptr %47, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %45, %41
  %50 = phi float [ %44, %41 ], [ %48, %45 ]
  br label %51

51:                                               ; preds = %49, %29
  %52 = phi float [ %32, %29 ], [ %50, %49 ]
  store float %52, ptr %6, align 4, !tbaa !9
  %53 = load float, ptr %6, align 4, !tbaa !9
  %54 = fpext float %53 to double
  %55 = fcmp olt double %54, 1.000000e-32
  br i1 %55, label %56, label %65

56:                                               ; preds = %51
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i64 3
  store i8 0, ptr %58, align 1, !tbaa !11
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 2
  store i8 0, ptr %60, align 1, !tbaa !11
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 1
  store i8 0, ptr %62, align 1, !tbaa !11
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i64 0
  store i8 0, ptr %64, align 1, !tbaa !11
  br label %102

65:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %66 = load float, ptr %6, align 4, !tbaa !9
  %67 = fpext float %66 to double
  %68 = call double @frexp(double noundef %67, ptr noundef %5) #3
  %69 = fptrunc double %68 to float
  %70 = fmul float %69, 2.560000e+02
  %71 = load float, ptr %6, align 4, !tbaa !9
  %72 = fdiv float %70, %71
  store float %72, ptr %7, align 4, !tbaa !9
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds float, ptr %73, i64 0
  %75 = load float, ptr %74, align 4, !tbaa !9
  %76 = load float, ptr %7, align 4, !tbaa !9
  %77 = fmul float %75, %76
  %78 = fptoui float %77 to i8
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds i8, ptr %79, i64 0
  store i8 %78, ptr %80, align 1, !tbaa !11
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds float, ptr %81, i64 1
  %83 = load float, ptr %82, align 4, !tbaa !9
  %84 = load float, ptr %7, align 4, !tbaa !9
  %85 = fmul float %83, %84
  %86 = fptoui float %85 to i8
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds i8, ptr %87, i64 1
  store i8 %86, ptr %88, align 1, !tbaa !11
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds float, ptr %89, i64 2
  %91 = load float, ptr %90, align 4, !tbaa !9
  %92 = load float, ptr %7, align 4, !tbaa !9
  %93 = fmul float %91, %92
  %94 = fptoui float %93 to i8
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = getelementptr inbounds i8, ptr %95, i64 2
  store i8 %94, ptr %96, align 1, !tbaa !11
  %97 = load i32, ptr %5, align 4, !tbaa !12
  %98 = add nsw i32 %97, 128
  %99 = trunc i32 %98 to i8
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  %101 = getelementptr inbounds i8, ptr %100, i64 3
  store i8 %99, ptr %101, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %102

102:                                              ; preds = %65, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

; Function Attrs: nounwind
declare double @frexp(double noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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"

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @stbiw__linear_to_rgbe(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %4 = load float, ptr %1, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %6 = load float, ptr %5, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load float, ptr %7, align 4, !tbaa !5
  %9 = fcmp ogt float %6, %8
  %. = select i1 %9, float %6, float %8
  %10 = fcmp ogt float %4, %.
  %11 = select i1 %10, float %4, float %.
  %12 = fpext float %11 to double
  %13 = fcmp olt double %12, 1.000000e-32
  br i1 %13, label %14, label %16

14:                                               ; preds = %2
  %15 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 0, ptr %15, align 1, !tbaa !9
  store i8 0, ptr %0, align 1, !tbaa !9
  br label %33

16:                                               ; preds = %2
  %17 = call double @frexp(double noundef %12, ptr noundef nonnull %3) #3
  %18 = fptrunc double %17 to float
  %19 = fmul float %18, 2.560000e+02
  %20 = fdiv float %19, %11
  %21 = fmul float %4, %20
  %22 = fptoui float %21 to i8
  store i8 %22, ptr %0, align 1, !tbaa !9
  %23 = load float, ptr %5, align 4, !tbaa !5
  %24 = fmul float %23, %20
  %25 = fptoui float %24 to i8
  %26 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 %25, ptr %26, align 1, !tbaa !9
  %27 = load float, ptr %7, align 4, !tbaa !5
  %28 = fmul float %20, %27
  %29 = fptoui float %28 to i8
  %30 = load i32, ptr %3, align 4, !tbaa !10
  %31 = trunc i32 %30 to i8
  %32 = xor i8 %31, -128
  br label %33

33:                                               ; preds = %16, %14
  %.sink32 = phi i8 [ 0, %14 ], [ %32, %16 ]
  %.sink = phi i8 [ 0, %14 ], [ %29, %16 ]
  %34 = getelementptr inbounds i8, ptr %0, i64 3
  store i8 %.sink32, ptr %34, align 1
  %35 = getelementptr inbounds i8, ptr %0, i64 2
  store i8 %.sink, ptr %35, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: write)
declare double @frexp(double noundef, ptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) 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 #2 = { mustprogress nofree nounwind willreturn memory(argmem: write) "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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass