#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*/ temp64;
typedef int /*<<< orphan*/ temp32;
typedef int /*<<< orphan*/ temp16;
typedef int int64_t;
typedef int int32_t;
typedef int int16_t;

/* Variables and functions */
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ memcpy(int *, unsigned char *, int);
void WavpackNativeToBigEndian(void *data, char *format) {
  unsigned char *cp = (unsigned char *)data;
  int64_t temp64;
  int32_t temp32;
  int16_t temp16;
  while (*format) {
    switch (*format) {
    case 'D':
      memcpy(&temp64, cp, sizeof(temp64));
      *cp++ = (unsigned char)(temp64 >> 56);
      *cp++ = (unsigned char)(temp64 >> 48);
      *cp++ = (unsigned char)(temp64 >> 40);
      *cp++ = (unsigned char)(temp64 >> 32);
      *cp++ = (unsigned char)(temp64 >> 24);
      *cp++ = (unsigned char)(temp64 >> 16);
      *cp++ = (unsigned char)(temp64 >> 8);
      *cp++ = (unsigned char)temp64;
      break;
    case 'L':
      memcpy(&temp32, cp, sizeof(temp32));
      *cp++ = (unsigned char)(temp32 >> 24);
      *cp++ = (unsigned char)(temp32 >> 16);
      *cp++ = (unsigned char)(temp32 >> 8);
      *cp++ = (unsigned char)temp32;
      break;
    case 'S':
      memcpy(&temp16, cp, sizeof(temp16));
      *cp++ = (unsigned char)(temp16 >> 8);
      *cp++ = (unsigned char)temp16;
      break;
    default:
      if (isdigit(*format))
        cp += *format - '0';
      break;
    }
    format++;
  }
}


x86 assembly (clang, -O0):
<WavpackNativeToBigEndian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     136c <WavpackNativeToBigEndian+0x24c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x28(%rbp)
sub    $0x44,%eax
je     117f <WavpackNativeToBigEndian+0x5f>
jmp    115d <WavpackNativeToBigEndian+0x3d>
mov    -0x28(%rbp),%eax
sub    $0x4c,%eax
je     126b <WavpackNativeToBigEndian+0x14b>
jmp    116e <WavpackNativeToBigEndian+0x4e>
mov    -0x28(%rbp),%eax
sub    $0x53,%eax
je     12e3 <WavpackNativeToBigEndian+0x1c3>
jmp    1329 <WavpackNativeToBigEndian+0x209>
mov    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%eax
mov    $0x38,%ecx
sar    %cl,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x30,%ecx
sar    %cl,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x28,%ecx
sar    %cl,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x18,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x10,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    135b <WavpackNativeToBigEndian+0x23b>
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%eax
sar    $0x18,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
sar    $0x10,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    135b <WavpackNativeToBigEndian+0x23b>
mov    -0x18(%rbp),%rsi
lea    -0x24(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x24(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    135b <WavpackNativeToBigEndian+0x23b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     1356 <WavpackNativeToBigEndian+0x236>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
sub    $0x30,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    135b <WavpackNativeToBigEndian+0x23b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1138 <WavpackNativeToBigEndian+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WavpackNativeToBigEndian>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    (%rsi),%al
test   %al,%al
je     122e <WavpackNativeToBigEndian+0x10e>
mov    %rsi,%rbx
mov    %rdi,%r14
add    $0x1,%rbx
lea    0x8(%rsp),%r15
lea    0x4(%rsp),%r12
lea    0xc(%rsp),%r13
jmp    11a6 <WavpackNativeToBigEndian+0x86>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
movzbl 0x7(%rsp),%eax
mov    %al,(%r14)
movzbl 0x6(%rsp),%eax
mov    %al,0x1(%r14)
movzbl 0x5(%rsp),%eax
mov    %al,0x2(%r14)
movzbl 0x4(%rsp),%eax
mov    %al,0x3(%r14)
add    $0x4,%r14
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     122e <WavpackNativeToBigEndian+0x10e>
movsbl %al,%edi
cmp    $0x53,%edi
je     11e0 <WavpackNativeToBigEndian+0xc0>
cmp    $0x4c,%edi
je     1160 <WavpackNativeToBigEndian+0x40>
cmp    $0x44,%edi
jne    1210 <WavpackNativeToBigEndian+0xf0>
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    0xc(%rsp),%eax
bswap  %eax
mov    %eax,0x4(%r14)
add    $0x8,%r14
jmp    1197 <WavpackNativeToBigEndian+0x77>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
movzbl 0x9(%rsp),%eax
mov    %al,(%r14)
movzbl 0x8(%rsp),%eax
mov    %al,0x1(%r14)
add    $0x2,%r14
jmp    1197 <WavpackNativeToBigEndian+0x77>
nopw   0x0(%rax,%rax,1)
call   1030 <isdigit@plt>
test   %eax,%eax
je     1197 <WavpackNativeToBigEndian+0x77>
movsbq -0x1(%rbx),%rax
add    %rax,%r14
add    $0xffffffffffffffd0,%r14
jmp    1197 <WavpackNativeToBigEndian+0x77>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @WavpackNativeToBigEndian(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
store i8* %9, i8** %5
br label %10
10: ; preds = %108, %2
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %111
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
switch i32 %17, label %94 [
i32 68, label %18
i32 76, label %60
i32 83, label %82
]
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = call i32 @memcpy(i32* %6, i8* %19, i32 4)
%21 = load i32, i32* %6
%22 = ashr i32 %21, 56
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %5
store i8 %23, i8* %24
%26 = load i32, i32* %6
%27 = ashr i32 %26, 48
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %5
store i8 %28, i8* %29
%31 = load i32, i32* %6
%32 = ashr i32 %31, 40
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
store i8 %33, i8* %34
%36 = load i32, i32* %6
%37 = ashr i32 %36, 32
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %5
store i8 %38, i8* %39
%41 = load i32, i32* %6
%42 = ashr i32 %41, 24
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %5
store i8 %43, i8* %44
%46 = load i32, i32* %6
%47 = ashr i32 %46, 16
%48 = trunc i32 %47 to i8
%49 = load i8*, i8** %5
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %5
store i8 %48, i8* %49
%51 = load i32, i32* %6
%52 = ashr i32 %51, 8
%53 = trunc i32 %52 to i8
%54 = load i8*, i8** %5
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %5
store i8 %53, i8* %54
%56 = load i32, i32* %6
%57 = trunc i32 %56 to i8
%58 = load i8*, i8** %5
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %5
store i8 %57, i8* %58
br label %108
60: ; preds = %14
%61 = load i8*, i8** %5
%62 = call i32 @memcpy(i32* %7, i8* %61, i32 4)
%63 = load i32, i32* %7
%64 = ashr i32 %63, 24
%65 = trunc i32 %64 to i8
%66 = load i8*, i8** %5
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %5
store i8 %65, i8* %66
%68 = load i32, i32* %7
%69 = ashr i32 %68, 16
%70 = trunc i32 %69 to i8
%71 = load i8*, i8** %5
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %5
store i8 %70, i8* %71
%73 = load i32, i32* %7
%74 = ashr i32 %73, 8
%75 = trunc i32 %74 to i8
%76 = load i8*, i8** %5
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %5
store i8 %75, i8* %76
%78 = load i32, i32* %7
%79 = trunc i32 %78 to i8
%80 = load i8*, i8** %5
%81 = getelementptr inbounds i8, i8* %80, i32 1
store i8* %81, i8** %5
store i8 %79, i8* %80
br label %108
82: ; preds = %14
%83 = load i8*, i8** %5
%84 = call i32 @memcpy(i32* %8, i8* %83, i32 4)
%85 = load i32, i32* %8
%86 = ashr i32 %85, 8
%87 = trunc i32 %86 to i8
%88 = load i8*, i8** %5
%89 = getelementptr inbounds i8, i8* %88, i32 1
store i8* %89, i8** %5
store i8 %87, i8* %88
%90 = load i32, i32* %8
%91 = trunc i32 %90 to i8
%92 = load i8*, i8** %5
%93 = getelementptr inbounds i8, i8* %92, i32 1
store i8* %93, i8** %5
store i8 %91, i8* %92
br label %108
94: ; preds = %14
%95 = load i8*, i8** %4
%96 = load i8, i8* %95
%97 = call i32 @isdigit(i8 signext %96)
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %107
99: ; preds = %94
%100 = load i8*, i8** %4
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = sub nsw i32 %102, 48
%104 = load i8*, i8** %5
%105 = sext i32 %103 to i64
%106 = getelementptr inbounds i8, i8* %104, i64 %105
store i8* %106, i8** %5
br label %107
107: ; preds = %99, %94
br label %108
108: ; preds = %107, %82, %60, %18
%109 = load i8*, i8** %4
%110 = getelementptr inbounds i8, i8* %109, i32 1
store i8* %110, i8** %4
br label %10
111: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @WavpackNativeToBigEndian(i8* %0, i8* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 0
br i1 %10, label %70, label %11
11: ; preds = %2, %65
%12 = phi i8 [ %68, %65 ], [ %9, %2 ]
%13 = phi i8* [ %66, %65 ], [ %0, %2 ]
%14 = phi i8* [ %67, %65 ], [ %1, %2 ]
%15 = sext i8 %12 to i32
switch i32 %15, label %57 [
i32 68, label %16
i32 76, label %31
i32 83, label %48
]
16: ; preds = %11
%17 = call i32 @memcpy(i32* %3, i8* %13, i32 4)
%18 = getelementptr inbounds i8, i8* %13, i64 4
%19 = load i32, i32* %3
%20 = lshr i32 %19, 24
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds i8, i8* %13, i64 5
store i8 %21, i8* %18
%23 = lshr i32 %19, 16
%24 = trunc i32 %23 to i8
%25 = getelementptr inbounds i8, i8* %13, i64 6
store i8 %24, i8* %22
%26 = lshr i32 %19, 8
%27 = trunc i32 %26 to i8
%28 = getelementptr inbounds i8, i8* %13, i64 7
store i8 %27, i8* %25
%29 = trunc i32 %19 to i8
%30 = getelementptr inbounds i8, i8* %13, i64 8
store i8 %29, i8* %28
br label %65
31: ; preds = %11
%32 = call i32 @memcpy(i32* %4, i8* %13, i32 4)
%33 = load i32, i32* %4
%34 = lshr i32 %33, 24
%35 = trunc i32 %34 to i8
%36 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %35, i8* %13
%37 = load i32, i32* %4
%38 = lshr i32 %37, 16
%39 = trunc i32 %38 to i8
%40 = getelementptr inbounds i8, i8* %13, i64 2
store i8 %39, i8* %36
%41 = load i32, i32* %4
%42 = lshr i32 %41, 8
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds i8, i8* %13, i64 3
store i8 %43, i8* %40
%45 = load i32, i32* %4
%46 = trunc i32 %45 to i8
%47 = getelementptr inbounds i8, i8* %13, i64 4
store i8 %46, i8* %44
br label %65
48: ; preds = %11
%49 = call i32 @memcpy(i32* %5, i8* %13, i32 4)
%50 = load i32, i32* %5
%51 = lshr i32 %50, 8
%52 = trunc i32 %51 to i8
%53 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %52, i8* %13
%54 = load i32, i32* %5
%55 = trunc i32 %54 to i8
%56 = getelementptr inbounds i8, i8* %13, i64 2
store i8 %55, i8* %53
br label %65
57: ; preds = %11
%58 = call i32 @isdigit(i8 signext %12)
%59 = icmp eq i32 %58, 0
br i1 %59, label %65, label %60
60: ; preds = %57
%61 = load i8, i8* %14
%62 = sext i8 %61 to i64
%63 = add nsw i64 %62, -48
%64 = getelementptr inbounds i8, i8* %13, i64 %63
br label %65
65: ; preds = %57, %60, %48, %31, %16
%66 = phi i8* [ %64, %60 ], [ %13, %57 ], [ %56, %48 ], [ %47, %31 ], [ %30, %16 ]
%67 = getelementptr inbounds i8, i8* %14, i64 1
%68 = load i8, i8* %67
%69 = icmp eq i8 %68, 0
br i1 %69, label %70, label %11
70: ; preds = %65, %2
ret void
}