int majorana_magnetic_field(double x, double y, double z, double t, double *bx,
                            double *by, double *bz, void *data) {
  if (!data)
    return 0;
  double Blarge = ((double *)data)[0];
  double Bsmall = ((double *)data)[1];
  double magnetLength = ((double *)data)[2];
  *bx = Blarge - 2 * Blarge * z / magnetLength;
  *by = Bsmall;
  *bz = 0;
  return 1;
}


x86 assembly (clang, -O0):
<majorana_magnetic_field>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    %rdi,-0x30(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %rcx,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    113f <majorana_magnetic_field+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11af <majorana_magnetic_field+0xaf>
mov    -0x48(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x48(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x48(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  0xe8b(%rip),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
divsd  -0x60(%rbp),%xmm1
subsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x58(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x40(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<majorana_magnetic_field>:
test   %rcx,%rcx
je     1138 <majorana_magnetic_field+0x38>
movsd  (%rcx),%xmm0
movsd  0x8(%rcx),%xmm1
movapd %xmm0,%xmm3
addsd  %xmm0,%xmm3
mulsd  %xmm2,%xmm3
divsd  0x10(%rcx),%xmm3
subsd  %xmm3,%xmm0
movsd  %xmm0,(%rdi)
movsd  %xmm1,(%rsi)
movq   $0x0,(%rdx)
mov    $0x1,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @majorana_magnetic_field(double %0, double %1, double %2, double %3, double* %4, double* %5, double* %6, i8* %7) {
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double*
%15 = alloca double*
%16 = alloca double*
%17 = alloca i8*
%18 = alloca double
%19 = alloca double
%20 = alloca double
store double %0, double* %10
store double %1, double* %11
store double %2, double* %12
store double %3, double* %13
store double* %4, double** %14
store double* %5, double** %15
store double* %6, double** %16
store i8* %7, i8** %17
%21 = load i8*, i8** %17
%22 = icmp ne i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %8
store i32 0, i32* %9
br label %49
24: ; preds = %8
%25 = load i8*, i8** %17
%26 = bitcast i8* %25 to double*
%27 = getelementptr inbounds double, double* %26, i64 0
%28 = load double, double* %27
store double %28, double* %18
%29 = load i8*, i8** %17
%30 = bitcast i8* %29 to double*
%31 = getelementptr inbounds double, double* %30, i64 1
%32 = load double, double* %31
store double %32, double* %19
%33 = load i8*, i8** %17
%34 = bitcast i8* %33 to double*
%35 = getelementptr inbounds double, double* %34, i64 2
%36 = load double, double* %35
store double %36, double* %20
%37 = load double, double* %18
%38 = load double, double* %18
%39 = fmul double 2.000000e+00, %38
%40 = load double, double* %12
%41 = fmul double %39, %40
%42 = load double, double* %20
%43 = fdiv double %41, %42
%44 = fsub double %37, %43
%45 = load double*, double** %14
store double %44, double* %45
%46 = load double, double* %19
%47 = load double*, double** %15
store double %46, double* %47
%48 = load double*, double** %16
store double 0.000000e+00, double* %48
store i32 1, i32* %9
br label %49
49: ; preds = %24, %23
%50 = load i32, i32* %9
ret i32 %50
}

LLVM IR (-O2):
define i32 @majorana_magnetic_field(double %0, double %1, double %2, double %3, double* nocapture writeonly %4, double* nocapture writeonly %5, double* nocapture writeonly %6, i8* %7) {
%9 = icmp eq i8* %7, null
br i1 %9, label %23, label %10
10: ; preds = %8
%11 = bitcast i8* %7 to double*
%12 = load double, double* %11
%13 = getelementptr inbounds i8, i8* %7, i64 8
%14 = bitcast i8* %13 to double*
%15 = load double, double* %14
%16 = getelementptr inbounds i8, i8* %7, i64 16
%17 = bitcast i8* %16 to double*
%18 = load double, double* %17
%19 = fmul double %12, 2.000000e+00
%20 = fmul double %19, %2
%21 = fdiv double %20, %18
%22 = fsub double %12, %21
store double %22, double* %4
store double %15, double* %5
store double 0.000000e+00, double* %6
br label %23
23: ; preds = %8, %10
%24 = phi i32 [ 1, %10 ], [ 0, %8 ]
ret i32 %24
}