#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 */
unsigned char cst_short_to_ulaw(short);
void add_residual_pulse(int targ_size, unsigned char *targ_residual,
                        int unit_size, const unsigned char *unit_residual) {
  if (unit_size < targ_size)
    targ_residual[((targ_size - unit_size) / 2)] =
        cst_short_to_ulaw((short)(int)unit_residual);
  else
    targ_residual[((unit_size - targ_size) / 2)] =
        cst_short_to_ulaw((short)(int)unit_residual);
}


x86 assembly (clang, -O0):
<add_residual_pulse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    116b <add_residual_pulse+0x5b>
mov    -0x20(%rbp),%rax
movswl %ax,%edi
call   1030 <cst_short_to_ulaw@plt>
mov    %al,-0x29(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x29(%rbp),%dl
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    119f <add_residual_pulse+0x8f>
mov    -0x20(%rbp),%rax
movswl %ax,%edi
call   1030 <cst_short_to_ulaw@plt>
mov    %al,-0x39(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x39(%rbp),%dl
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_residual_pulse>:
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edx,%eax
sub    %edi,%eax
neg    %eax
sub    %edi,%ebx
movswl %cx,%edi
cmovl  %eax,%ebx
call   1030 <cst_short_to_ulaw@plt>
mov    %ebx,%ecx
shr    $0x1f,%ecx
add    %ebx,%ecx
sar    %ecx
movslq %ecx,%rcx
mov    %al,(%r14,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @add_residual_pulse(i32 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %24
12: ; preds = %4
%13 = load i8*, i8** %8
%14 = ptrtoint i8* %13 to i32
%15 = trunc i32 %14 to i16
%16 = call zeroext i8 @cst_short_to_ulaw(i16 signext %15)
%17 = load i8*, i8** %6
%18 = load i32, i32* %5
%19 = load i32, i32* %7
%20 = sub nsw i32 %18, %19
%21 = sdiv i32 %20, 2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %17, i64 %22
store i8 %16, i8* %23
br label %36
24: ; preds = %4
%25 = load i8*, i8** %8
%26 = ptrtoint i8* %25 to i32
%27 = trunc i32 %26 to i16
%28 = call zeroext i8 @cst_short_to_ulaw(i16 signext %27)
%29 = load i8*, i8** %6
%30 = load i32, i32* %7
%31 = load i32, i32* %5
%32 = sub nsw i32 %30, %31
%33 = sdiv i32 %32, 2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %29, i64 %34
store i8 %28, i8* %35
br label %36
36: ; preds = %24, %12
ret void
}

LLVM IR (-O2):
define void @add_residual_pulse(i32 %0, i8* nocapture writeonly %1, i32 %2, i8* %3) {
%5 = icmp slt i32 %2, %0
%6 = ptrtoint i8* %3 to i64
%7 = trunc i64 %6 to i16
%8 = tail call zeroext i8 @cst_short_to_ulaw(i16 signext %7)
%9 = sub nsw i32 %2, %0
%10 = sub nsw i32 %0, %2
%11 = select i1 %5, i32 %10, i32 %9
%12 = sdiv i32 %11, 2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %8, i8* %14
ret void
}