#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 getsamplen(float *, int, int, int, int, int, int);
int round(float);
void interpolate_nearest(float *result, float *x, int w, int h, int pd, float p,
                         float q) {
  int ip = round(p);
  int iq = round(q);
  for (int l = 0; l < (pd); l++) {
    float r = getsamplen(x, w, h, pd, ip, iq, l);
    result[l] = r;
  }
}


x86 assembly (clang, -O0):
<interpolate_nearest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movss  %xmm0,-0x20(%rbp)
movss  %xmm1,-0x24(%rbp)
movss  -0x20(%rbp),%xmm0
call   1040 <round@plt>
mov    %eax,-0x28(%rbp)
movss  -0x24(%rbp),%xmm0
call   1040 <round@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b6 <interpolate_nearest+0x96>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <getsamplen@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1165 <interpolate_nearest+0x45>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interpolate_nearest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movss  %xmm1,0xc(%rsp)
mov    %r8d,%r14d
mov    %ecx,0x14(%rsp)
mov    %edx,0x10(%rsp)
mov    %rsi,%r12
mov    %rdi,%r13
call   1040 <round@plt>
mov    %eax,%ebx
movss  0xc(%rsp),%xmm0
call   1040 <round@plt>
test   %r14d,%r14d
jle    119d <interpolate_nearest+0x7d>
mov    %eax,%ebp
mov    %r14d,%r14d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,(%rsp)
mov    %r12,%rdi
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
mov    %r14d,%ecx
mov    %ebx,%r8d
mov    %ebp,%r9d
call   1030 <getsamplen@plt>
movss  %xmm0,0x0(%r13,%r15,4)
add    $0x1,%r15
cmp    %r15,%r14
jne    1170 <interpolate_nearest+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @interpolate_nearest(float* %0, float* %1, i32 %2, i32 %3, i32 %4, float %5, float %6) {
%8 = alloca float*
%9 = alloca float*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca float
%14 = alloca float
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca float
store float* %0, float** %8
store float* %1, float** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store float %5, float* %13
store float %6, float* %14
%19 = load float, float* %13
%20 = call i32 @round(float %19)
store i32 %20, i32* %15
%21 = load float, float* %14
%22 = call i32 @round(float %21)
store i32 %22, i32* %16
store i32 0, i32* %17
br label %23
23: ; preds = %41, %7
%24 = load i32, i32* %17
%25 = load i32, i32* %12
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %44
27: ; preds = %23
%28 = load float*, float** %9
%29 = load i32, i32* %10
%30 = load i32, i32* %11
%31 = load i32, i32* %12
%32 = load i32, i32* %15
%33 = load i32, i32* %16
%34 = load i32, i32* %17
%35 = call float @getsamplen(float* %28, i32 %29, i32 %30, i32 %31, i32 %32, i32 %33, i32 %34)
store float %35, float* %18
%36 = load float, float* %18
%37 = load float*, float** %8
%38 = load i32, i32* %17
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds float, float* %37, i64 %39
store float %36, float* %40
br label %41
41: ; preds = %27
%42 = load i32, i32* %17
%43 = add nsw i32 %42, 1
store i32 %43, i32* %17
br label %23
44: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @interpolate_nearest(float* nocapture writeonly %0, float* %1, i32 %2, i32 %3, i32 %4, float %5, float %6) {
%8 = tail call i32 @round(float %5)
%9 = tail call i32 @round(float %6)
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = zext i32 %4 to i64
br label %14
13: ; preds = %14, %7
ret void
14: ; preds = %11, %14
%15 = phi i64 [ 0, %11 ], [ %19, %14 ]
%16 = trunc i64 %15 to i32
%17 = tail call float @getsamplen(float* %1, i32 %2, i32 %3, i32 %4, i32 %8, i32 %9, i32 %16)
%18 = getelementptr inbounds float, float* %0, i64 %15
store float %17, float* %18
%19 = add nuw nsw i64 %15, 1
%20 = icmp eq i64 %19, %12
br i1 %20, label %13, label %14
}