; LLVM IR from paintdream/DontStarveLuaJIT :: src/luajit/src (lj_ctype)

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

%union.TValue = type { i64 }
%struct.anon.1 = type { i32, i32 }
%struct.SBuf = type { %struct.MRef, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.MRef = type { i32 }

; 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 hidden ptr @lj_ctype_repr_complex(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca %union.TValue, align 8
  %9 = alloca %union.TValue, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call ptr @lj_buf_tmp_(ptr noundef %10)
  store ptr %11, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = zext i32 %12 to i64
  %14 = icmp eq i64 %13, 16
  br i1 %14, label %15, label %21

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load double, ptr %16, align 8, !tbaa !11
  store double %17, ptr %8, align 8, !tbaa !13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds double, ptr %18, i64 1
  %20 = load double, ptr %19, align 8, !tbaa !11
  store double %20, ptr %9, align 8, !tbaa !13
  br label %29

21:                                               ; preds = %3
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load float, ptr %22, align 4, !tbaa !14
  %24 = fpext float %23 to double
  store double %24, ptr %8, align 8, !tbaa !13
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds float, ptr %25, i64 1
  %27 = load float, ptr %26, align 4, !tbaa !14
  %28 = fpext float %27 to double
  store double %28, ptr %9, align 8, !tbaa !13
  br label %29

29:                                               ; preds = %21, %15
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load double, ptr %8, align 8, !tbaa !13
  %32 = call ptr @lj_strfmt_putfnum(ptr noundef %30, i32 noundef 251658293, double noundef %31)
  %33 = getelementptr inbounds %struct.anon.1, ptr %9, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !13
  %35 = and i32 %34, -2147483648
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %41

37:                                               ; preds = %29
  %38 = load double, ptr %9, align 8, !tbaa !13
  %39 = load double, ptr %9, align 8, !tbaa !13
  %40 = fcmp une double %38, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %37, %29
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = call ptr @lj_buf_putchar(ptr noundef %42, i32 noundef 43)
  br label %44

44:                                               ; preds = %41, %37
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load double, ptr %9, align 8, !tbaa !13
  %47 = call ptr @lj_strfmt_putfnum(ptr noundef %45, i32 noundef 251658293, double noundef %46)
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.SBuf, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds %struct.MRef, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 4, !tbaa !16
  %53 = zext i32 %52 to i64
  %54 = inttoptr i64 %53 to ptr
  %55 = getelementptr inbounds i8, ptr %54, i64 -1
  %56 = load i8, ptr %55, align 1, !tbaa !13
  %57 = sext i8 %56 to i32
  %58 = icmp sge i32 %57, 97
  %59 = zext i1 %58 to i64
  %60 = select i1 %58, i32 73, i32 105
  %61 = call ptr @lj_buf_putchar(ptr noundef %48, i32 noundef %60)
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = call ptr @lj_buf_str(ptr noundef %62, ptr noundef %63)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret ptr %64
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @lj_buf_tmp_(ptr noundef) #2

declare hidden ptr @lj_strfmt_putfnum(ptr noundef, i32 noundef, double noundef) #3

declare hidden ptr @lj_buf_putchar(ptr noundef, i32 noundef) #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @lj_buf_str(ptr 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 = { alwaysinline 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 #3 = { "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 = !{!"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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!17, !10, i64 0}
!17 = !{!"SBuf", !18, i64 0, !18, i64 4, !18, i64 8, !18, i64 12}
!18 = !{!"MRef", !10, 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: nounwind uwtable
define hidden ptr @lj_ctype_repr_complex(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @lj_buf_tmp_(ptr noundef %0)
  %5 = icmp eq i32 %2, 16
  br i1 %5, label %6, label %8

6:                                                ; preds = %3
  %7 = load <2 x double>, ptr %1, align 8, !tbaa !5
  br label %11

8:                                                ; preds = %3
  %9 = load <2 x float>, ptr %1, align 4, !tbaa !9
  %10 = fpext <2 x float> %9 to <2 x double>
  br label %11

11:                                               ; preds = %8, %6
  %12 = phi <2 x double> [ %7, %6 ], [ %10, %8 ]
  %13 = extractelement <2 x double> %12, i64 0
  %14 = tail call ptr @lj_strfmt_putfnum(ptr noundef %4, i32 noundef 251658293, double noundef %13) #3
  %15 = extractelement <2 x double> %12, i64 1
  %16 = bitcast double %15 to i64
  %.not = icmp sgt i64 %16, -1
  %17 = fcmp uno double %15, 0.000000e+00
  %or.cond = or i1 %17, %.not
  br i1 %or.cond, label %18, label %20

18:                                               ; preds = %11
  %19 = tail call ptr @lj_buf_putchar(ptr noundef %4, i32 noundef 43) #3
  br label %20

20:                                               ; preds = %11, %18
  %21 = tail call ptr @lj_strfmt_putfnum(ptr noundef %4, i32 noundef 251658293, double noundef %15) #3
  %22 = load i32, ptr %4, align 4, !tbaa !11
  %23 = zext i32 %22 to i64
  %24 = inttoptr i64 %23 to ptr
  %25 = getelementptr inbounds i8, ptr %24, i64 -1
  %26 = load i8, ptr %25, align 1, !tbaa !15
  %27 = icmp sgt i8 %26, 96
  %28 = select i1 %27, i32 73, i32 105
  %29 = tail call ptr @lj_buf_putchar(ptr noundef nonnull %4, i32 noundef %28) #3
  %30 = tail call ptr @lj_buf_str(ptr noundef %0, ptr noundef nonnull %4)
  ret ptr %30
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @lj_buf_tmp_(ptr noundef) local_unnamed_addr #1

declare hidden ptr @lj_strfmt_putfnum(ptr noundef, i32 noundef, double noundef) local_unnamed_addr #2

declare hidden ptr @lj_buf_putchar(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @lj_buf_str(ptr noundef, ptr noundef) local_unnamed_addr #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 = { alwaysinline 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 = { "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 = !{!"double", !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 = !{!12, !14, i64 0}
!12 = !{!"SBuf", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12}
!13 = !{!"MRef", !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}


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