#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 */
char *charset_conv_iso_8859_1_to_utf8(char const *, size_t);
char *charset_conv_ucs_2be_to_utf8(char const *, size_t);
char *strdup(char const *);
char *charset_conv_given_to_utf8(const char *msg, size_t len,
                                 unsigned short charset) {
  char *retmsg = NULL;
  switch (charset) {
  case 2:
    retmsg = charset_conv_ucs_2be_to_utf8(msg, len);
    break;
  case 3:
    retmsg = charset_conv_iso_8859_1_to_utf8(msg, len);
    break;
  default:
    retmsg = strdup(msg);
    break;
  }
  return retmsg;
}


x86 assembly (clang, -O0):
<charset_conv_given_to_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dx,%ax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
movq   $0x0,-0x20(%rbp)
movzwl -0x12(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x2,%eax
je     1175 <charset_conv_given_to_utf8+0x45>
jmp    1164 <charset_conv_given_to_utf8+0x34>
mov    -0x24(%rbp),%eax
sub    $0x3,%eax
je     118b <charset_conv_given_to_utf8+0x5b>
jmp    11a1 <charset_conv_given_to_utf8+0x71>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <charset_conv_ucs_2be_to_utf8@plt>
mov    %rax,-0x20(%rbp)
jmp    11ae <charset_conv_given_to_utf8+0x7e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <charset_conv_iso_8859_1_to_utf8@plt>
mov    %rax,-0x20(%rbp)
jmp    11ae <charset_conv_given_to_utf8+0x7e>
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charset_conv_given_to_utf8>:
cmp    $0x3,%dx
je     1141 <charset_conv_given_to_utf8+0x11>
cmp    $0x2,%dx
jne    1146 <charset_conv_given_to_utf8+0x16>
jmp    1030 <charset_conv_ucs_2be_to_utf8@plt>
jmp    1040 <charset_conv_iso_8859_1_to_utf8@plt>
jmp    1050 <strdup@plt>

LLVM IR (-O0):
define i8* @charset_conv_given_to_utf8(i8* %0, i64 %1, i16 zeroext %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i16
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i16 %2, i16* %6
store i8* null, i8** %7
%8 = load i16, i16* %6
%9 = zext i16 %8 to i32
switch i32 %9, label %18 [
i32 2, label %10
i32 3, label %14
]
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = load i64, i64* %5
%13 = call i8* @charset_conv_ucs_2be_to_utf8(i8* %11, i64 %12)
store i8* %13, i8** %7
br label %21
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = load i64, i64* %5
%17 = call i8* @charset_conv_iso_8859_1_to_utf8(i8* %15, i64 %16)
store i8* %17, i8** %7
br label %21
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %7
br label %21
21: ; preds = %18, %14, %10
%22 = load i8*, i8** %7
ret i8* %22
}

LLVM IR (-O2):
define i8* @charset_conv_given_to_utf8(i8* %0, i64 %1, i16 zeroext %2) {
switch i16 %2, label %8 [
i16 2, label %4
i16 3, label %6
]
4: ; preds = %3
%5 = tail call i8* @charset_conv_ucs_2be_to_utf8(i8* %0, i64 %1)
br label %10
6: ; preds = %3
%7 = tail call i8* @charset_conv_iso_8859_1_to_utf8(i8* %0, i64 %1)
br label %10
8: ; preds = %3
%9 = tail call i8* @strdup(i8* %0)
br label %10
10: ; preds = %8, %6, %4
%11 = phi i8* [ %9, %8 ], [ %7, %6 ], [ %5, %4 ]
ret i8* %11
}