#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 ulaw_encode(int);
void out_u8ulaw(char *dest, int *src, int num, int cod) {
  int smp;
  for (; num--; ++src, ++dest) {
    smp = *src >> (12 + 4);
    *dest = smp > 4095    ? ulaw_encode(4095)
            : smp < -4096 ? ulaw_encode(-4096)
                          : ulaw_encode(smp);
  }
}


x86 assembly (clang, -O0):
<out_u8ulaw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11c6 <out_u8ulaw+0xb6>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sar    $0x10,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0xfff,-0x1c(%rbp)
jle    1168 <out_u8ulaw+0x58>
mov    $0xfff,%edi
call   1030 <ulaw_encode@plt>
movsbl %al,%eax
mov    %eax,-0x20(%rbp)
jmp    119e <out_u8ulaw+0x8e>
cmpl   $0xfffff000,-0x1c(%rbp)
jge    118a <out_u8ulaw+0x7a>
mov    $0xfffff000,%edi
call   1030 <ulaw_encode@plt>
movsbl %al,%eax
mov    %eax,-0x24(%rbp)
jmp    1198 <out_u8ulaw+0x88>
mov    -0x1c(%rbp),%edi
call   1030 <ulaw_encode@plt>
movsbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1126 <out_u8ulaw+0x16>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<out_u8ulaw>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     116c <out_u8ulaw+0x5c>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
mov    $0xfffff000,%r13d
mov    $0xfff,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%rbx,4),%eax
mov    %eax,%edi
sar    $0x10,%edi
cmp    $0xf0000000,%eax
cmovl  %r13d,%edi
cmp    $0x10000000,%eax
cmovge %ebp,%edi
call   1030 <ulaw_encode@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    1140 <out_u8ulaw+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @out_u8ulaw(i8* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
br label %10
10: ; preds = %39, %4
%11 = load i32, i32* %7
%12 = add nsw i32 %11, -1
store i32 %12, i32* %7
%13 = icmp ne i32 %11, 0
br i1 %13, label %14, label %44
14: ; preds = %10
%15 = load i32*, i32** %6
%16 = load i32, i32* %15
%17 = ashr i32 %16, 16
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp sgt i32 %18, 4095
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call signext i8 @ulaw_encode(i32 4095)
%22 = sext i8 %21 to i32
br label %35
23: ; preds = %14
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, -4096
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call signext i8 @ulaw_encode(i32 -4096)
%28 = sext i8 %27 to i32
br label %33
29: ; preds = %23
%30 = load i32, i32* %9
%31 = call signext i8 @ulaw_encode(i32 %30)
%32 = sext i8 %31 to i32
br label %33
33: ; preds = %29, %26
%34 = phi i32 [ %28, %26 ], [ %32, %29 ]
br label %35
35: ; preds = %33, %20
%36 = phi i32 [ %22, %20 ], [ %34, %33 ]
%37 = trunc i32 %36 to i8
%38 = load i8*, i8** %5
store i8 %37, i8* %38
br label %39
39: ; preds = %35
%40 = load i32*, i32** %6
%41 = getelementptr inbounds i32, i32* %40, i32 1
store i32* %41, i32** %6
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %5
br label %10
44: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @out_u8ulaw(i8* nocapture writeonly %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 0
br i1 %5, label %21, label %6
6: ; preds = %4, %6
%7 = phi i32 [ %10, %6 ], [ %2, %4 ]
%8 = phi i8* [ %19, %6 ], [ %0, %4 ]
%9 = phi i32* [ %18, %6 ], [ %1, %4 ]
%10 = add nsw i32 %7, -1
%11 = load i32, i32* %9
%12 = ashr i32 %11, 16
%13 = icmp sgt i32 %11, 268435455
%14 = icmp slt i32 %11, -268435456
%15 = select i1 %14, i32 -4096, i32 %12
%16 = select i1 %13, i32 4095, i32 %15
%17 = tail call signext i8 @ulaw_encode(i32 %16)
store i8 %17, i8* %8
%18 = getelementptr inbounds i32, i32* %9, i64 1
%19 = getelementptr inbounds i8, i8* %8, i64 1
%20 = icmp eq i32 %10, 0
br i1 %20, label %21, label %6
21: ; preds = %6, %4
ret void
}