#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 /*<<< orphan*/ rawaudio_byte_order();
int rawaudio_swap_bytes(char *buffer, long samples, int channels, int bits) {
  long i;
  char byte1, byte2, byte3;
  char *buffer1, *buffer2, *buffer3;
  if (!rawaudio_byte_order())
    return 0;
  switch (bits) {
  case 8:
    break;
  case 16:
    buffer1 = buffer;
    buffer2 = buffer + 1;
    while (i < samples * 2) {
      byte1 = buffer2[i];
      buffer2[i] = buffer1[i];
      buffer1[i] = byte1;
      i += 2;
    }
    break;
  case 24:
    buffer1 = buffer;
    buffer2 = buffer + 2;
    while (i < samples * 3) {
      byte1 = buffer2[i];
      buffer2[i] = buffer1[i];
      buffer1[i] = byte1;
      i += 3;
    }
    break;
  default:
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rawaudio_swap_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    $0x0,%al
call   1030 <rawaudio_byte_order@plt>
cmp    $0x0,%eax
jne    1142 <rawaudio_swap_bytes+0x32>
movl   $0x0,-0x4(%rbp)
jmp    1268 <rawaudio_swap_bytes+0x158>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4c(%rbp)
sub    $0x8,%eax
je     1178 <rawaudio_swap_bytes+0x68>
jmp    1156 <rawaudio_swap_bytes+0x46>
mov    -0x4c(%rbp),%eax
sub    $0x10,%eax
je     117d <rawaudio_swap_bytes+0x6d>
jmp    1167 <rawaudio_swap_bytes+0x57>
mov    -0x4c(%rbp),%eax
sub    $0x18,%eax
je     11ee <rawaudio_swap_bytes+0xde>
jmp    125c <rawaudio_swap_bytes+0x14c>
jmp    1261 <rawaudio_swap_bytes+0x151>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x1,%rcx
cmp    %rcx,%rax
jge    11e9 <rawaudio_swap_bytes+0xd9>
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x29(%rbp),%dl
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    1191 <rawaudio_swap_bytes+0x81>
jmp    1261 <rawaudio_swap_bytes+0x151>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
imul   $0x3,-0x18(%rbp),%rcx
cmp    %rcx,%rax
jge    1257 <rawaudio_swap_bytes+0x147>
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x29(%rbp),%dl
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x28(%rbp)
jmp    1202 <rawaudio_swap_bytes+0xf2>
jmp    1261 <rawaudio_swap_bytes+0x151>
jmp    1261 <rawaudio_swap_bytes+0x151>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rawaudio_swap_bytes>:
push   %rax
xor    %eax,%eax
call   1030 <rawaudio_byte_order@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @rawaudio_swap_bytes(i8* %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%17 = call i32 (...) @rawaudio_byte_order()
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %4
store i32 0, i32* %5
br label %81
20: ; preds = %4
%21 = load i32, i32* %9
switch i32 %21, label %79 [
i32 8, label %22
i32 16, label %23
i32 24, label %51
]
22: ; preds = %20
br label %80
23: ; preds = %20
%24 = load i8*, i8** %6
store i8* %24, i8** %14
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %26, i8** %15
br label %27
27: ; preds = %32, %23
%28 = load i64, i64* %10
%29 = load i64, i64* %7
%30 = mul nsw i64 %29, 2
%31 = icmp slt i64 %28, %30
br i1 %31, label %32, label %50
32: ; preds = %27
%33 = load i8*, i8** %15
%34 = load i64, i64* %10
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = load i8, i8* %35
store i8 %36, i8* %11
%37 = load i8*, i8** %14
%38 = load i64, i64* %10
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i8, i8* %39
%41 = load i8*, i8** %15
%42 = load i64, i64* %10
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8 %40, i8* %43
%44 = load i8, i8* %11
%45 = load i8*, i8** %14
%46 = load i64, i64* %10
%47 = getelementptr inbounds i8, i8* %45, i64 %46
store i8 %44, i8* %47
%48 = load i64, i64* %10
%49 = add nsw i64 %48, 2
store i64 %49, i64* %10
br label %27
50: ; preds = %27
br label %80
51: ; preds = %20
%52 = load i8*, i8** %6
store i8* %52, i8** %14
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i64 2
store i8* %54, i8** %15
br label %55
55: ; preds = %60, %51
%56 = load i64, i64* %10
%57 = load i64, i64* %7
%58 = mul nsw i64 %57, 3
%59 = icmp slt i64 %56, %58
br i1 %59, label %60, label %78
60: ; preds = %55
%61 = load i8*, i8** %15
%62 = load i64, i64* %10
%63 = getelementptr inbounds i8, i8* %61, i64 %62
%64 = load i8, i8* %63
store i8 %64, i8* %11
%65 = load i8*, i8** %14
%66 = load i64, i64* %10
%67 = getelementptr inbounds i8, i8* %65, i64 %66
%68 = load i8, i8* %67
%69 = load i8*, i8** %15
%70 = load i64, i64* %10
%71 = getelementptr inbounds i8, i8* %69, i64 %70
store i8 %68, i8* %71
%72 = load i8, i8* %11
%73 = load i8*, i8** %14
%74 = load i64, i64* %10
%75 = getelementptr inbounds i8, i8* %73, i64 %74
store i8 %72, i8* %75
%76 = load i64, i64* %10
%77 = add nsw i64 %76, 3
store i64 %77, i64* %10
br label %55
78: ; preds = %55
br label %80
79: ; preds = %20
br label %80
80: ; preds = %79, %78, %50, %22
store i32 0, i32* %5
br label %81
81: ; preds = %80, %19
%82 = load i32, i32* %5
ret i32 %82
}

LLVM IR (-O2):
define i32 @rawaudio_swap_bytes(i8* nocapture %0, i64 %1, i32 %2, i32 %3) {
%5 = tail call i32 (...) @rawaudio_byte_order()
ret i32 0
}