#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*/ error(char *, int);
unsigned int codec_required_space(int codec, int length) {
  int ret = 0;
  switch (codec) {
  case 0x0:
    ret = (unsigned int)((length * 5) / 8);
    break;
  case 0x1:
    ret = length;
    break;
  case 0x2:
    ret = (unsigned int)((length * 6) / 8);
    break;
  default:
    error("unknown codec: %.2x\n", codec);
  }
  return ret;
}


x86 assembly (clang, -O0):
<codec_required_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
test   %eax,%eax
je     115a <codec_required_space+0x4a>
jmp    1138 <codec_required_space+0x28>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
je     116e <codec_required_space+0x5e>
jmp    1149 <codec_required_space+0x39>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     1179 <codec_required_space+0x69>
jmp    118d <codec_required_space+0x7d>
imul   $0x5,-0x8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    119c <codec_required_space+0x8c>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    119c <codec_required_space+0x8c>
imul   $0x6,-0x8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    119c <codec_required_space+0x8c>
mov    -0x4(%rbp),%esi
lea    0xe69(%rip),%rdi
call   1030 <error@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<codec_required_space>:
mov    %esi,%eax
cmp    $0x2,%edi
je     112d <codec_required_space+0x1d>
mov    %edi,%esi
cmp    $0x1,%edi
je     1154 <codec_required_space+0x44>
test   %esi,%esi
jne    1141 <codec_required_space+0x31>
lea    (%rax,%rax,4),%ecx
lea    (%rax,%rax,4),%eax
add    $0x7,%eax
jmp    1138 <codec_required_space+0x28>
add    %eax,%eax
lea    (%rax,%rax,2),%ecx
lea    (%rax,%rax,2),%eax
add    $0x7,%eax
test   %ecx,%ecx
cmovns %ecx,%eax
sar    $0x3,%eax
ret
push   %rax
lea    0xeb7(%rip),%rdi
call   1030 <error@plt>
xor    %eax,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"unknown codec: %.2x\0A\00"
define i32 @codec_required_space(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %3
switch i32 %6, label %17 [
i32 0, label %7
i32 1, label %11
i32 2, label %13
]
7: ; preds = %2
%8 = load i32, i32* %4
%9 = mul nsw i32 %8, 5
%10 = sdiv i32 %9, 8
store i32 %10, i32* %5
br label %20
11: ; preds = %2
%12 = load i32, i32* %4
store i32 %12, i32* %5
br label %20
13: ; preds = %2
%14 = load i32, i32* %4
%15 = mul nsw i32 %14, 6
%16 = sdiv i32 %15, 8
store i32 %16, i32* %5
br label %20
17: ; preds = %2
%18 = load i32, i32* %3
%19 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %13, %11, %7
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
@.str = [21 x i8] c"unknown codec: %.2x\0A\00"
define i32 @codec_required_space(i32 %0, i32 %1) {
switch i32 %0, label %9 [
i32 0, label %3
i32 1, label %11
i32 2, label %6
]
3: ; preds = %2
%4 = mul nsw i32 %1, 5
%5 = sdiv i32 %4, 8
br label %11
6: ; preds = %2
%7 = mul nsw i32 %1, 6
%8 = sdiv i32 %7, 8
br label %11
9: ; preds = %2
%10 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %11
11: ; preds = %2, %9, %6, %3
%12 = phi i32 [ 0, %9 ], [ %8, %6 ], [ %5, %3 ], [ %1, %2 ]
ret i32 %12
}