; LLVM IR from epicf/ef :: lib/tinyexpr (tinyexpr)

; 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.state = type { ptr, ptr, i32, %union.anon.0, ptr, ptr, i32 }
%union.anon.0 = type { double }

; Function Attrs: nounwind uwtable
declare dso_local void @te_free(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @next_token(ptr noundef) #0

; 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

; Function Attrs: nounwind uwtable
define dso_local ptr @te_compile(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca %struct.state, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 56, ptr %10) #2
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.state, ptr %10, i32 0, i32 1
  store ptr %13, ptr %14, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.state, ptr %10, i32 0, i32 0
  store ptr %13, ptr %15, align 8, !tbaa !13
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.state, ptr %10, i32 0, i32 5
  store ptr %16, ptr %17, align 8, !tbaa !14
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = getelementptr inbounds %struct.state, ptr %10, i32 0, i32 6
  store i32 %18, ptr %19, align 8, !tbaa !15
  call void @next_token(ptr noundef %10)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %20 = call ptr @list(ptr noundef %10)
  store ptr %20, ptr %11, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.state, ptr %10, i32 0, i32 2
  %22 = load i32, ptr %21, align 8, !tbaa !16
  %23 = icmp ne i32 %22, 26
  br i1 %23, label %24, label %45

24:                                               ; preds = %4
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  call void @te_free(ptr noundef %25)
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %44

28:                                               ; preds = %24
  %29 = getelementptr inbounds %struct.state, ptr %10, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds %struct.state, ptr %10, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = ptrtoint ptr %30 to i64
  %34 = ptrtoint ptr %32 to i64
  %35 = sub i64 %33, %34
  %36 = trunc i64 %35 to i32
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %36, ptr %37, align 4, !tbaa !9
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %28
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 1, ptr %42, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %41, %28
  br label %44

44:                                               ; preds = %43, %24
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %53

45:                                               ; preds = %4
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  call void @optimize(ptr noundef %46)
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %51

49:                                               ; preds = %45
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %50, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %49, %45
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %52, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %53

53:                                               ; preds = %51, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 56, ptr %10) #2
  %54 = load ptr, ptr %5, align 8
  ret ptr %54
}

; Function Attrs: nounwind uwtable
declare hidden ptr @list(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @optimize(ptr noundef) #0

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, !6, i64 8}
!12 = !{!"state", !6, i64 0, !6, i64 8, !10, i64 16, !7, i64 24, !6, i64 32, !6, i64 40, !10, i64 48}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !6, i64 40}
!15 = !{!12, !10, i64 48}
!16 = !{!12, !10, i64 16}


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

%struct.state = type { ptr, ptr, i32, %union.anon.0, ptr, ptr, i32 }
%union.anon.0 = type { double }

; Function Attrs: nounwind uwtable
declare dso_local void @te_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @next_token(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @te_compile(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  %5 = alloca %struct.state, align 8
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %5) #3
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %0, ptr %5, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %5, i64 40
  store ptr %1, ptr %7, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %5, i64 48
  store i32 %2, ptr %8, align 8, !tbaa !13
  call void @next_token(ptr noundef nonnull %5)
  %9 = call ptr @list(ptr noundef nonnull %5)
  %10 = getelementptr inbounds i8, ptr %5, i64 16
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %.not = icmp eq i32 %11, 26
  %.not13 = icmp eq ptr %3, null
  br i1 %.not, label %20, label %12

12:                                               ; preds = %4
  call void @te_free(ptr noundef %9)
  br i1 %.not13, label %21, label %13

13:                                               ; preds = %12
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !11
  %16 = ptrtoint ptr %14 to i64
  %17 = ptrtoint ptr %15 to i64
  %18 = sub i64 %16, %17
  %19 = trunc i64 %18 to i32
  %spec.store.select = call i32 @llvm.umax.i32(i32 %19, i32 1)
  br label %.sink.split

20:                                               ; preds = %4
  call void @optimize(ptr noundef %9)
  br i1 %.not13, label %21, label %.sink.split

.sink.split:                                      ; preds = %20, %13
  %spec.store.select.sink = phi i32 [ %spec.store.select, %13 ], [ 0, %20 ]
  %.0.ph = phi ptr [ null, %13 ], [ %9, %20 ]
  store i32 %spec.store.select.sink, ptr %3, align 4
  br label %21

21:                                               ; preds = %.sink.split, %20, %12
  %.0 = phi ptr [ null, %12 ], [ %9, %20 ], [ %.0.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %5) #3
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare hidden ptr @list(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @optimize(ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 8}
!6 = !{!"state", !7, i64 0, !7, i64 8, !10, i64 16, !8, i64 24, !7, i64 32, !7, i64 40, !10, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 40}
!13 = !{!6, !10, i64 48}
!14 = !{!6, !10, i64 16}


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