#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*/ calc_coeffs(float *, float, int, int, int);
int min(int, int);
int split_map(int, int, int, float *);
void scale_up_coeffs(int in_width, int out_width, float *coeff_buf,
                     int *border_buf) {
  int i, smp_i, start, end, ltrim, rtrim, safe_end, max_pos;
  float tx;
  max_pos = in_width - 1;
  for (i = 0; i < out_width; i++) {
    smp_i = split_map(in_width, out_width, i, &tx);
    start = smp_i - 1;
    end = smp_i + 2;
    safe_end = min(end, max_pos);
    ltrim = 0;
    rtrim = 0;
    if (start < 0) {
      ltrim = -1 * start;
    }
    if (end > max_pos) {
      rtrim = end - max_pos;
    }
    border_buf[safe_end] += 1;
    calc_coeffs(coeff_buf + rtrim, tx, 4, ltrim, rtrim);
    coeff_buf += 4;
  }
}


x86 assembly (clang, -O0):
<scale_up_coeffs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121d <scale_up_coeffs+0xed>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    -0x3c(%rbp),%rcx
call   1050 <split_map@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x38(%rbp),%esi
call   1030 <min@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11b9 <scale_up_coeffs+0x89>
imul   $0xffffffff,-0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x38(%rbp),%eax
jle    11ce <scale_up_coeffs+0x9e>
mov    -0x28(%rbp),%eax
sub    -0x38(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rdi
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
movss  -0x3c(%rbp),%xmm0
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    $0x4,%esi
call   1040 <calc_coeffs@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <scale_up_coeffs+0x26>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scale_up_coeffs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
test   %esi,%esi
jle    11e8 <scale_up_coeffs+0xb8>
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    0x8(%rsp),%rax
add    $0xffffffff,%eax
mov    %eax,0x10(%rsp)
xor    %r13d,%r13d
mov    %esi,0x4(%rsp)
mov    0x10(%rsp),%r12d
nopl   0x0(%rax)
mov    0x8(%rsp),%rdi
mov    0x4(%rsp),%esi
mov    %r13d,%edx
lea    0x14(%rsp),%rcx
call   1050 <split_map@plt>
mov    %eax,%r14d
lea    0x2(%r14),%r15d
mov    %r15d,%edi
mov    %r12d,%esi
call   1030 <min@plt>
mov    $0x1,%edx
sub    %r14d,%edx
test   %r14d,%r14d
mov    $0x0,%esi
cmovg  %esi,%edx
mov    %r15d,%ecx
sub    %r12d,%ecx
cmp    0x8(%rsp),%r15d
cmovl  %esi,%ecx
cltq
addl   $0x1,0x0(%rbp,%rax,4)
movslq %ecx,%rcx
lea    (%rbx,%rcx,4),%rdi
movss  0x14(%rsp),%xmm0
mov    $0x4,%esi
call   1040 <calc_coeffs@plt>
mov    0x4(%rsp),%esi
add    $0x10,%rbx
add    $0x1,%r13d
cmp    %r13d,%esi
jne    1170 <scale_up_coeffs+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @scale_up_coeffs(i32 %0, i32 %1, float* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca float*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca float
store i32 %0, i32* %5
store i32 %1, i32* %6
store float* %2, float** %7
store i32* %3, i32** %8
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 1
store i32 %19, i32* %16
store i32 0, i32* %9
br label %20
20: ; preds = %66, %4
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %69
24: ; preds = %20
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = load i32, i32* %9
%28 = call i32 @split_map(i32 %25, i32 %26, i32 %27, float* %17)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = sub nsw i32 %29, 1
store i32 %30, i32* %11
%31 = load i32, i32* %10
%32 = add nsw i32 %31, 2
store i32 %32, i32* %12
%33 = load i32, i32* %12
%34 = load i32, i32* %16
%35 = call i32 @min(i32 %33, i32 %34)
store i32 %35, i32* %15
store i32 0, i32* %13
store i32 0, i32* %14
%36 = load i32, i32* %11
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %24
%39 = load i32, i32* %11
%40 = mul nsw i32 -1, %39
store i32 %40, i32* %13
br label %41
41: ; preds = %38, %24
%42 = load i32, i32* %12
%43 = load i32, i32* %16
%44 = icmp sgt i32 %42, %43
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load i32, i32* %12
%47 = load i32, i32* %16
%48 = sub nsw i32 %46, %47
store i32 %48, i32* %14
br label %49
49: ; preds = %45, %41
%50 = load i32*, i32** %8
%51 = load i32, i32* %15
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
%54 = load i32, i32* %53
%55 = add nsw i32 %54, 1
store i32 %55, i32* %53
%56 = load float*, float** %7
%57 = load i32, i32* %14
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds float, float* %56, i64 %58
%60 = load float, float* %17
%61 = load i32, i32* %13
%62 = load i32, i32* %14
%63 = call i32 @calc_coeffs(float* %59, float %60, i32 4, i32 %61, i32 %62)
%64 = load float*, float** %7
%65 = getelementptr inbounds float, float* %64, i64 4
store float* %65, float** %7
br label %66
66: ; preds = %49
%67 = load i32, i32* %9
%68 = add nsw i32 %67, 1
store i32 %68, i32* %9
br label %20
69: ; preds = %20
ret void
}

LLVM IR (-O2):
define void @scale_up_coeffs(i32 %0, i32 %1, float* %2, i32* nocapture %3) {
%5 = alloca float
%6 = bitcast float* %5 to i8*
%7 = add nsw i32 %0, -1
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %32
9: ; preds = %4, %9
%10 = phi float* [ %29, %9 ], [ %2, %4 ]
%11 = phi i32 [ %30, %9 ], [ 0, %4 ]
%12 = call i32 @split_map(i32 %0, i32 %1, i32 %11, float* %5)
%13 = add nsw i32 %12, 2
%14 = call i32 @min(i32 %13, i32 %7)
%15 = sub i32 1, %12
%16 = icmp sgt i32 %12, 0
%17 = select i1 %16, i32 0, i32 %15
%18 = icmp slt i32 %13, %0
%19 = sub nsw i32 %13, %7
%20 = select i1 %18, i32 0, i32 %19
%21 = sext i32 %14 to i64
%22 = getelementptr inbounds i32, i32* %3, i64 %21
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1
store i32 %24, i32* %22
%25 = sext i32 %20 to i64
%26 = getelementptr inbounds float, float* %10, i64 %25
%27 = load float, float* %5
%28 = call i32 @calc_coeffs(float* %26, float %27, i32 4, i32 %17, i32 %20)
%29 = getelementptr inbounds float, float* %10, i64 4
%30 = add nuw nsw i32 %11, 1
%31 = icmp eq i32 %30, %1
br i1 %31, label %32, label %9
32: ; preds = %9, %4
ret void
}