#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 uint8_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ reflect32(int /*<<< orphan*/);
int reflect8(int);
void reverse(void *payload, uint8_t bit_size) {
  assert(bit_size == 8 || bit_size == 32);
  switch (bit_size) {
  case 8:
    *((uint8_t *)payload) = reflect8(*((uint8_t *)payload));
    break;
  case 32:
    *((uint32_t *)payload) = reflect32(*((uint32_t *)payload));
    break;
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x1,%al
cmpl   $0x8,-0xc(%rbp)
mov    %al,-0xd(%rbp)
je     1158 <reverse+0x28>
cmpl   $0x20,-0xc(%rbp)
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
movzbl %al,%edi
and    $0x1,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x8,%eax
je     118b <reverse+0x5b>
jmp    117a <reverse+0x4a>
mov    -0x14(%rbp),%eax
sub    $0x20,%eax
je     11a3 <reverse+0x73>
jmp    11b6 <reverse+0x86>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <reflect8@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11b6 <reverse+0x86>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <reflect32@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
cmp    $0x8,%esi
sete   %al
cmp    $0x20,%esi
sete   %cl
or     %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
cmp    $0x20,%ebp
je     1161 <reverse+0x31>
cmp    $0x8,%ebp
jne    116a <reverse+0x3a>
mov    (%rbx),%edi
call   1030 <reflect8@plt>
jmp    1168 <reverse+0x38>
mov    (%rbx),%edi
call   1050 <reflect32@plt>
mov    %eax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @reverse(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 8
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 32
br label %10
10: ; preds = %7, %2
%11 = phi i1 [ true, %2 ], [ %9, %7 ]
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* %4
switch i32 %14, label %29 [
i32 8, label %15
i32 32, label %22
]
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = bitcast i8* %16 to i32*
%18 = load i32, i32* %17
%19 = call i32 @reflect8(i32 %18)
%20 = load i8*, i8** %3
%21 = bitcast i8* %20 to i32*
store i32 %19, i32* %21
br label %29
22: ; preds = %10
%23 = load i8*, i8** %3
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
%26 = call i32 @reflect32(i32 %25)
%27 = load i8*, i8** %3
%28 = bitcast i8* %27 to i32*
store i32 %26, i32* %28
br label %29
29: ; preds = %10, %22, %15
ret void
}

LLVM IR (-O2):
define void @reverse(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 8
%4 = icmp eq i32 %1, 32
%5 = or i1 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
switch i32 %1, label %16 [
i32 8, label %8
i32 32, label %12
]
8: ; preds = %2
%9 = bitcast i8* %0 to i32*
%10 = load i32, i32* %9
%11 = tail call i32 @reflect8(i32 %10)
store i32 %11, i32* %9
br label %16
12: ; preds = %2
%13 = bitcast i8* %0 to i32*
%14 = load i32, i32* %13
%15 = tail call i32 @reflect32(i32 %14)
store i32 %15, i32* %13
br label %16
16: ; preds = %2, %12, %8
ret void
}