#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 */
unsigned int codec_base32_encode(unsigned char *, unsigned int, unsigned char *,
                                 unsigned int);
unsigned int codec_base64_encode(unsigned char *, unsigned int, unsigned char *,
                                 unsigned int);
unsigned int codec_binary_encode(unsigned char *, unsigned int, unsigned char *,
                                 unsigned int *, unsigned int);
int /*<<< orphan*/ error(char *, unsigned char);
unsigned int strlen(unsigned char *);
unsigned int codec_encode(unsigned char codec, unsigned char *input,
                          unsigned int in_len, unsigned char *output,
                          unsigned int *out_len, unsigned int max_out_len) {
  unsigned int consumed = 0;
  switch (codec) {
  case 0x0:
    consumed = codec_base32_encode(input, in_len, output, max_out_len);
    *out_len = strlen(output);
    break;
  case 0x2:
    consumed = codec_base64_encode(input, in_len, output, max_out_len);
    *out_len = strlen(output);
    break;
  case 0x1:
    consumed = codec_binary_encode(input, in_len, output, out_len, max_out_len);
    break;
  default:
    error("unknown codec: %.2x\n", codec);
  }
  return consumed;
}


x86 assembly (clang, -O0):
<codec_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movzbl -0x1(%rbp),%eax
mov    %eax,-0x34(%rbp)
test   %eax,%eax
je     11ae <codec_encode+0x5e>
jmp    118c <codec_encode+0x3c>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     1206 <codec_encode+0xb6>
jmp    119d <codec_encode+0x4d>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     11da <codec_encode+0x8a>
jmp    1226 <codec_encode+0xd6>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1050 <codec_base32_encode@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    1236 <codec_encode+0xe6>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1030 <codec_base64_encode@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    1236 <codec_encode+0xe6>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   1070 <codec_binary_encode@plt>
mov    %eax,-0x30(%rbp)
jmp    1236 <codec_encode+0xe6>
lea    0xdd3(%rip),%rdi
movzbl -0x1(%rbp),%esi
call   1060 <error@plt>
mov    -0x30(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<codec_encode>:
push   %rbp
push   %r14
push   %rbx
mov    %r8,%r14
mov    %rcx,%rbx
cmp    $0x2,%dil
je     117d <codec_encode+0x2d>
cmp    $0x1,%dil
je     119e <codec_encode+0x4e>
test   %dil,%dil
jne    11b5 <codec_encode+0x65>
mov    %rsi,%rdi
mov    %edx,%esi
mov    %rbx,%rdx
mov    %r9d,%ecx
call   1050 <codec_base32_encode@plt>
jmp    118d <codec_encode+0x3d>
mov    %rsi,%rdi
mov    %edx,%esi
mov    %rbx,%rdx
mov    %r9d,%ecx
call   1030 <codec_base64_encode@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,(%r14)
mov    %ebp,%eax
jmp    11c7 <codec_encode+0x77>
mov    %rsi,%rdi
mov    %edx,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %r9d,%r8d
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <codec_binary_encode@plt>
movzbl %dil,%esi
lea    0xe40(%rip),%rdi
call   1060 <error@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"unknown codec: %.2x\0A\00"
define i32 @codec_encode(i8 zeroext %0, i8* %1, i32 %2, i8* %3, i32* %4, i32 %5) {
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i8 %0, i8* %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32* %4, i32** %11
store i32 %5, i32* %12
store i32 0, i32* %13
%14 = load i8, i8* %7
%15 = zext i8 %14 to i32
switch i32 %15, label %41 [
i32 0, label %16
i32 2, label %25
i32 1, label %34
]
16: ; preds = %6
%17 = load i8*, i8** %8
%18 = load i32, i32* %9
%19 = load i8*, i8** %10
%20 = load i32, i32* %12
%21 = call i32 @codec_base32_encode(i8* %17, i32 %18, i8* %19, i32 %20)
store i32 %21, i32* %13
%22 = load i8*, i8** %10
%23 = call i32 @strlen(i8* %22)
%24 = load i32*, i32** %11
store i32 %23, i32* %24
br label %44
25: ; preds = %6
%26 = load i8*, i8** %8
%27 = load i32, i32* %9
%28 = load i8*, i8** %10
%29 = load i32, i32* %12
%30 = call i32 @codec_base64_encode(i8* %26, i32 %27, i8* %28, i32 %29)
store i32 %30, i32* %13
%31 = load i8*, i8** %10
%32 = call i32 @strlen(i8* %31)
%33 = load i32*, i32** %11
store i32 %32, i32* %33
br label %44
34: ; preds = %6
%35 = load i8*, i8** %8
%36 = load i32, i32* %9
%37 = load i8*, i8** %10
%38 = load i32*, i32** %11
%39 = load i32, i32* %12
%40 = call i32 @codec_binary_encode(i8* %35, i32 %36, i8* %37, i32* %38, i32 %39)
store i32 %40, i32* %13
br label %44
41: ; preds = %6
%42 = load i8, i8* %7
%43 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8 zeroext %42)
br label %44
44: ; preds = %41, %34, %25, %16
%45 = load i32, i32* %13
ret i32 %45
}

LLVM IR (-O2):
@.str = [21 x i8] c"unknown codec: %.2x\0A\00"
define i32 @codec_encode(i8 zeroext %0, i8* %1, i32 %2, i8* %3, i32* %4, i32 %5) {
switch i8 %0, label %15 [
i8 0, label %7
i8 2, label %10
i8 1, label %13
]
7: ; preds = %6
%8 = tail call i32 @codec_base32_encode(i8* %1, i32 %2, i8* %3, i32 %5)
%9 = tail call i32 @strlen(i8* %3)
store i32 %9, i32* %4
br label %17
10: ; preds = %6
%11 = tail call i32 @codec_base64_encode(i8* %1, i32 %2, i8* %3, i32 %5)
%12 = tail call i32 @strlen(i8* %3)
store i32 %12, i32* %4
br label %17
13: ; preds = %6
%14 = tail call i32 @codec_binary_encode(i8* %1, i32 %2, i8* %3, i32* %4, i32 %5)
br label %17
15: ; preds = %6
%16 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8 zeroext %0)
br label %17
17: ; preds = %15, %13, %10, %7
%18 = phi i32 [ 0, %15 ], [ %14, %13 ], [ %11, %10 ], [ %8, %7 ]
ret i32 %18
}