#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*/ memcpy(unsigned char *, char *, int);
char *strchr(char *, char);
void *strtol(char *, char **, int);
void raop_prepare_pcm(unsigned char *header, char *format, unsigned long *sr,
                      unsigned char *c, unsigned long *s) {
  unsigned long samplerate = 0;
  unsigned char channels = 0;
  unsigned char bits = 0;
  char *str;
  memcpy(header, "RIFF", 4);
  memcpy(header + 12, "fmt", 4);
  header[21] = 1;
  str = strchr(format, ' ');
  if (str != NULL) {
    str += 2;
    bits = strtol(str, &str, 10);
    str++;
    samplerate = strtol(str, &str, 10);
    str++;
    channels = strtol(str, NULL, 10);
  }
  if (samplerate == 0)
    samplerate = 44100;
  if (channels == 0)
    channels = 2;
  if (bits == 0)
    bits = 16;
  header[23] = channels;
  header[24] = samplerate >> 24;
  header[25] = samplerate >> 16;
  header[26] = samplerate >> 8;
  header[27] = samplerate;
  header[35] = bits;
  if (sr != NULL)
    *sr = samplerate;
  if (c != NULL)
    *c = channels;
  if (s != NULL)
    *s = 352;
}


x86 assembly (clang, -O0):
<raop_prepare_pcm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movb   $0x0,-0x31(%rbp)
movb   $0x0,-0x32(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0xc,%rdi
lea    0xe85(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
movb   $0x1,0x15(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1213 <raop_prepare_pcm+0xe3>
mov    -0x40(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %al,-0x32(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %al,-0x31(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1226 <raop_prepare_pcm+0xf6>
movq   $0xac44,-0x30(%rbp)
movzbl -0x31(%rbp),%eax
cmp    $0x0,%eax
jne    1237 <raop_prepare_pcm+0x107>
movb   $0x2,-0x31(%rbp)
movzbl -0x32(%rbp),%eax
cmp    $0x0,%eax
jne    1248 <raop_prepare_pcm+0x118>
movb   $0x10,-0x32(%rbp)
mov    -0x31(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x17(%rax)
mov    -0x30(%rbp),%rax
shr    $0x18,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x18(%rax)
mov    -0x30(%rbp),%rax
shr    $0x10,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x19(%rax)
mov    -0x30(%rbp),%rax
shr    $0x8,%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1a(%rax)
mov    -0x30(%rbp),%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1b(%rax)
mov    -0x32(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x23(%rax)
cmpq   $0x0,-0x18(%rbp)
je     12b2 <raop_prepare_pcm+0x182>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     12c6 <raop_prepare_pcm+0x196>
mov    -0x31(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     12dc <raop_prepare_pcm+0x1ac>
mov    -0x28(%rbp),%rax
movq   $0x160,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raop_prepare_pcm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xeaf(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
lea    0xc(%rbp),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
movb   $0x1,0x15(%rbp)
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11df <raop_prepare_pcm+0xaf>
add    $0x2,%rax
mov    %rax,(%rsp)
mov    %rsp,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%r13
mov    (%rsp),%rdi
add    $0x1,%rdi
mov    %rdi,(%rsp)
mov    %rbx,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
mov    (%rsp),%rdi
add    $0x1,%rdi
mov    %rdi,(%rsp)
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
test   %rbx,%rbx
jne    11e9 <raop_prepare_pcm+0xb9>
jmp    11e4 <raop_prepare_pcm+0xb4>
xor    %r13d,%r13d
xor    %eax,%eax
mov    $0xac44,%ebx
test   %al,%al
movzbl %al,%ecx
mov    $0x2,%eax
cmovne %ecx,%eax
test   %r13b,%r13b
movzbl %r13b,%ecx
mov    $0x10,%edx
cmovne %ecx,%edx
mov    %al,0x17(%rbp)
mov    %rbx,%rcx
shr    $0x18,%rcx
mov    %cl,0x18(%rbp)
mov    %rbx,%rcx
shr    $0x10,%rcx
mov    %cl,0x19(%rbp)
mov    %bh,0x1a(%rbp)
mov    %bl,0x1b(%rbp)
mov    %dl,0x23(%rbp)
test   %r12,%r12
je     122e <raop_prepare_pcm+0xfe>
mov    %rbx,(%r12)
test   %r15,%r15
je     1236 <raop_prepare_pcm+0x106>
mov    %al,(%r15)
test   %r14,%r14
je     1242 <raop_prepare_pcm+0x112>
movq   $0x160,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"RIFF\00"
@.str.1 = [4 x i8] c"fmt\00"
define void @raop_prepare_pcm(i8* %0, i8* %1, i64* %2, i8* %3, i64* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64*
%9 = alloca i8*
%10 = alloca i64*
%11 = alloca i64
%12 = alloca i8
%13 = alloca i8
%14 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64* %2, i64** %8
store i8* %3, i8** %9
store i64* %4, i64** %10
store i64 0, i64* %11
store i8 0, i8* %12
store i8 0, i8* %13
%15 = load i8*, i8** %6
%16 = call i32 @memcpy(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 12
%19 = call i32 @memcpy(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 21
store i8 1, i8* %21
%22 = load i8*, i8** %7
%23 = call i8* @strchr(i8* %22, i8 signext 32)
store i8* %23, i8** %14
%24 = load i8*, i8** %14
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %42
26: ; preds = %5
%27 = load i8*, i8** %14
%28 = getelementptr inbounds i8, i8* %27, i64 2
store i8* %28, i8** %14
%29 = load i8*, i8** %14
%30 = call i8* @strtol(i8* %29, i8** %14, i32 10)
%31 = ptrtoint i8* %30 to i8
store i8 %31, i8* %13
%32 = load i8*, i8** %14
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %14
%34 = load i8*, i8** %14
%35 = call i8* @strtol(i8* %34, i8** %14, i32 10)
%36 = ptrtoint i8* %35 to i64
store i64 %36, i64* %11
%37 = load i8*, i8** %14
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %14
%39 = load i8*, i8** %14
%40 = call i8* @strtol(i8* %39, i8** null, i32 10)
%41 = ptrtoint i8* %40 to i8
store i8 %41, i8* %12
br label %42
42: ; preds = %26, %5
%43 = load i64, i64* %11
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %42
store i64 44100, i64* %11
br label %46
46: ; preds = %45, %42
%47 = load i8, i8* %12
%48 = zext i8 %47 to i32
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %46
store i8 2, i8* %12
br label %51
51: ; preds = %50, %46
%52 = load i8, i8* %13
%53 = zext i8 %52 to i32
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %51
store i8 16, i8* %13
br label %56
56: ; preds = %55, %51
%57 = load i8, i8* %12
%58 = load i8*, i8** %6
%59 = getelementptr inbounds i8, i8* %58, i64 23
store i8 %57, i8* %59
%60 = load i64, i64* %11
%61 = lshr i64 %60, 24
%62 = trunc i64 %61 to i8
%63 = load i8*, i8** %6
%64 = getelementptr inbounds i8, i8* %63, i64 24
store i8 %62, i8* %64
%65 = load i64, i64* %11
%66 = lshr i64 %65, 16
%67 = trunc i64 %66 to i8
%68 = load i8*, i8** %6
%69 = getelementptr inbounds i8, i8* %68, i64 25
store i8 %67, i8* %69
%70 = load i64, i64* %11
%71 = lshr i64 %70, 8
%72 = trunc i64 %71 to i8
%73 = load i8*, i8** %6
%74 = getelementptr inbounds i8, i8* %73, i64 26
store i8 %72, i8* %74
%75 = load i64, i64* %11
%76 = trunc i64 %75 to i8
%77 = load i8*, i8** %6
%78 = getelementptr inbounds i8, i8* %77, i64 27
store i8 %76, i8* %78
%79 = load i8, i8* %13
%80 = load i8*, i8** %6
%81 = getelementptr inbounds i8, i8* %80, i64 35
store i8 %79, i8* %81
%82 = load i64*, i64** %8
%83 = icmp ne i64* %82, null
br i1 %83, label %84, label %87
84: ; preds = %56
%85 = load i64, i64* %11
%86 = load i64*, i64** %8
store i64 %85, i64* %86
br label %87
87: ; preds = %84, %56
%88 = load i8*, i8** %9
%89 = icmp ne i8* %88, null
br i1 %89, label %90, label %93
90: ; preds = %87
%91 = load i8, i8* %12
%92 = load i8*, i8** %9
store i8 %91, i8* %92
br label %93
93: ; preds = %90, %87
%94 = load i64*, i64** %10
%95 = icmp ne i64* %94, null
br i1 %95, label %96, label %98
96: ; preds = %93
%97 = load i64*, i64** %10
store i64 352, i64* %97
br label %98
98: ; preds = %96, %93
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"RIFF\00"
@.str.1 = [4 x i8] c"fmt\00"
define void @raop_prepare_pcm(i8* %0, i8* %1, i64* writeonly %2, i8* writeonly %3, i64* writeonly %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
%8 = tail call i32 @memcpy(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%9 = getelementptr inbounds i8, i8* %0, i64 12
%10 = tail call i32 @memcpy(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%11 = getelementptr inbounds i8, i8* %0, i64 21
store i8 1, i8* %11
%12 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 32)
%13 = icmp eq i8* %12, null
br i1 %13, label %29, label %14
14: ; preds = %5
%15 = getelementptr inbounds i8, i8* %12, i64 2
store i8* %15, i8** %6
%16 = call i8* @strtol(i8* %15, i8** %6, i32 10)
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i8
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8* %20, i8** %6
%21 = call i8* @strtol(i8* %20, i8** %6, i32 10)
%22 = ptrtoint i8* %21 to i64
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8* %24, i8** %6
%25 = tail call i8* @strtol(i8* nocapture %24, i8** null, i32 10)
%26 = ptrtoint i8* %25 to i64
%27 = trunc i64 %26 to i8
%28 = icmp eq i8* %21, null
br i1 %28, label %29, label %32
29: ; preds = %5, %14
%30 = phi i8 [ %18, %14 ], [ 0, %5 ]
%31 = phi i8 [ %27, %14 ], [ 0, %5 ]
br label %32
32: ; preds = %14, %29
%33 = phi i8 [ %30, %29 ], [ %18, %14 ]
%34 = phi i8 [ %31, %29 ], [ %27, %14 ]
%35 = phi i64 [ 44100, %29 ], [ %22, %14 ]
%36 = icmp eq i8 %34, 0
%37 = select i1 %36, i8 2, i8 %34
%38 = icmp eq i8 %33, 0
%39 = select i1 %38, i8 16, i8 %33
%40 = getelementptr inbounds i8, i8* %0, i64 23
store i8 %37, i8* %40
%41 = lshr i64 %35, 24
%42 = trunc i64 %41 to i8
%43 = getelementptr inbounds i8, i8* %0, i64 24
store i8 %42, i8* %43
%44 = lshr i64 %35, 16
%45 = trunc i64 %44 to i8
%46 = getelementptr inbounds i8, i8* %0, i64 25
store i8 %45, i8* %46
%47 = lshr i64 %35, 8
%48 = trunc i64 %47 to i8
%49 = getelementptr inbounds i8, i8* %0, i64 26
store i8 %48, i8* %49
%50 = trunc i64 %35 to i8
%51 = getelementptr inbounds i8, i8* %0, i64 27
store i8 %50, i8* %51
%52 = getelementptr inbounds i8, i8* %0, i64 35
store i8 %39, i8* %52
%53 = icmp eq i64* %2, null
br i1 %53, label %55, label %54
54: ; preds = %32
store i64 %35, i64* %2
br label %55
55: ; preds = %54, %32
%56 = icmp eq i8* %3, null
br i1 %56, label %58, label %57
57: ; preds = %55
store i8 %37, i8* %3
br label %58
58: ; preds = %57, %55
%59 = icmp eq i64* %4, null
br i1 %59, label %61, label %60
60: ; preds = %58
store i64 352, i64* %4
br label %61
61: ; preds = %60, %58
ret void
}