#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 */
char s16_to_ulaw(short);
void mulaw_enc(char *s16_data, char *mulaw_data, int pcm_size) {
  int i;
  int limit = pcm_size / 2;
  for (i = 0; i < limit; i++) {
    mulaw_data[i] = s16_to_ulaw(*((signed short *)s16_data));
    s16_data += 2;
  }
}


x86 assembly (clang, -O0):
<mulaw_enc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1177 <mulaw_enc+0x67>
mov    -0x8(%rbp),%rax
movswl (%rax),%edi
call   1030 <s16_to_ulaw@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1138 <mulaw_enc+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mulaw_enc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edx
jl     1147 <mulaw_enc+0x37>
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
shr    %r12d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movswl (%r15,%rbx,2),%edi
call   1030 <s16_to_ulaw@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <mulaw_enc+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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