char *strndup_iconv_to_ucs2(unsigned long *out_size, const char *src_codeset,
                            const char *src, unsigned long src_size) {
  char *buffer;
  unsigned long buffer_size;
  if (((void *)0) == src_codeset) {
    src_codeset = "UTF-8";
  } else if (same_codeset(src_codeset, "UCS2")) {
    return strndup_identity(out_size, src, src_size);
  } else if (same_codeset(src_codeset, "EIA608")) {
    return strndup_ucs2_eia608(out_size, src, src_size, 0);
  }
  if (((void *)0) != out_size)
    *out_size = 0;
  if (__builtin_expect(((void *)0) == src, 0))
    return ((void *)0);
  buffer = ((void *)0);
  buffer_size = 0;
  return buffer;
}


x86 assembly (clang, -O0):
<strndup_iconv_to_ucs2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1164 <strndup_iconv_to_ucs2+0x34>
lea    0xea5(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11e2 <strndup_iconv_to_ucs2+0xb2>
mov    -0x18(%rbp),%rdi
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1050 <same_codeset@plt>
cmp    $0x0,%eax
je     119d <strndup_iconv_to_ucs2+0x6d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1040 <strndup_identity@plt>
cltq
mov    %rax,-0x8(%rbp)
jmp    1238 <strndup_iconv_to_ucs2+0x108>
mov    -0x18(%rbp),%rdi
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1050 <same_codeset@plt>
cmp    $0x0,%eax
je     11d8 <strndup_iconv_to_ucs2+0xa8>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1030 <strndup_ucs2_eia608@plt>
cltq
mov    %rax,-0x8(%rbp)
jmp    1238 <strndup_iconv_to_ucs2+0x108>
jmp    11dd <strndup_iconv_to_ucs2+0xad>
jmp    11e2 <strndup_iconv_to_ucs2+0xb2>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     11f9 <strndup_iconv_to_ucs2+0xc9>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cltq
cmp    $0x0,%rax
je     1220 <strndup_iconv_to_ucs2+0xf0>
movq   $0x0,-0x8(%rbp)
jmp    1238 <strndup_iconv_to_ucs2+0x108>
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strndup_iconv_to_ucs2>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
test   %rsi,%rsi
je     119d <strndup_iconv_to_ucs2+0x6d>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
lea    0xeb0(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <same_codeset@plt>
test   %eax,%eax
je     1172 <strndup_iconv_to_ucs2+0x42>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <strndup_identity@plt>
cltq
jmp    11ac <strndup_iconv_to_ucs2+0x7c>
lea    0xe8c(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <same_codeset@plt>
test   %eax,%eax
je     119d <strndup_iconv_to_ucs2+0x6d>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <strndup_ucs2_eia608@plt>
cltq
jmp    11ac <strndup_iconv_to_ucs2+0x7c>
test   %r12,%r12
je     11aa <strndup_iconv_to_ucs2+0x7a>
movq   $0x0,(%r12)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"UTF-8\00"
@.str.1 = [5 x i8] c"UCS2\00"
@.str.2 = [7 x i8] c"EIA608\00"
define i8* @strndup_iconv_to_ucs2(i64* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
store i64* %0, i64** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%12 = load i8*, i8** %7
%13 = icmp eq i8* null, %12
br i1 %13, label %14, label %15
14: ; preds = %4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %7
br label %39
15: ; preds = %4
%16 = load i8*, i8** %7
%17 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @same_codeset to i32 (i8*, i8*, ...)*)(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i64*, i64** %6
%21 = load i8*, i8** %8
%22 = load i64, i64* %9
%23 = call i32 (i64*, i8*, i64, ...) bitcast (i32 (...)* @strndup_identity to i32 (i64*, i8*, i64, ...)*)(i64* %20, i8* %21, i64 %22)
%24 = sext i32 %23 to i64
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %5
br label %53
26: ; preds = %15
%27 = load i8*, i8** %7
%28 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @same_codeset to i32 (i8*, i8*, ...)*)(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = load i64*, i64** %6
%32 = load i8*, i8** %8
%33 = load i64, i64* %9
%34 = call i32 (i64*, i8*, i64, i32, ...) bitcast (i32 (...)* @strndup_ucs2_eia608 to i32 (i64*, i8*, i64, i32, ...)*)(i64* %31, i8* %32, i64 %33, i32 0)
%35 = sext i32 %34 to i64
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %5
br label %53
37: ; preds = %26
br label %38
38: ; preds = %37
br label %39
39: ; preds = %38, %14
%40 = load i64*, i64** %6
%41 = icmp ne i64* null, %40
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = load i64*, i64** %6
store i64 0, i64* %43
br label %44
44: ; preds = %42, %39
%45 = load i8*, i8** %8
%46 = icmp eq i8* null, %45
%47 = zext i1 %46 to i32
%48 = sext i32 %47 to i64
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %44
store i8* null, i8** %5
br label %53
51: ; preds = %44
store i8* null, i8** %10
store i64 0, i64* %11
%52 = load i8*, i8** %10
store i8* %52, i8** %5
br label %53
53: ; preds = %51, %50, %30, %19
%54 = load i8*, i8** %5
ret i8* %54
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"UCS2\00"
@.str.2 = [7 x i8] c"EIA608\00"
define i8* @strndup_iconv_to_ucs2(i64* %0, i8* %1, i8* %2, i64 %3) {
%5 = icmp eq i8* %1, null
br i1 %5, label %20, label %6
6: ; preds = %4
%7 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @same_codeset to i32 (i8*, i8*, ...)*)(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = tail call i32 (i64*, i8*, i64, ...) bitcast (i32 (...)* @strndup_identity to i32 (i64*, i8*, i64, ...)*)(i64* %0, i8* %2, i64 %3)
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i8*
br label %23
13: ; preds = %6
%14 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @same_codeset to i32 (i8*, i8*, ...)*)(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = tail call i32 (i64*, i8*, i64, i32, ...) bitcast (i32 (...)* @strndup_ucs2_eia608 to i32 (i64*, i8*, i64, i32, ...)*)(i64* %0, i8* %2, i64 %3, i32 0)
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i8*
br label %23
20: ; preds = %4, %13
%21 = icmp eq i64* %0, null
br i1 %21, label %23, label %22
22: ; preds = %20
store i64 0, i64* %0
br label %23
23: ; preds = %20, %22, %16, %9
%24 = phi i8* [ %12, %9 ], [ %19, %16 ], [ null, %22 ], [ null, %20 ]
ret i8* %24
}