#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ find_max(double *, int *, int);
int ind(int, int);
void skyrmion_position(double *mag, double *skpos, int sign) {
  int ids[2];
  find_max(mag, ids, sign);
  int i = ids[0];
  int j = ids[1];
  double mz0 = mag[ind(i, j) + 2];
  double mz1 = mag[ind(i + 1, j) + 2];
  double mz2 = mag[ind(i - 1, j) + 2];
  double mz3 = mag[ind(i, j + 1) + 2];
  double mz4 = mag[ind(i, j - 1) + 2];
  double gx = mz0 - 0.5 * (mz1 + mz2);
  double gy = mz0 - 0.5 * (mz3 + mz4);
  skpos[0] = i + (mz1 - mz2) / (4. * gx);
  skpos[1] = j + (mz3 - mz4) / (4. * gy);
}


x86 assembly (clang, -O0):
<skyrmion_position>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <find_max@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1030 <ind@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x20(%rbp),%edi
add    $0x1,%edi
mov    -0x24(%rbp),%esi
call   1030 <ind@plt>
mov    %eax,%ecx
mov    -0x80(%rbp),%rax
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%edi
sub    $0x1,%edi
mov    -0x24(%rbp),%esi
call   1030 <ind@plt>
mov    %eax,%ecx
mov    -0x78(%rbp),%rax
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
call   1030 <ind@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%rax
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
sub    $0x1,%esi
call   1030 <ind@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%rax
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  0xdc0(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  0xd9c(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
subsd  -0x40(%rbp),%xmm1
movsd  0xd70(%rip),%xmm2
mulsd  -0x58(%rbp),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
subsd  -0x50(%rbp),%xmm1
movsd  0xd44(%rip),%xmm2
mulsd  -0x60(%rbp),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skyrmion_position>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x18(%rsp),%rsi
call   1040 <find_max@plt>
mov    0x18(%rsp),%r12
movq   %r12,%xmm0
movdqa %xmm0,0x40(%rsp)
pshufd $0x55,%xmm0,%xmm0
movd   %xmm0,%ebx
mov    %r12d,%edi
mov    %ebx,%esi
call   1030 <ind@plt>
cltq
lea    0x1(%r12),%edi
movsd  0x10(%r15,%rax,8),%xmm0
movaps %xmm0,0x30(%rsp)
mov    %ebx,%esi
call   1030 <ind@plt>
cltq
lea    -0x1(%r12),%edi
movsd  0x10(%r15,%rax,8),%xmm0
movaps %xmm0,(%rsp)
mov    %ebx,%esi
call   1030 <ind@plt>
cltq
lea    0x1(%rbx),%esi
movsd  0x10(%r15,%rax,8),%xmm0
movaps %xmm0,0x20(%rsp)
mov    %r12d,%edi
call   1030 <ind@plt>
cltq
add    $0xffffffff,%ebx
movaps (%rsp),%xmm0
movhps 0x10(%r15,%rax,8),%xmm0
movaps %xmm0,(%rsp)
mov    %r12d,%edi
mov    %ebx,%esi
call   1030 <ind@plt>
cltq
movapd 0x20(%rsp),%xmm1
movhpd 0x10(%r15,%rax,8),%xmm1
movapd (%rsp),%xmm2
movapd %xmm2,%xmm0
addpd  %xmm1,%xmm0
movapd %xmm1,%xmm3
movapd 0x30(%rsp),%xmm1
unpcklpd %xmm1,%xmm1
mulpd  0xe07(%rip),%xmm0
addpd  %xmm1,%xmm0
cvtdq2pd 0x40(%rsp),%xmm1
mulpd  0xe05(%rip),%xmm0
subpd  %xmm3,%xmm2
divpd  %xmm0,%xmm2
addpd  %xmm1,%xmm2
movupd %xmm2,(%r14)
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @skyrmion_position(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%17 = load double*, double** %4
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%19 = load i32, i32* %6
%20 = call i32 @find_max(double* %17, i32* %18, i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%22 = load i32, i32* %21
store i32 %22, i32* %8
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%24 = load i32, i32* %23
store i32 %24, i32* %9
%25 = load double*, double** %4
%26 = load i32, i32* %8
%27 = load i32, i32* %9
%28 = call i32 @ind(i32 %26, i32 %27)
%29 = add nsw i32 %28, 2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %25, i64 %30
%32 = load double, double* %31
store double %32, double* %10
%33 = load double*, double** %4
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
%36 = load i32, i32* %9
%37 = call i32 @ind(i32 %35, i32 %36)
%38 = add nsw i32 %37, 2
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %33, i64 %39
%41 = load double, double* %40
store double %41, double* %11
%42 = load double*, double** %4
%43 = load i32, i32* %8
%44 = sub nsw i32 %43, 1
%45 = load i32, i32* %9
%46 = call i32 @ind(i32 %44, i32 %45)
%47 = add nsw i32 %46, 2
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %42, i64 %48
%50 = load double, double* %49
store double %50, double* %12
%51 = load double*, double** %4
%52 = load i32, i32* %8
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
%55 = call i32 @ind(i32 %52, i32 %54)
%56 = add nsw i32 %55, 2
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %51, i64 %57
%59 = load double, double* %58
store double %59, double* %13
%60 = load double*, double** %4
%61 = load i32, i32* %8
%62 = load i32, i32* %9
%63 = sub nsw i32 %62, 1
%64 = call i32 @ind(i32 %61, i32 %63)
%65 = add nsw i32 %64, 2
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %60, i64 %66
%68 = load double, double* %67
store double %68, double* %14
%69 = load double, double* %10
%70 = load double, double* %11
%71 = load double, double* %12
%72 = fadd double %70, %71
%73 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %72, double %69)
store double %73, double* %15
%74 = load double, double* %10
%75 = load double, double* %13
%76 = load double, double* %14
%77 = fadd double %75, %76
%78 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %77, double %74)
store double %78, double* %16
%79 = load i32, i32* %8
%80 = sitofp i32 %79 to double
%81 = load double, double* %11
%82 = load double, double* %12
%83 = fsub double %81, %82
%84 = load double, double* %15
%85 = fmul double 4.000000e+00, %84
%86 = fdiv double %83, %85
%87 = fadd double %80, %86
%88 = load double*, double** %5
%89 = getelementptr inbounds double, double* %88, i64 0
store double %87, double* %89
%90 = load i32, i32* %9
%91 = sitofp i32 %90 to double
%92 = load double, double* %13
%93 = load double, double* %14
%94 = fsub double %92, %93
%95 = load double, double* %16
%96 = fmul double 4.000000e+00, %95
%97 = fdiv double %94, %96
%98 = fadd double %91, %97
%99 = load double*, double** %5
%100 = getelementptr inbounds double, double* %99, i64 1
store double %98, double* %100
ret void
}

LLVM IR (-O2):
define void @skyrmion_position(double* %0, double* nocapture writeonly %1, i32 %2) {
%4 = alloca <2 x i32>
%5 = bitcast <2 x i32>* %4 to i8*
%6 = getelementptr inbounds <2 x i32>, <2 x i32>* %4, i64 0, i64 0
%7 = call i32 @find_max(double* %0, i32* %6, i32 %2)
%8 = load <2 x i32>, <2 x i32>* %4
%9 = extractelement <2 x i32> %8, i64 0
%10 = extractelement <2 x i32> %8, i64 1
%11 = call i32 @ind(i32 %9, i32 %10)
%12 = add nsw i32 %11, 2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds double, double* %0, i64 %13
%15 = load double, double* %14
%16 = add nsw i32 %9, 1
%17 = call i32 @ind(i32 %16, i32 %10)
%18 = add nsw i32 %17, 2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %0, i64 %19
%21 = load double, double* %20
%22 = add nsw i32 %9, -1
%23 = call i32 @ind(i32 %22, i32 %10)
%24 = add nsw i32 %23, 2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %0, i64 %25
%27 = load double, double* %26
%28 = add nsw i32 %10, 1
%29 = call i32 @ind(i32 %9, i32 %28)
%30 = add nsw i32 %29, 2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %0, i64 %31
%33 = load double, double* %32
%34 = add nsw i32 %10, -1
%35 = call i32 @ind(i32 %9, i32 %34)
%36 = add nsw i32 %35, 2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %0, i64 %37
%39 = load double, double* %38
%40 = insertelement <2 x double> poison, double %21, i64 0
%41 = insertelement <2 x double> %40, double %33, i64 1
%42 = insertelement <2 x double> poison, double %27, i64 0
%43 = insertelement <2 x double> %42, double %39, i64 1
%44 = fadd <2 x double> %41, %43
%45 = insertelement <2 x double> poison, double %15, i64 0
%46 = shufflevector <2 x double> %45, <2 x double> poison, <2 x i32> zeroinitializer
%47 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %44, <2 x double> <double -5.000000e-01, double -5.000000e-01>, <2 x double> %46)
%48 = sitofp <2 x i32> %8 to <2 x double>
%49 = fsub <2 x double> %41, %43
%50 = fmul <2 x double> %47, <double 4.000000e+00, double 4.000000e+00>
%51 = fdiv <2 x double> %49, %50
%52 = fadd <2 x double> %51, %48
%53 = bitcast double* %1 to <2 x double>*
store <2 x double> %52, <2 x double>* %53
ret void
}