#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 */
float FLT_EPSILON;
double round(double);
void minimum_image(double *x, float *box, float *inverse_box) {
  int i;
  double s;
  for (i = 0; i < 3; i++) {
    if (box[i] > FLT_EPSILON) {
      s = inverse_box[i] * x[i];
      x[i] = box[i] * (s - round(s));
    }
  }
}


x86 assembly (clang, -O0):
<minimum_image>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    11d4 <minimum_image+0xc4>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    0x2e97(%rip),%rax
ucomiss (%rax),%xmm0
jbe    11c1 <minimum_image+0xb1>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <round@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11c6 <minimum_image+0xb6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112b <minimum_image+0x1b>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<minimum_image>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2eb7(%rip),%rax
movss  (%rax),%xmm1
movss  (%rsi),%xmm2
ucomiss %xmm1,%xmm2
movss  %xmm1,0x10(%rsp)
jbe    117d <minimum_image+0x6d>
movss  (%r14),%xmm1
cvtss2sd %xmm1,%xmm0
mulsd  (%r15),%xmm0
movsd  %xmm0,0x18(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1030 <round@plt>
movss  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
subsd  %xmm0,%xmm2
mulsd  0x8(%rsp),%xmm2
movsd  %xmm2,(%r15)
movss  0x4(%rbx),%xmm2
ucomiss %xmm1,%xmm2
jbe    11ce <minimum_image+0xbe>
movss  0x4(%r14),%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
mulsd  0x8(%r15),%xmm0
movsd  %xmm0,0x18(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1030 <round@plt>
movss  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
subsd  %xmm0,%xmm2
mulsd  0x8(%rsp),%xmm2
movsd  %xmm2,0x8(%r15)
movss  0x8(%rbx),%xmm2
ucomiss %xmm1,%xmm2
jbe    1219 <minimum_image+0x109>
movss  0x8(%r14),%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
mulsd  0x10(%r15),%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
movsd  %xmm1,0x10(%rsp)
call   1030 <round@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  %xmm1,0x10(%r15)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@FLT_EPSILON = global float 0.000000e+00
define void @minimum_image(double* %0, float* %1, float* %2) {
%4 = alloca double*
%5 = alloca float*
%6 = alloca float*
%7 = alloca i32
%8 = alloca double
store double* %0, double** %4
store float* %1, float** %5
store float* %2, float** %6
store i32 0, i32* %7
br label %9
9: ; preds = %49, %3
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %52
12: ; preds = %9
%13 = load float*, float** %5
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds float, float* %13, i64 %15
%17 = load float, float* %16
%18 = load float, float* @FLT_EPSILON
%19 = fcmp ogt float %17, %18
br i1 %19, label %20, label %48
20: ; preds = %12
%21 = load float*, float** %6
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds float, float* %21, i64 %23
%25 = load float, float* %24
%26 = fpext float %25 to double
%27 = load double*, double** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = fmul double %26, %31
store double %32, double* %8
%33 = load float*, float** %5
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds float, float* %33, i64 %35
%37 = load float, float* %36
%38 = fpext float %37 to double
%39 = load double, double* %8
%40 = load double, double* %8
%41 = call double @llvm.round.f64(double %40)
%42 = fsub double %39, %41
%43 = fmul double %38, %42
%44 = load double*, double** %4
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
store double %43, double* %47
br label %48
48: ; preds = %20, %12
br label %49
49: ; preds = %48
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %9
52: ; preds = %9
ret void
}

LLVM IR (-O2):
@FLT_EPSILON = global float 0.000000e+00
define void @minimum_image(double* nocapture %0, float* nocapture %1, float* nocapture %2) {
%4 = load float, float* @FLT_EPSILON
%5 = load float, float* %1
%6 = fcmp ogt float %5, %4
br i1 %6, label %7, label %16
7: ; preds = %3
%8 = load float, float* %2
%9 = fpext float %8 to double
%10 = load double, double* %0
%11 = fmul double %10, %9
%12 = fpext float %5 to double
%13 = tail call double @llvm.round.f64(double %11)
%14 = fsub double %11, %13
%15 = fmul double %14, %12
store double %15, double* %0
br label %16
16: ; preds = %3, %7
%17 = getelementptr inbounds float, float* %1, i64 1
%18 = load float, float* %17
%19 = fcmp ogt float %18, %4
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = getelementptr inbounds float, float* %2, i64 1
%22 = load float, float* %21
%23 = fpext float %22 to double
%24 = getelementptr inbounds double, double* %0, i64 1
%25 = load double, double* %24
%26 = fmul double %25, %23
%27 = fpext float %18 to double
%28 = tail call double @llvm.round.f64(double %26)
%29 = fsub double %26, %28
%30 = fmul double %29, %27
store double %30, double* %24
br label %31
31: ; preds = %20, %16
%32 = getelementptr inbounds float, float* %1, i64 2
%33 = load float, float* %32
%34 = fcmp ogt float %33, %4
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = getelementptr inbounds float, float* %2, i64 2
%37 = load float, float* %36
%38 = fpext float %37 to double
%39 = getelementptr inbounds double, double* %0, i64 2
%40 = load double, double* %39
%41 = fmul double %40, %38
%42 = fpext float %33 to double
%43 = tail call double @llvm.round.f64(double %41)
%44 = fsub double %41, %43
%45 = fmul double %44, %42
store double %45, double* %39
br label %46
46: ; preds = %35, %31
ret void
}