#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_alaw(short);
void alaw_enc(char *s16_data, char *alaw_data, int pcm_size) {
  int i;
  int limit = pcm_size / 2;
  char s16[2];
  for (i = 0; i < limit; i++) {
    s16[0] = s16_data[1];
    s16[1] = s16_data[0];
    alaw_data[i] = s16_to_alaw(*((signed short *)s16));
    s16_data += 2;
  }
}


x86 assembly (clang, -O0):
<alaw_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    1187 <alaw_enc+0x77>
mov    -0x8(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x1e(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
movswl -0x1e(%rbp),%edi
call   1030 <s16_to_alaw@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 <alaw_enc+0x28>
add    $0x20,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
define void @alaw_enc(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = icmp sgt i32 %2, 1
br i1 %4, label %5, label %23
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 ], [ %21, %8 ]
%10 = phi i8* [ %0, %5 ], [ %20, %8 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = load i8, i8* %10
%14 = zext i8 %13 to i16
%15 = shl nuw i16 %14, 8
%16 = zext i8 %12 to i16
%17 = or i16 %15, %16
%18 = tail call signext i8 @s16_to_alaw(i16 signext %17)
%19 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %18, i8* %19
%20 = getelementptr inbounds i8, i8* %10, i64 2
%21 = add nuw nsw i64 %9, 1
%22 = icmp eq i64 %21, %7
br i1 %22, label %23, label %8
23: ; preds = %8, %3
ret void
}