#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int mp3_play(char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char const *, char *);
char *strrchr(char const *, char);
int wav_play(char const *);
int wav_rec(char const *, unsigned int, unsigned int);
int main(int argc, char **argv) {
  const char *fn = 0;
  int play = 1;
  unsigned channels = 1;
  unsigned rate = 44100;
  argc--;
  argv++;
  while (argc > 0) {
    if (!strcmp(argv[0], "-rec")) {
      play = 0;
    } else if (!strcmp(argv[0], "-play")) {
      play = 1;
    } else if (!strcmp(argv[0], "-stereo")) {
      channels = 2;
    } else if (!strcmp(argv[0], "-mono")) {
      channels = 1;
    } else if (!strcmp(argv[0], "-rate")) {
      argc--;
      argv++;
      if (argc == 0) {
        fprintf(stderr, "playwav: -rate requires a parameter\n");
        return -1;
      }
      rate = atoi(argv[0]);
    } else {
      fn = argv[0];
    }
    argc--;
    argv++;
  }
  if (fn == 0) {
    fn = play ? "/data/out.wav" : "/data/rec.wav";
  }
  if (play) {
    const char *dot = strrchr(fn, '.');
    if (dot && !strcmp(dot, ".mp3")) {
      return mp3_play(fn);
    } else {
      return wav_play(fn);
    }
  } else {
    return wav_rec(fn, channels, rate);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0xac44,-0x24(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    130b <main+0x19b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe30(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11ea <main+0x7a>
movl   $0x0,-0x1c(%rbp)
jmp    12f1 <main+0x181>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe0d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1212 <main+0xa2>
movl   $0x1,-0x1c(%rbp)
jmp    12ec <main+0x17c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdeb(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    123a <main+0xca>
movl   $0x2,-0x20(%rbp)
jmp    12e7 <main+0x177>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdcb(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1262 <main+0xf2>
movl   $0x1,-0x20(%rbp)
jmp    12e2 <main+0x172>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xda9(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    12d2 <main+0x162>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    12be <main+0x14e>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a6 <main+0x236>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    12dd <main+0x16d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    12e2 <main+0x172>
jmp    12e7 <main+0x177>
jmp    12ec <main+0x17c>
jmp    12f1 <main+0x181>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    11b8 <main+0x48>
cmpq   $0x0,-0x18(%rbp)
jne    1332 <main+0x1c2>
mov    -0x1c(%rbp),%edx
lea    0xd32(%rip),%rax
lea    0xd1d(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1394 <main+0x224>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1383 <main+0x213>
mov    -0x30(%rbp),%rdi
lea    0xcfc(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1383 <main+0x213>
mov    -0x18(%rbp),%rdi
call   1080 <mp3_play@plt>
mov    %eax,-0x4(%rbp)
jmp    13a6 <main+0x236>
mov    -0x18(%rbp),%rdi
call   1070 <wav_play@plt>
mov    %eax,-0x4(%rbp)
jmp    13a6 <main+0x236>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1060 <wav_rec@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     128a <main+0x11a>
mov    %rsi,%r14
mov    %edi,%r13d
movl   $0x1,0x8(%rsp)
movl   $0xac44,0xc(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
mov    $0x1,%r15d
jmp    11c2 <main+0x52>
nopl   0x0(%rax)
xor    %r15d,%r15d
mov    %rbp,%r14
mov    %ebx,%r13d
cmp    $0x1,%ebx
jle    1293 <main+0x123>
lea    0x8(%r14),%rbp
lea    -0x1(%r13),%ebx
mov    0x8(%r14),%r12
mov    %r12,%rdi
lea    0xe28(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11b0 <main+0x40>
mov    %r12,%rdi
lea    0xe1a(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1240 <main+0xd0>
mov    %r12,%rdi
lea    0xe0d(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     124b <main+0xdb>
mov    %r12,%rdi
lea    0xe02(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1258 <main+0xe8>
mov    %r12,%rdi
lea    0xdf5(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1265 <main+0xf5>
mov    %r12,0x10(%rsp)
jmp    11b3 <main+0x43>
nopw   0x0(%rax,%rax,1)
mov    $0x1,%r15d
jmp    11b3 <main+0x43>
movl   $0x2,0x8(%rsp)
jmp    11b3 <main+0x43>
movl   $0x1,0x8(%rsp)
jmp    11b3 <main+0x43>
add    $0xfffffffe,%r13d
je     1328 <main+0x1b8>
add    $0x10,%r14
mov    (%r14),%rdi
call   1090 <atoi@plt>
mov    %eax,0xc(%rsp)
mov    %r13d,%ebx
mov    %r14,%rbp
jmp    11b3 <main+0x43>
lea    0xdb3(%rip),%rbx
jmp    12b9 <main+0x149>
test   %r15d,%r15d
lea    0xdb5(%rip),%rax
lea    0xda0(%rip),%rbx
cmove  %rax,%rbx
mov    0x10(%rsp),%rax
test   %rax,%rax
cmovne %rax,%rbx
test   %r15d,%r15d
je     130a <main+0x19a>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     12de <main+0x16e>
lea    0xd8e(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     12f4 <main+0x184>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <wav_play@plt>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <mp3_play@plt>
mov    %rbx,%rdi
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <wav_rec@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
lea    0xce7(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"-rec\00"
@.str.1 = [6 x i8] c"-play\00"
@.str.2 = [8 x i8] c"-stereo\00"
@.str.3 = [6 x i8] c"-mono\00"
@.str.4 = [6 x i8] c"-rate\00"
@stderr = global i32 0
@.str.5 = [37 x i8] c"playwav: -rate requires a parameter\0A\00"
@.str.6 = [14 x i8] c"/data/out.wav\00"
@.str.7 = [14 x i8] c"/data/rec.wav\00"
@.str.8 = [5 x i8] c".mp3\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 1, i32* %7
store i32 1, i32* %8
store i32 44100, i32* %9
%11 = load i32, i32* %4
%12 = add nsw i32 %11, -1
store i32 %12, i32* %4
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i32 1
store i8** %14, i8*** %5
br label %15
15: ; preds = %75, %2
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %80
18: ; preds = %15
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @strcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %18
store i32 0, i32* %7
br label %75
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %25
store i32 1, i32* %7
br label %74
32: ; preds = %25
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @strcmp(i8* %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %32
store i32 2, i32* %8
br label %73
39: ; preds = %32
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @strcmp(i8* %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp ne i32 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %39
store i32 1, i32* %8
br label %72
46: ; preds = %39
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 0
%49 = load i8*, i8** %48
%50 = call i32 @strcmp(i8* %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%51 = icmp ne i32 %50, 0
br i1 %51, label %67, label %52
52: ; preds = %46
%53 = load i32, i32* %4
%54 = add nsw i32 %53, -1
store i32 %54, i32* %4
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i32 1
store i8** %56, i8*** %5
%57 = load i32, i32* %4
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %52
%60 = load i32, i32* @stderr
%61 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %111
62: ; preds = %52
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 0
%65 = load i8*, i8** %64
%66 = call i32 @atoi(i8* %65)
store i32 %66, i32* %9
br label %71
67: ; preds = %46
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 0
%70 = load i8*, i8** %69
store i8* %70, i8** %6
br label %71
71: ; preds = %67, %62
br label %72
72: ; preds = %71, %45
br label %73
73: ; preds = %72, %38
br label %74
74: ; preds = %73, %31
br label %75
75: ; preds = %74, %24
%76 = load i32, i32* %4
%77 = add nsw i32 %76, -1
store i32 %77, i32* %4
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i32 1
store i8** %79, i8*** %5
br label %15
80: ; preds = %15
%81 = load i8*, i8** %6
%82 = icmp eq i8* %81, null
br i1 %82, label %83, label %88
83: ; preds = %80
%84 = load i32, i32* %7
%85 = icmp ne i32 %84, 0
%86 = zext i1 %85 to i64
%87 = select i1 %85, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0)
store i8* %87, i8** %6
br label %88
88: ; preds = %83, %80
%89 = load i32, i32* %7
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %106
91: ; preds = %88
%92 = load i8*, i8** %6
%93 = call i8* @strrchr(i8* %92, i8 signext 46)
store i8* %93, i8** %10
%94 = load i8*, i8** %10
%95 = icmp ne i8* %94, null
br i1 %95, label %96, label %103
96: ; preds = %91
%97 = load i8*, i8** %10
%98 = call i32 @strcmp(i8* %97, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%99 = icmp ne i32 %98, 0
br i1 %99, label %103, label %100
100: ; preds = %96
%101 = load i8*, i8** %6
%102 = call i32 @mp3_play(i8* %101)
store i32 %102, i32* %3
br label %111
103: ; preds = %96, %91
%104 = load i8*, i8** %6
%105 = call i32 @wav_play(i8* %104)
store i32 %105, i32* %3
br label %111
106: ; preds = %88
%107 = load i8*, i8** %6
%108 = load i32, i32* %8
%109 = load i32, i32* %9
%110 = call i32 @wav_rec(i8* %107, i32 %108, i32 %109)
store i32 %110, i32* %3
br label %111
111: ; preds = %106, %103, %100, %59
%112 = load i32, i32* %3
ret i32 %112
}

LLVM IR (-O2):
@.str = [5 x i8] c"-rec\00"
@.str.1 = [6 x i8] c"-play\00"
@.str.2 = [8 x i8] c"-stereo\00"
@.str.3 = [6 x i8] c"-mono\00"
@.str.4 = [6 x i8] c"-rate\00"
@stderr = global i32 0
@.str.5 = [37 x i8] c"playwav: -rate requires a parameter\0A\00"
@.str.6 = [14 x i8] c"/data/out.wav\00"
@.str.7 = [14 x i8] c"/data/rec.wav\00"
@.str.8 = [5 x i8] c".mp3\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %51
4: ; preds = %2, %38
%5 = phi i32 [ %44, %38 ], [ 44100, %2 ]
%6 = phi i32 [ %43, %38 ], [ 1, %2 ]
%7 = phi i32 [ %42, %38 ], [ 1, %2 ]
%8 = phi i8* [ %41, %38 ], [ null, %2 ]
%9 = phi i8** [ %40, %38 ], [ %1, %2 ]
%10 = phi i32 [ %39, %38 ], [ %0, %2 ]
%11 = getelementptr inbounds i8*, i8** %9, i64 1
%12 = add nsw i32 %10, -1
%13 = load i8*, i8** %11
%14 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %38, label %16
16: ; preds = %4
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %38, label %19
19: ; preds = %16
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %38, label %22
22: ; preds = %19
%23 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %38, label %25
25: ; preds = %22
%26 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = add nsw i32 %10, -2
%30 = getelementptr inbounds i8*, i8** %9, i64 2
%31 = icmp eq i32 %29, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %64
35: ; preds = %28
%36 = load i8*, i8** %30
%37 = tail call i32 @atoi(i8* %36)
br label %38
38: ; preds = %25, %22, %19, %16, %4, %35
%39 = phi i32 [ %29, %35 ], [ %12, %4 ], [ %12, %16 ], [ %12, %19 ], [ %12, %22 ], [ %12, %25 ]
%40 = phi i8** [ %30, %35 ], [ %11, %4 ], [ %11, %16 ], [ %11, %19 ], [ %11, %22 ], [ %11, %25 ]
%41 = phi i8* [ %8, %35 ], [ %8, %4 ], [ %8, %16 ], [ %8, %19 ], [ %8, %22 ], [ %13, %25 ]
%42 = phi i32 [ %7, %35 ], [ 0, %4 ], [ 1, %16 ], [ %7, %19 ], [ %7, %22 ], [ %7, %25 ]
%43 = phi i32 [ %6, %35 ], [ %6, %4 ], [ %6, %16 ], [ 2, %19 ], [ 1, %22 ], [ %6, %25 ]
%44 = phi i32 [ %37, %35 ], [ %5, %4 ], [ %5, %16 ], [ %5, %19 ], [ %5, %22 ], [ %5, %25 ]
%45 = icmp sgt i32 %39, 1
br i1 %45, label %4, label %46
46: ; preds = %38
%47 = icmp eq i8* %41, null
%48 = icmp eq i32 %42, 0
%49 = select i1 %48, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0)
%50 = select i1 %47, i8* %49, i8* %41
br i1 %48, label %62, label %51
51: ; preds = %2, %46
%52 = phi i8* [ %50, %46 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), %2 ]
%53 = tail call i8* @strrchr(i8* dereferenceable(1) %52, i8 signext 46)
%54 = icmp eq i8* %53, null
br i1 %54, label %60, label %55
55: ; preds = %51
%56 = tail call i32 @strcmp(i8* %53, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = tail call i32 @mp3_play(i8* %52)
br label %64
60: ; preds = %55, %51
%61 = tail call i32 @wav_play(i8* %52)
br label %64
62: ; preds = %46
%63 = tail call i32 @wav_rec(i8* %50, i32 %43, i32 %44)
br label %64
64: ; preds = %58, %60, %62, %32
%65 = phi i32 [ -1, %32 ], [ %63, %62 ], [ %61, %60 ], [ %59, %58 ]
ret i32 %65
}