#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 abs_max(int, int);
int pioneer_send_command1(int, int);
int pioneer_vel2(int vl, int vr) {
  int arg;
  int absmax;
  absmax = abs_max(vl, vr);
  if (absmax > 127) {
    float scale_factor;
    scale_factor = 127.0 / ((float)absmax);
    vl = (int)(scale_factor * ((float)vl));
    vr = (int)(scale_factor * ((float)vr));
  }
  arg = 256 * vl + vr;
  return pioneer_send_command1(32, arg);
}


x86 assembly (clang, -O0):
<pioneer_vel2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <abs_max@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x7f,-0x10(%rbp)
jle    118e <pioneer_vel2+0x6e>
cvtsi2ssl -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xea9(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtsi2ssl -0x4(%rbp),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
movss  -0x14(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x8,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    $0x20,%edi
call   1030 <pioneer_send_command1@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pioneer_vel2>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
call   1040 <abs_max@plt>
movd   %ebp,%xmm1
movd   %ebx,%xmm0
punpckldq %xmm1,%xmm0
cmp    $0x80,%eax
jl     1160 <pioneer_vel2+0x40>
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
movss  0xeb2(%rip),%xmm2
divss  %xmm1,%xmm2
cvtdq2ps %xmm0,%xmm0
shufps $0x0,%xmm2,%xmm2
mulps  %xmm0,%xmm2
cvttps2dq %xmm2,%xmm0
pshufd $0x55,%xmm0,%xmm1
movd   %xmm1,%eax
shl    $0x8,%eax
movd   %xmm0,%esi
add    %eax,%esi
mov    $0x20,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <pioneer_send_command1@plt>

LLVM IR (-O0):
define i32 @pioneer_vel2(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = call i32 @abs_max(i32 %8, i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 127
br i1 %12, label %13, label %29
13: ; preds = %2
%14 = load i32, i32* %6
%15 = sitofp i32 %14 to float
%16 = fpext float %15 to double
%17 = fdiv double 1.270000e+02, %16
%18 = fptrunc double %17 to float
store float %18, float* %7
%19 = load float, float* %7
%20 = load i32, i32* %3
%21 = sitofp i32 %20 to float
%22 = fmul float %19, %21
%23 = fptosi float %22 to i32
store i32 %23, i32* %3
%24 = load float, float* %7
%25 = load i32, i32* %4
%26 = sitofp i32 %25 to float
%27 = fmul float %24, %26
%28 = fptosi float %27 to i32
store i32 %28, i32* %4
br label %29
29: ; preds = %13, %2
%30 = load i32, i32* %3
%31 = mul nsw i32 256, %30
%32 = load i32, i32* %4
%33 = add nsw i32 %31, %32
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = call i32 @pioneer_send_command1(i32 32, i32 %34)
ret i32 %35
}

LLVM IR (-O2):
define i32 @pioneer_vel2(i32 %0, i32 %1) {
%3 = tail call i32 @abs_max(i32 %0, i32 %1)
%4 = icmp sgt i32 %3, 127
%5 = insertelement <2 x i32> poison, i32 %1, i64 0
%6 = insertelement <2 x i32> %5, i32 %0, i64 1
br i1 %4, label %7, label %15
7: ; preds = %2
%8 = sitofp i32 %3 to float
%9 = fdiv float 1.270000e+02, %8
%10 = sitofp <2 x i32> %6 to <2 x float>
%11 = insertelement <2 x float> poison, float %9, i64 0
%12 = shufflevector <2 x float> %11, <2 x float> poison, <2 x i32> zeroinitializer
%13 = fmul <2 x float> %12, %10
%14 = fptosi <2 x float> %13 to <2 x i32>
br label %15
15: ; preds = %7, %2
%16 = phi <2 x i32> [ %14, %7 ], [ %6, %2 ]
%17 = extractelement <2 x i32> %16, i64 1
%18 = shl nsw i32 %17, 8
%19 = extractelement <2 x i32> %16, i64 0
%20 = add nsw i32 %18, %19
%21 = tail call i32 @pioneer_send_command1(i32 32, i32 %20)
ret i32 %21
}