#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 fread(char *, int, int, int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ puts(char *);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  char frm[2];
  unsigned count;
  if (argc != 3) {
    puts("Usage: swapendian input.pcm OUTPUT.PCM");
    return 1;
  }
  in = fopen(argv[1], "rb");
  if (!in) {
    puts("Open error");
    return 1;
  }
  out = fopen(argv[2], "wb");
  if (!out) {
    puts("Open error");
    fclose(in);
    return 1;
  }
  count = 0;
  for (;;) {
    char tmp;
    if (fread(frm, 2, 1, in) != 1)
      break;
    tmp = frm[0];
    frm[0] = frm[1];
    frm[1] = tmp;
    if (fwrite(frm, 2, 1, out) != 1) {
      puts("Write error");
      break;
    }
    ++count;
  }
  printf("%d samples converted\n", count);
  fclose(in);
  fclose(out);
  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   $0x3,-0x8(%rbp)
je     1198 <main+0x38>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bc <main+0x15c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d3 <main+0x73>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bc <main+0x15c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe53(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1217 <main+0xb7>
lea    0xe2d(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bc <main+0x15c>
movl   $0x0,-0x28(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     1243 <main+0xe3>
jmp    1294 <main+0x134>
mov    -0x22(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x21(%rbp),%al
mov    %al,-0x22(%rbp)
mov    -0x29(%rbp),%al
mov    %al,-0x21(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
cmp    $0x1,%eax
je     1286 <main+0x126>
lea    0xdbc(%rip),%rdi
call   1030 <puts@plt>
jmp    1294 <main+0x134>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    121e <main+0xbe>
mov    -0x28(%rbp),%esi
lea    0xda6(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    121f <main+0xbf>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1228 <main+0xc8>
mov    %rax,%r12
mov    0x10(%rbx),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     123c <main+0xdc>
mov    %rax,%r14
lea    0xe(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
xor    %r15d,%r15d
mov    $0x0,%ebp
cmp    $0x1,%eax
jne    1264 <main+0x104>
xor    %ebp,%ebp
lea    0xe(%rsp),%rbx
nop
rolw   $0x8,0xe(%rsp)
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
cmp    $0x1,%eax
jne    1258 <main+0xf8>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     11e0 <main+0x80>
jmp    1264 <main+0x104>
lea    0xdda(%rip),%rdi
jmp    122f <main+0xcf>
lea    0xdfb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r15d
jmp    1282 <main+0x122>
lea    0xde7(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    $0x1,%r15d
jmp    1282 <main+0x122>
lea    0xdd9(%rip),%rdi
call   1030 <puts@plt>
lea    0xdd9(%rip),%rdi
mov    %ebp,%esi
call   1060 <printf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Usage: swapendian input.pcm OUTPUT.PCM\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [11 x i8] c"Open error\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [12 x i8] c"Write error\00"
@.str.5 = [22 x i8] c"%d samples converted\0A\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 [2 x i8]
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @puts(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %66
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %66
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %28, i32** %7
%29 = load i32*, i32** %7
%30 = icmp ne i32* %29, null
br i1 %30, label %35, label %31
31: ; preds = %24
%32 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
store i32 1, i32* %3
br label %66
35: ; preds = %24
store i32 0, i32* %9
br label %36
36: ; preds = %56, %35
%37 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%38 = load i32*, i32** %6
%39 = call i32 @fread(i8* %37, i32 2, i32 1, i32* %38)
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %42
41: ; preds = %36
br label %59
42: ; preds = %36
%43 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%44 = load i8, i8* %43
store i8 %44, i8* %10
%45 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
%46 = load i8, i8* %45
%47 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
store i8 %46, i8* %47
%48 = load i8, i8* %10
%49 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
store i8 %48, i8* %49
%50 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%51 = load i32*, i32** %7
%52 = call i32 @fwrite(i8* %50, i32 2, i32 1, i32* %51)
%53 = icmp ne i32 %52, 1
br i1 %53, label %54, label %56
54: ; preds = %42
%55 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %59
56: ; preds = %42
%57 = load i32, i32* %9
%58 = add i32 %57, 1
store i32 %58, i32* %9
br label %36
59: ; preds = %54, %41
%60 = load i32, i32* %9
%61 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %60)
%62 = load i32*, i32** %6
%63 = call i32 @fclose(i32* %62)
%64 = load i32*, i32** %7
%65 = call i32 @fclose(i32* %64)
store i32 0, i32* %3
br label %66
66: ; preds = %59, %31, %22, %13
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [39 x i8] c"Usage: swapendian input.pcm OUTPUT.PCM\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [11 x i8] c"Open error\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [12 x i8] c"Write error\00"
@.str.5 = [22 x i8] c"%d samples converted\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %45
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %45
15: ; preds = %8
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %25, label %20
20: ; preds = %15
%21 = call i32 @fread(i8* %4, i32 2, i32 1, i32* %11)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
br label %28
25: ; preds = %15
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 @fclose(i32* %11)
br label %45
28: ; preds = %23, %36
%29 = phi i32 [ 0, %23 ], [ %37, %36 ]
%30 = load i8, i8* %4
%31 = load i8, i8* %24
store i8 %31, i8* %4
store i8 %30, i8* %24
%32 = call i32 @fwrite(i8* %4, i32 2, i32 1, i32* %18)
%33 = icmp eq i32 %32, 1
br i1 %33, label %36, label %34
34: ; preds = %28
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %40
36: ; preds = %28
%37 = add i32 %29, 1
%38 = call i32 @fread(i8* %4, i32 2, i32 1, i32* %11)
%39 = icmp eq i32 %38, 1
br i1 %39, label %28, label %40
40: ; preds = %36, %20, %34
%41 = phi i32 [ %29, %34 ], [ 0, %20 ], [ %37, %36 ]
%42 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = tail call i32 @fclose(i32* %11)
%44 = tail call i32 @fclose(i32* %18)
br label %45
45: ; preds = %40, %25, %13, %6
%46 = phi i32 [ 1, %6 ], [ 0, %40 ], [ 1, %25 ], [ 1, %13 ]
ret i32 %46
}