// #target: wasm32
module abi;

struct Vector2 {
  float x;
  float y;
}
fn Vector2 vector2_zero() @extern("vector2_zero") { return {}; }
fn Vector2 vector2_one() @extern("vector2_one") { return {}; }
fn Vector2 vector2_add(Vector2 v1, Vector2 v2) @extern("vector2_add") { return {}; }
fn Vector2 vector2_add_value(Vector2 v, float add) @extern("vector2_add_value") { return {}; }
fn Vector2 vector2_subtract(Vector2 v1, Vector2 v2) @extern("vector2_subtract") { return {}; }
fn Vector2 vector2_subtract_value(Vector2 v, float sub) @extern("vector2_subtract_value")  { return {}; }

/* #expect: abi.ll

target triple = "wasm32-unknown-unknown"

%Vector2 = type { float, float }

define void @vector2_zero(ptr noalias sret(%Vector2) align 4 %0) #0 {
entry:
  %literal = alloca %Vector2, align 4
  store float 0.000000e+00, ptr %literal, align 4
  %ptradd = getelementptr inbounds i8, ptr %literal, i32 4
  store float 0.000000e+00, ptr %ptradd, align 4
  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %0, ptr align 4 %literal, i32 8, i1 false)
  ret void
}

; Function Attrs:
define void @vector2_one(ptr noalias sret(%Vector2) align 4 %0) #0 {
entry:
  %literal = alloca %Vector2, align 4
  store float 0.000000e+00, ptr %literal, align 4
  %ptradd = getelementptr inbounds i8, ptr %literal, i32 4
  store float 0.000000e+00, ptr %ptradd, align 4
  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %0, ptr align 4 %literal, i32 8, i1 false)
  ret void
}

; Function Attrs:
define void @vector2_add(ptr noalias sret(%Vector2) align 4 %0, ptr byval(%Vector2) align 4 %1, ptr byval(%Vector2) align 4 %2) #0 {
entry:
  %literal = alloca %Vector2, align 4
  store float 0.000000e+00, ptr %literal, align 4
  %ptradd = getelementptr inbounds i8, ptr %literal, i32 4
  store float 0.000000e+00, ptr %ptradd, align 4
  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %0, ptr align 4 %literal, i32 8, i1 false)
  ret void
}

; Function Attrs:
define void @vector2_add_value(ptr noalias sret(%Vector2) align 4 %0, ptr byval(%Vector2) align 4 %1, float %2) #0 {
entry:
  %literal = alloca %Vector2, align 4
  store float 0.000000e+00, ptr %literal, align 4
  %ptradd = getelementptr inbounds i8, ptr %literal, i32 4
  store float 0.000000e+00, ptr %ptradd, align 4
  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %0, ptr align 4 %literal, i32 8, i1 false)
  ret void
}

; Function Attrs:
define void @vector2_subtract(ptr noalias sret(%Vector2) align 4 %0, ptr byval(%Vector2) align 4 %1, ptr byval(%Vector2) align 4 %2) #0 {
entry:
  %literal = alloca %Vector2, align 4
  store float 0.000000e+00, ptr %literal, align 4
  %ptradd = getelementptr inbounds i8, ptr %literal, i32 4
  store float 0.000000e+00, ptr %ptradd, align 4
  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %0, ptr align 4 %literal, i32 8, i1 false)
  ret void
}

; Function Attrs:
define void @vector2_subtract_value(ptr noalias sret(%Vector2) align 4 %0, ptr byval(%Vector2) align 4 %1, float %2) #0 {
entry:
  %literal = alloca %Vector2, align 4
  store float 0.000000e+00, ptr %literal, align 4
  %ptradd = getelementptr inbounds i8, ptr %literal, i32 4
  store float 0.000000e+00, ptr %ptradd, align 4
  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %0, ptr align 4 %literal, i32 8, i1 false)
  ret void
}

