#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*/ process(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int, int,
                           int, int /*<<< orphan*/);
int sscanf(char *, char *, int *, char *);
int main(int argc, char **argv) {
  FILE *fi, *fo;
  int freq, adpcm, stereo;
  char c;
  if (argc != 6) {
    printf("Usage:\nunraw infile.raw outfile.wav compressed freq "
           "stereo\n\ncompressed: 0 - raw; 1 - adpcm\nfreq: 11025; 22050; "
           "44100\nstereo: 0 - mono; 1 - stereo\n\n");
    return 1;
  }
  if (sscanf(argv[3], "%u%c", &adpcm, &c) != 1)
    return 1;
  if (sscanf(argv[4], "%u%c", &freq, &c) != 1)
    return 1;
  if ((freq < 0) || (freq > 96000))
    return 1;
  if (sscanf(argv[5], "%u%c", &stereo, &c) != 1)
    return 1;
  if ((stereo < 0) || (stereo > 1))
    return 1;
  if (fi = fopen(argv[1], "rb")) {
    if (fo = fopen(argv[2], "wb")) {
      process(fi, fo, adpcm, freq, stereo, 0);
      fclose(fo);
    }
    fclose(fi);
  }
  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)
cmpl   $0x6,-0x8(%rbp)
je     1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d5 <main+0x185>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xefd(%rip),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2d(%rbp),%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11b9 <main+0x69>
movl   $0x1,-0x4(%rbp)
jmp    12d5 <main+0x185>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xecc(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x2d(%rbp),%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11ea <main+0x9a>
movl   $0x1,-0x4(%rbp)
jmp    12d5 <main+0x185>
cmpl   $0x0,-0x24(%rbp)
jl     1201 <main+0xb1>
cmpl   $0x17700,-0x24(%rbp)
jle    120d <main+0xbd>
movl   $0x1,-0x4(%rbp)
jmp    12d5 <main+0x185>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
lea    0xe78(%rip),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x2d(%rbp),%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     123e <main+0xee>
movl   $0x1,-0x4(%rbp)
jmp    12d5 <main+0x185>
cmpl   $0x0,-0x2c(%rbp)
jl     1252 <main+0x102>
cmpl   $0x1,-0x2c(%rbp)
jle    125e <main+0x10e>
movl   $0x1,-0x4(%rbp)
jmp    12d5 <main+0x185>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12ce <main+0x17e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe0d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12c5 <main+0x175>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
xor    %r9d,%r9d
call   1050 <process@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x6,%edi
jne    1242 <main+0xf2>
mov    %rsi,%rbx
mov    0x18(%rsi),%rdi
lea    0xe91(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x3(%rsp),%rcx
call   1060 <sscanf@plt>
mov    $0x1,%ebp
cmp    $0x1,%eax
jne    1253 <main+0x103>
mov    0x20(%rbx),%rdi
lea    0xe69(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x3(%rsp),%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1253 <main+0x103>
cmpl   $0x17700,0x8(%rsp)
ja     1253 <main+0x103>
mov    0x28(%rbx),%rdi
lea    0xe38(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x3(%rsp),%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1253 <main+0x103>
cmpl   $0x1,0x4(%rsp)
ja     1253 <main+0x103>
mov    0x8(%rbx),%rdi
lea    0xe17(%rip),%rsi
call   1070 <fopen@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1253 <main+0x103>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe00(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1238 <main+0xe8>
mov    %rax,%rbx
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0x4(%rsp),%r8d
mov    %r14,%rdi
mov    %rax,%rsi
xor    %r9d,%r9d
call   1050 <process@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    1253 <main+0x103>
lea    0xdc2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [148 x i8] c"Usage:\0Aunraw infile.raw outfile.wav compressed freq stereo\0A\0Acompressed: 0 - raw; 1 - adpcm\0Afreq: 11025; 22050; 44100\0Astereo: 0 - mono; 1 - stereo\0A\0A\00"
@.str.1 = [5 x i8] c"%u%c\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 6
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %76
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 3
%19 = load i8*, i8** %18
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %9, i8* %11)
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 1, i32* %3
br label %76
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 4
%26 = load i8*, i8** %25
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %8, i8* %11)
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 1, i32* %3
br label %76
30: ; preds = %23
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i32, i32* %8
%35 = icmp sgt i32 %34, 96000
br i1 %35, label %36, label %37
36: ; preds = %33, %30
store i32 1, i32* %3
br label %76
37: ; preds = %33
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 5
%40 = load i8*, i8** %39
%41 = call i32 @sscanf(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %10, i8* %11)
%42 = icmp ne i32 %41, 1
br i1 %42, label %43, label %44
43: ; preds = %37
store i32 1, i32* %3
br label %76
44: ; preds = %37
%45 = load i32, i32* %10
%46 = icmp slt i32 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %44
%48 = load i32, i32* %10
%49 = icmp sgt i32 %48, 1
br i1 %49, label %50, label %51
50: ; preds = %47, %44
store i32 1, i32* %3
br label %76
51: ; preds = %47
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i32* @fopen(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %55, i32** %6
%56 = icmp ne i32* %55, null
br i1 %56, label %57, label %75
57: ; preds = %51
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 2
%60 = load i8*, i8** %59
%61 = call i32* @fopen(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %61, i32** %7
%62 = icmp ne i32* %61, null
br i1 %62, label %63, label %72
63: ; preds = %57
%64 = load i32*, i32** %6
%65 = load i32*, i32** %7
%66 = load i32, i32* %9
%67 = load i32, i32* %8
%68 = load i32, i32* %10
%69 = call i32 @process(i32* %64, i32* %65, i32 %66, i32 %67, i32 %68, i32 0)
%70 = load i32*, i32** %7
%71 = call i32 @fclose(i32* %70)
br label %72
72: ; preds = %63, %57
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
br label %75
75: ; preds = %72, %51
store i32 0, i32* %3
br label %76
76: ; preds = %75, %50, %43, %36, %29, %22, %14
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%u%c\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [3 x i8] c"wb\00"
@str = [147 x i8] c"Usage:\0Aunraw infile.raw outfile.wav compressed freq stereo\0A\0Acompressed: 0 - raw; 1 - adpcm\0Afreq: 11025; 22050; 44100\0Astereo: 0 - mono; 1 - stereo\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = icmp eq i32 %0, 6
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([147 x i8], [147 x i8]* @str, i64 0, i64 0))
br label %52
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %4, i8* %6)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %52
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 4
%20 = load i8*, i8** %19
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8* %6)
%22 = icmp ne i32 %21, 1
%23 = load i32, i32* %3
%24 = icmp ugt i32 %23, 96000
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %52, label %26
26: ; preds = %18
%27 = getelementptr inbounds i8*, i8** %1, i64 5
%28 = load i8*, i8** %27
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %5, i8* %6)
%30 = icmp ne i32 %29, 1
%31 = load i32, i32* %5
%32 = icmp ugt i32 %31, 1
%33 = select i1 %30, i1 true, i1 %32
br i1 %33, label %52, label %34
34: ; preds = %26
%35 = getelementptr inbounds i8*, i8** %1, i64 1
%36 = load i8*, i8** %35
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i32* %37, null
br i1 %38, label %52, label %39
39: ; preds = %34
%40 = getelementptr inbounds i8*, i8** %1, i64 2
%41 = load i8*, i8** %40
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp eq i32* %42, null
br i1 %43, label %50, label %44
44: ; preds = %39
%45 = load i32, i32* %4
%46 = load i32, i32* %3
%47 = load i32, i32* %5
%48 = call i32 @process(i32* %37, i32* %42, i32 %45, i32 %46, i32 %47, i32 0)
%49 = call i32 @fclose(i32* %42)
br label %50
50: ; preds = %44, %39
%51 = call i32 @fclose(i32* %37)
br label %52
52: ; preds = %34, %50, %26, %18, %13, %11
%53 = phi i32 [ 1, %11 ], [ 1, %13 ], [ 1, %18 ], [ 1, %26 ], [ 0, %50 ], [ 0, %34 ]
ret i32 %53
}