#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 strlen(char const *);
void OneUTF82Unicode(const char *utf_char, char *unicode_char) {
  int utf_length = strlen(utf_char);
  switch (utf_length) {
  case 1:
    unicode_char[0] = utf_char[0];
    unicode_char[1] = 0;
    break;
  case 2:
    unicode_char[0] = (utf_char[1] & 0x3F) | ((utf_char[0] & 0x3) << 6);
    unicode_char[1] = (utf_char[0] & 0x3C) >> 2;
    break;
  case 3:
    unicode_char[0] = (utf_char[2] & 0x3F) | ((utf_char[1] & 0x3) << 6);
    unicode_char[1] = ((utf_char[1] & 0x3C) >> 2) | ((utf_char[0] & 0xF) << 4);
    break;
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<OneUTF82Unicode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x1,%eax
je     1162 <OneUTF82Unicode+0x52>
jmp    1140 <OneUTF82Unicode+0x30>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
je     117b <OneUTF82Unicode+0x6b>
jmp    1151 <OneUTF82Unicode+0x41>
mov    -0x18(%rbp),%eax
sub    $0x3,%eax
je     11b8 <OneUTF82Unicode+0xa8>
jmp    1206 <OneUTF82Unicode+0xf6>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    120b <OneUTF82Unicode+0xfb>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0x3f,%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
and    $0x3,%ecx
shl    $0x6,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
and    $0x3c,%eax
sar    $0x2,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
jmp    120b <OneUTF82Unicode+0xfb>
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%eax
and    $0x3f,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
and    $0x3,%ecx
shl    $0x6,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0x3c,%eax
sar    $0x2,%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
and    $0xf,%ecx
shl    $0x4,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
jmp    120b <OneUTF82Unicode+0xfb>
jmp    120b <OneUTF82Unicode+0xfb>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OneUTF82Unicode>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x3,%eax
je     1137 <OneUTF82Unicode+0x27>
cmp    $0x2,%eax
je     115a <OneUTF82Unicode+0x4a>
cmp    $0x1,%eax
jne    1175 <OneUTF82Unicode+0x65>
mov    (%rbx),%al
mov    %al,(%r14)
xor    %eax,%eax
jmp    1171 <OneUTF82Unicode+0x61>
mov    0x1(%rbx),%al
mov    0x2(%rbx),%cl
and    $0x3f,%cl
shl    $0x6,%al
or     %cl,%al
mov    %al,(%r14)
mov    (%rbx),%al
mov    0x1(%rbx),%cl
shr    $0x2,%cl
and    $0xf,%cl
shl    $0x4,%al
or     %cl,%al
jmp    1171 <OneUTF82Unicode+0x61>
mov    (%rbx),%al
mov    0x1(%rbx),%cl
and    $0x3f,%cl
shl    $0x6,%al
or     %cl,%al
mov    %al,(%r14)
mov    (%rbx),%al
shr    $0x2,%al
and    $0xf,%al
mov    %al,0x1(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @OneUTF82Unicode(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
switch i32 %8, label %74 [
i32 1, label %9
i32 2, label %17
i32 3, label %42
]
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 %12, i8* %14
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8 0, i8* %16
br label %75
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = and i32 %21, 63
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = and i32 %26, 3
%28 = shl i32 %27, 6
%29 = or i32 %22, %28
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 0
store i8 %30, i8* %32
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = and i32 %36, 60
%38 = ashr i32 %37, 2
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 1
store i8 %39, i8* %41
br label %75
42: ; preds = %2
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i64 2
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = and i32 %46, 63
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = and i32 %51, 3
%53 = shl i32 %52, 6
%54 = or i32 %47, %53
%55 = trunc i32 %54 to i8
%56 = load i8*, i8** %4
%57 = getelementptr inbounds i8, i8* %56, i64 0
store i8 %55, i8* %57
%58 = load i8*, i8** %3
%59 = getelementptr inbounds i8, i8* %58, i64 1
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = and i32 %61, 60
%63 = ashr i32 %62, 2
%64 = load i8*, i8** %3
%65 = getelementptr inbounds i8, i8* %64, i64 0
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = and i32 %67, 15
%69 = shl i32 %68, 4
%70 = or i32 %63, %69
%71 = trunc i32 %70 to i8
%72 = load i8*, i8** %4
%73 = getelementptr inbounds i8, i8* %72, i64 1
store i8 %71, i8* %73
br label %75
74: ; preds = %2
br label %75
75: ; preds = %74, %42, %17, %9
ret void
}

LLVM IR (-O2):
define void @OneUTF82Unicode(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
switch i32 %3, label %33 [
i32 1, label %4
i32 2, label %6
i32 3, label %16
]
4: ; preds = %2
%5 = load i8, i8* %0
store i8 %5, i8* %1
br label %30
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = and i8 %8, 63
%10 = load i8, i8* %0
%11 = shl i8 %10, 6
%12 = or i8 %11, %9
store i8 %12, i8* %1
%13 = load i8, i8* %0
%14 = lshr i8 %13, 2
%15 = and i8 %14, 15
br label %30
16: ; preds = %2
%17 = getelementptr inbounds i8, i8* %0, i64 2
%18 = load i8, i8* %17
%19 = and i8 %18, 63
%20 = getelementptr inbounds i8, i8* %0, i64 1
%21 = load i8, i8* %20
%22 = shl i8 %21, 6
%23 = or i8 %22, %19
store i8 %23, i8* %1
%24 = load i8, i8* %20
%25 = lshr i8 %24, 2
%26 = and i8 %25, 15
%27 = load i8, i8* %0
%28 = shl i8 %27, 4
%29 = or i8 %26, %28
br label %30
30: ; preds = %4, %6, %16
%31 = phi i8 [ %29, %16 ], [ %15, %6 ], [ 0, %4 ]
%32 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %31, i8* %32
br label %33
33: ; preds = %30, %2
ret void
}