#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ write_law(int /*<<< orphan*/ *, char *, unsigned char);
int main(int argc, char *argv[]) {
  FILE *fp;
  if (argc <= 1) {
  usage:
    printf("Usage:\n");
    printf("%s ulaw2wave <alaw file> <wav file>\n", argv[0]);
    printf("%s alaw2wave <alaw file> <wav file>\n", argv[0]);
    return (0);
  }
  if (!strcmp(argv[1], "alaw2wave")) {
    if (argc <= 3)
      goto usage;
    if ((fp = fopen(argv[3], "w"))) {
      write_law(fp, argv[2], 'a');
      fclose(fp);
    } else {
      printf("Cannot open wave file %s\n", argv[3]);
    }
  } else if (!strcmp(argv[1], "ulaw2wave")) {
    if (argc <= 3)
      goto usage;
    if ((fp = fopen(argv[3], "w"))) {
      write_law(fp, argv[2], 'u');
      fclose(fp);
    } else {
      printf("Cannot open wave file %s\n", argv[3]);
    }
  } else
    goto usage;
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11b9 <main+0x69>
jmp    1175 <main+0x25>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e4 <main+0x194>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1246 <main+0xf6>
cmpl   $0x3,-0x8(%rbp)
jg     11e5 <main+0x95>
jmp    1175 <main+0x25>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe68(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     122b <main+0xdb>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x61,%edx
call   1060 <write_law@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1241 <main+0xf1>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12dd <main+0x18d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe23(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    12d3 <main+0x183>
cmpl   $0x3,-0x8(%rbp)
jg     1272 <main+0x122>
jmp    1175 <main+0x25>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xddb(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12b8 <main+0x168>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x75,%edx
call   1060 <write_law@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    12ce <main+0x17e>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d8 <main+0x188>
jmp    1175 <main+0x25>
jmp    12dd <main+0x18d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x1,%edi
jg     11a1 <main+0x41>
lea    0xf07(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%rsi
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%rsi
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %edi,%ebp
mov    0x8(%r14),%rbx
lea    0xe9c(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11f8 <main+0x98>
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
cmp    $0x4,%ebp
jb     116c <main+0xc>
test   %eax,%eax
jne    116c <main+0xc>
mov    0x18(%r14),%rdi
lea    0xe77(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1237 <main+0xd7>
mov    %rax,%rbp
mov    0x10(%r14),%rsi
mov    %rax,%rdi
mov    $0x75,%edx
jmp    1225 <main+0xc5>
cmp    $0x4,%ebp
jb     116c <main+0xc>
mov    0x18(%r14),%rdi
lea    0xe48(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1237 <main+0xd7>
mov    %rax,%rbp
mov    0x10(%r14),%rsi
mov    %rax,%rdi
mov    $0x61,%edx
call   1070 <write_law@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    119a <main+0x3a>
mov    0x18(%r14),%rsi
lea    0xe14(%rip),%rdi
jmp    1193 <main+0x33>

LLVM IR (-O0):
@.str = [8 x i8] c"Usage:\0A\00"
@.str.1 = [37 x i8] c"%s ulaw2wave <alaw file> <wav file>\0A\00"
@.str.2 = [37 x i8] c"%s alaw2wave <alaw file> <wav file>\0A\00"
@.str.3 = [10 x i8] c"alaw2wave\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [26 x i8] c"Cannot open wave file %s\0A\00"
@.str.6 = [10 x i8] c"ulaw2wave\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp sle i32 %7, 1
br i1 %8, label %9, label %20
9: ; preds = %2
br label %10
10: ; preds = %80, %59, %29, %9
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %18)
store i32 0, i32* %3
br label %83
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %50, label %26
26: ; preds = %20
%27 = load i32, i32* %4
%28 = icmp sle i32 %27, 3
br i1 %28, label %29, label %30
29: ; preds = %26
br label %10
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %34, i32** %6
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %44
36: ; preds = %30
%37 = load i32*, i32** %6
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @write_law(i32* %37, i8* %40, i8 zeroext 97)
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
br label %49
44: ; preds = %30
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 3
%47 = load i8*, i8** %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %44, %36
br label %82
50: ; preds = %20
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32 @strcmp(i8* %53, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%55 = icmp ne i32 %54, 0
br i1 %55, label %80, label %56
56: ; preds = %50
%57 = load i32, i32* %4
%58 = icmp sle i32 %57, 3
br i1 %58, label %59, label %60
59: ; preds = %56
br label %10
60: ; preds = %56
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 3
%63 = load i8*, i8** %62
%64 = call i32* @fopen(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %64, i32** %6
%65 = icmp ne i32* %64, null
br i1 %65, label %66, label %74
66: ; preds = %60
%67 = load i32*, i32** %6
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 2
%70 = load i8*, i8** %69
%71 = call i32 @write_law(i32* %67, i8* %70, i8 zeroext 117)
%72 = load i32*, i32** %6
%73 = call i32 @fclose(i32* %72)
br label %79
74: ; preds = %60
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 3
%77 = load i8*, i8** %76
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %77)
br label %79
79: ; preds = %74, %66
br label %81
80: ; preds = %50
br label %10
81: ; preds = %79
br label %82
82: ; preds = %81, %49
store i32 0, i32* %3
br label %83
83: ; preds = %82, %10
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str.1 = [37 x i8] c"%s ulaw2wave <alaw file> <wav file>\0A\00"
@.str.2 = [37 x i8] c"%s alaw2wave <alaw file> <wav file>\0A\00"
@.str.3 = [10 x i8] c"alaw2wave\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [26 x i8] c"Cannot open wave file %s\0A\00"
@.str.6 = [10 x i8] c"ulaw2wave\00"
@str = [7 x i8] c"Usage:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %10
4: ; preds = %30, %15, %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %48
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %10
%16 = icmp ult i32 %0, 4
br i1 %16, label %4, label %17
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i32 @write_law(i32* %20, i8* %24, i8 zeroext 97)
%26 = tail call i32 @fclose(i32* %20)
br label %48
27: ; preds = %17
%28 = load i8*, i8** %18
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %28)
br label %48
30: ; preds = %10
%31 = tail call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
%33 = icmp ult i32 %0, 4
%34 = or i1 %33, %32
br i1 %34, label %4, label %35
35: ; preds = %30
%36 = getelementptr inbounds i8*, i8** %1, i64 3
%37 = load i8*, i8** %36
%38 = tail call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp eq i32* %38, null
br i1 %39, label %45, label %40
40: ; preds = %35
%41 = getelementptr inbounds i8*, i8** %1, i64 2
%42 = load i8*, i8** %41
%43 = tail call i32 @write_law(i32* %38, i8* %42, i8 zeroext 117)
%44 = tail call i32 @fclose(i32* %38)
br label %48
45: ; preds = %35
%46 = load i8*, i8** %36
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %27, %22, %40, %45, %4
ret i32 0
}