#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);
void invert(void *payload, uint8_t bit_size) {
  assert(bit_size == 8 || bit_size == 32);
  switch (bit_size) {
  case 8:
    *((uint8_t *)payload) = ~*((uint8_t *)payload);
    break;
  case 32:
    *((uint32_t *)payload) = ~*((uint32_t *)payload);
    break;
  }
}


x86 assembly (clang, -O0):
<invert>:
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     1138 <invert+0x28>
cmpl   $0x20,-0xc(%rbp)
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
movzbl %al,%edi
and    $0x1,%edi
call   1030 <assert@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x8,%eax
je     116b <invert+0x5b>
jmp    115a <invert+0x4a>
mov    -0x14(%rbp),%eax
sub    $0x20,%eax
je     117f <invert+0x6f>
jmp    118e <invert+0x7e>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    118e <invert+0x7e>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<invert>:
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   1030 <assert@plt>
cmp    $0x20,%ebp
je     1138 <invert+0x28>
cmp    $0x8,%ebp
jne    113a <invert+0x2a>
notl   (%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @invert(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 = xor i32 %18, -1
%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 = xor i32 %25, -1
%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 @invert(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 %12 [
i32 8, label %8
i32 32, label %8
]
8: ; preds = %2, %2
%9 = bitcast i8* %0 to i32*
%10 = load i32, i32* %9
%11 = xor i32 %10, -1
store i32 %11, i32* %9
br label %12
12: ; preds = %8, %2
ret void
}