#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 creat(char *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int);
char *map(char *, int *);
int /*<<< orphan*/ printf(char *);
short u2l(int);
int /*<<< orphan*/ wr(int, char *, int);
main(int argc, char *argv[]) {
  int fd;
  char *cp;
  int size;
  int i;
  int hdr_size;
  struct au_header {
    int magic;
    int hdr_size;
    int data_size;
    int encoding;
    int sample_rate;
    int channels;
  } au_header = {0x2e736e64, 24, 0, 3, 8000, 1};
  argc--;
  argv++;
  if (argc != 2) {
    printf("usage: <ulaw input file> <linear output file>\n");
    exit(1);
  }
  cp = map(argv[0], &size);
  hdr_size = *(int *)&cp[4];
  cp += hdr_size;
  size -= hdr_size;
  if ((fd = creat(argv[1], 0666)) < 0)
    error("creat");
  au_header.data_size = size * 2;
  wr(fd, (char *)&au_header, sizeof(struct au_header));
  for (i = 0; i < size; i++) {
    short v;
    v = u2l(*cp++ & 0xff);
    wr(fd, (char *)&v, 2);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe73(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe6d(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11dc <main+0x6c>
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <map@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x1b6,%esi
call   1080 <creat@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1240 <main+0xd0>
lea    0xe0c(%rip),%rdi
call   1070 <error@plt>
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x18,%edx
call   1060 <wr@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12ad <main+0x13d>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%edi
and    $0xff,%edi
call   1050 <u2l@plt>
mov    %ax,-0x4a(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x4a(%rbp),%rsi
mov    $0x2,%edx
call   1060 <wr@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1261 <main+0xf1>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xe8f(%rip),%rax
mov    %rax,0x20(%rsp)
movups 0xe73(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
cmp    $0x3,%edi
jne    1245 <main+0xd5>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1040 <map@plt>
mov    %rax,%r15
movslq 0x4(%rax),%r14
sub    %r14d,0x8(%rsp)
mov    0x10(%rbp),%rdi
mov    $0x1b6,%esi
call   1080 <creat@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11d8 <main+0x68>
lea    0xe45(%rip),%rdi
call   1070 <error@plt>
mov    0x8(%rsp),%eax
add    %eax,%eax
mov    %eax,0x18(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x18,%edx
call   1060 <wr@plt>
cmpl   $0x0,0x8(%rsp)
jle    1238 <main+0xc8>
add    %r14,%r15
xor    %ebx,%ebx
lea    0xe(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r15,%rbx,1),%edi
call   1050 <u2l@plt>
mov    %ax,0xe(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1060 <wr@plt>
add    $0x1,%rbx
cmp    0x8(%rsp),%ebx
jl     1210 <main+0xa0>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.au_header = type { i32, i32, i32, i32, i32, i32 }
@__const.main.au_header = %struct.au_header { i32 779316836, i32 24, i32 0, i32 3, i32 8000, i32 1 }
@.str = [47 x i8] c"usage: <ulaw input file> <linear output file>\0A\00"
@.str.1 = [6 x i8] c"creat\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.au_header
%12 = alloca i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast %struct.au_header* %11 to i8*
%14 = load i32, i32* %4
%15 = add nsw i32 %14, -1
store i32 %15, i32* %4
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i32 1
store i8** %17, i8*** %5
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i8* @map(i8* %26, i32* %8)
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 4
%30 = bitcast i8* %29 to i32*
%31 = load i32, i32* %30
store i32 %31, i32* %10
%32 = load i32, i32* %10
%33 = load i8*, i8** %7
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %7
%36 = load i32, i32* %10
%37 = load i32, i32* %8
%38 = sub nsw i32 %37, %36
store i32 %38, i32* %8
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @creat(i8* %41, i32 438)
store i32 %42, i32* %6
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %23
%45 = call i32 @error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %44, %23
%47 = load i32, i32* %8
%48 = mul nsw i32 %47, 2
%49 = getelementptr inbounds %struct.au_header, %struct.au_header* %11, i32 0, i32 2
store i32 %48, i32* %49
%50 = load i32, i32* %6
%51 = bitcast %struct.au_header* %11 to i8*
%52 = call i32 @wr(i32 %50, i8* %51, i32 24)
store i32 0, i32* %9
br label %53
53: ; preds = %67, %46
%54 = load i32, i32* %9
%55 = load i32, i32* %8
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %70
57: ; preds = %53
%58 = load i8*, i8** %7
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %7
%60 = load i8, i8* %58
%61 = sext i8 %60 to i32
%62 = and i32 %61, 255
%63 = call signext i16 @u2l(i32 %62)
store i16 %63, i16* %12
%64 = load i32, i32* %6
%65 = bitcast i16* %12 to i8*
%66 = call i32 @wr(i32 %64, i8* %65, i32 2)
br label %67
67: ; preds = %57
%68 = load i32, i32* %9
%69 = add nsw i32 %68, 1
store i32 %69, i32* %9
br label %53
70: ; preds = %53
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
%struct.au_header = type { i32, i32, i32, i32, i32, i32 }
@__const.main.au_header = %struct.au_header { i32 779316836, i32 24, i32 0, i32 3, i32 8000, i32 1 }
@.str.1 = [6 x i8] c"creat\00"
@str = [46 x i8] c"usage: <ulaw input file> <linear output file>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.au_header
%5 = alloca i16
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.au_header* %4 to i8*
%8 = icmp eq i32 %0, 3
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i8* @map(i8* %14, i32* %3)
%16 = getelementptr inbounds i8, i8* %15, i64 4
%17 = bitcast i8* %16 to i32*
%18 = load i32, i32* %17
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, %18
store i32 %22, i32* %3
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @creat(i8* %24, i32 438)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %12
%28 = call i32 @error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %12
%30 = load i32, i32* %3
%31 = shl nsw i32 %30, 1
%32 = getelementptr inbounds %struct.au_header, %struct.au_header* %4, i64 0, i32 2
store i32 %31, i32* %32
%33 = call i32 @wr(i32 %25, i8* %7, i32 24)
%34 = load i32, i32* %3
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %49
36: ; preds = %29
%37 = bitcast i16* %5 to i8*
br label %38
38: ; preds = %36, %38
%39 = phi i32 [ 0, %36 ], [ %46, %38 ]
%40 = phi i8* [ %20, %36 ], [ %41, %38 ]
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = load i8, i8* %40
%43 = zext i8 %42 to i32
%44 = call signext i16 @u2l(i32 %43)
store i16 %44, i16* %5
%45 = call i32 @wr(i32 %25, i8* %37, i32 2)
%46 = add nuw nsw i32 %39, 1
%47 = load i32, i32* %3
%48 = icmp slt i32 %46, %47
br i1 %48, label %38, label %49
49: ; preds = %38, %29
ret i32 0
}