#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 */
double cubic(double, int, int, int, int);
void expand_line(double *dest, double *src, int bytes, int old_width,
                 int width) {
  double ratio;
  int x, b;
  int src_col;
  double frac;
  double *s;
  ratio = old_width / (double)width;
  for (x = 0; x < width; ++x) {
    src_col = ((int)(x * ratio + 2.0 - 0.5)) - 2;
    frac = (x * ratio - 0.5) - src_col;
    s = &src[src_col * bytes];
    for (b = 0; b < bytes; b++)
      dest[b] = cubic(frac, (int)s[b - bytes], (int)s[b], (int)s[b + bytes],
                      (int)s[b + bytes * 2]);
    dest += bytes;
  }
}


x86 assembly (clang, -O0):
<expand_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1267 <expand_line+0x157>
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xeaa(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe96(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
sub    $0x2,%eax
mov    %eax,-0x34(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe6a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsi2sdl -0x34(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
imul   -0x14(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1244 <expand_line+0x134>
movsd  -0x40(%rbp),%xmm0
mov    -0x48(%rbp),%rax
mov    -0x30(%rbp),%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
cvttsd2si (%rax,%rcx,8),%edi
mov    -0x48(%rbp),%rax
movslq -0x30(%rbp),%rcx
cvttsd2si (%rax,%rcx,8),%esi
mov    -0x48(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
cvttsd2si (%rax,%rcx,8),%edx
mov    -0x48(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    -0x14(%rbp),%r8d
shl    $0x1,%r8d
add    %r8d,%ecx
movslq %ecx,%rcx
cvttsd2si (%rax,%rcx,8),%ecx
call   1030 <cubic@plt>
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11c8 <expand_line+0xb8>
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1144 <expand_line+0x34>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,0x18(%rsp)
mov    %r8d,0xc(%rsp)
test   %r8d,%r8d
jle    127c <expand_line+0x16c>
mov    %rdi,%r15
cvtsi2sd %ecx,%xmm1
cvtsi2sdl 0xc(%rsp),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x40(%rsp)
mov    0x10(%rsp),%rcx
lea    (%rcx,%rcx,1),%eax
movslq %ecx,%rdx
cltq
mov    %edx,%ebp
mov    0x18(%rsp),%rcx
lea    (%rcx,%rax,8),%rax
mov    %rax,0x30(%rsp)
lea    (%rcx,%rdx,8),%rax
mov    %rax,0x28(%rsp)
shl    $0x3,%rdx
mov    %rdx,0x38(%rsp)
sub    %rdx,%rcx
mov    %rcx,0x20(%rsp)
xor    %eax,%eax
xorpd  %xmm0,%xmm0
jmp    11b5 <expand_line+0xa5>
nopl   0x0(%rax)
movsd  0x48(%rsp),%xmm0
addsd  0xe72(%rip),%xmm0
mov    0x50(%rsp),%rax
add    $0x1,%eax
add    0x38(%rsp),%r15
cmp    0xc(%rsp),%eax
je     127c <expand_line+0x16c>
mov    %rax,0x50(%rsp)
movsd  %xmm0,0x48(%rsp)
mulsd  0x40(%rsp),%xmm0
movapd %xmm0,%xmm2
addsd  0xe2e(%rip),%xmm0
cmpl   $0x0,0x10(%rsp)
jle    1190 <expand_line+0x80>
movsd  0xe27(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0xfffffffe,%eax
addsd  %xmm1,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
imul   0x10(%rsp),%eax
subsd  %xmm0,%xmm2
movsd  %xmm2,0x60(%rsp)
cltq
mov    0x18(%rsp),%rcx
lea    (%rcx,%rax,8),%rcx
mov    %rcx,0x58(%rsp)
mov    0x30(%rsp),%rcx
lea    (%rcx,%rax,8),%r12
mov    0x28(%rsp),%rcx
lea    (%rcx,%rax,8),%r13
mov    0x20(%rsp),%rcx
lea    (%rcx,%rax,8),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cvttsd2si (%r14,%rbx,8),%edi
mov    0x58(%rsp),%rax
cvttsd2si (%rax,%rbx,8),%esi
cvttsd2si 0x0(%r13,%rbx,8),%edx
cvttsd2si (%r12,%rbx,8),%ecx
movsd  0x60(%rsp),%xmm0
call   1030 <cubic@plt>
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1240 <expand_line+0x130>
jmp    1190 <expand_line+0x80>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @expand_line(double* nocapture writeonly %0, double* nocapture %1, i32 %2, i32 %3, i32 %4) {
%6 = sitofp i32 %3 to double
%7 = sitofp i32 %4 to double
%8 = fdiv double %6, %7
%9 = icmp sgt i32 %4, 0
br i1 %9, label %10, label %55
10: ; preds = %5
%11 = icmp sgt i32 %2, 0
%12 = shl nsw i32 %2, 1
%13 = sext i32 %2 to i64
%14 = sext i32 %12 to i64
%15 = zext i32 %2 to i64
br label %16
16: ; preds = %10, %51
%17 = phi double* [ %0, %10 ], [ %52, %51 ]
%18 = phi i32 [ 0, %10 ], [ %53, %51 ]
%19 = sitofp i32 %18 to double
%20 = tail call double @llvm.fmuladd.f64(double %19, double %8, double 2.000000e+00)
%21 = fadd double %20, -5.000000e-01
%22 = fptosi double %21 to i32
%23 = add nsw i32 %22, -2
%24 = tail call double @llvm.fmuladd.f64(double %19, double %8, double -5.000000e-01)
%25 = sitofp i32 %23 to double
%26 = fsub double %24, %25
%27 = mul nsw i32 %23, %2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %1, i64 %28
br i1 %11, label %30, label %51
30: ; preds = %16, %30
%31 = phi i64 [ %49, %30 ], [ 0, %16 ]
%32 = sub nsw i64 %31, %13
%33 = getelementptr inbounds double, double* %29, i64 %32
%34 = load double, double* %33
%35 = fptosi double %34 to i32
%36 = getelementptr inbounds double, double* %29, i64 %31
%37 = load double, double* %36
%38 = fptosi double %37 to i32
%39 = add nsw i64 %31, %13
%40 = getelementptr inbounds double, double* %29, i64 %39
%41 = load double, double* %40
%42 = fptosi double %41 to i32
%43 = add nsw i64 %31, %14
%44 = getelementptr inbounds double, double* %29, i64 %43
%45 = load double, double* %44
%46 = fptosi double %45 to i32
%47 = tail call double @cubic(double %26, i32 %35, i32 %38, i32 %42, i32 %46)
%48 = getelementptr inbounds double, double* %17, i64 %31
store double %47, double* %48
%49 = add nuw nsw i64 %31, 1
%50 = icmp eq i64 %49, %15
br i1 %50, label %51, label %30
51: ; preds = %30, %16
%52 = getelementptr inbounds double, double* %17, i64 %13
%53 = add nuw nsw i32 %18, 1
%54 = icmp eq i32 %53, %4
br i1 %54, label %55, label %16
55: ; preds = %51, %5
ret void
}