#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned char, ...);
void fprintf_char(FILE *f, int wchar) {
  if (wchar < 128)
    fprintf(f, "%c", wchar);
  else {
    unsigned char first = (wchar >> 6) | 0xC0;
    unsigned char second = (wchar & 0x3F) | 0x80;
    fprintf(f, "%c%c", first, second);
  }
}


x86 assembly (clang, -O0):
<fprintf_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x80,-0xc(%rbp)
jge    1149 <fprintf_char+0x39>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
lea    0xec8(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1181 <fprintf_char+0x71>
mov    -0xc(%rbp),%eax
sar    $0x6,%eax
or     $0xc0,%eax
mov    %al,-0xd(%rbp)
mov    -0xc(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,-0xe(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xd(%rbp),%al
movzbl -0xe(%rbp),%ecx
lea    0xe89(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fprintf_char>:
mov    %esi,%ecx
mov    %rdi,%rax
cmp    $0x7f,%esi
jg     1135 <fprintf_char+0x15>
movsbl %cl,%edi
mov    %rax,%rsi
jmp    1030 <fputc@plt>
mov    %ecx,%edx
shr    $0x6,%edx
or     $0xc0,%dl
and    $0x3f,%ecx
or     $0x80,%ecx
movzbl %dl,%edx
lea    0xeb0(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [5 x i8] c"%c%c\00"
define void @fprintf_char(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 128
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32*, i32** %3
%11 = load i32, i32* %4
%12 = trunc i32 %11 to i8
%13 = call i32 (i32*, i8*, i8, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %12)
br label %28
14: ; preds = %2
%15 = load i32, i32* %4
%16 = ashr i32 %15, 6
%17 = or i32 %16, 192
%18 = trunc i32 %17 to i8
store i8 %18, i8* %5
%19 = load i32, i32* %4
%20 = and i32 %19, 63
%21 = or i32 %20, 128
%22 = trunc i32 %21 to i8
store i8 %22, i8* %6
%23 = load i32*, i32** %3
%24 = load i8, i8* %5
%25 = load i8, i8* %6
%26 = zext i8 %25 to i32
%27 = call i32 (i32*, i8*, i8, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %24, i32 %26)
br label %28
28: ; preds = %14, %9
ret void
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%c%c\00"
define void @fprintf_char(i32* nocapture %0, i32 %1) {
%3 = icmp slt i32 %1, 128
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = shl i32 %1, 24
%6 = ashr exact i32 %5, 24
%7 = tail call i32 @fputc(i32 %6, i32* %0)
br label %15
8: ; preds = %2
%9 = lshr i32 %1, 6
%10 = trunc i32 %9 to i8
%11 = or i8 %10, -64
%12 = and i32 %1, 63
%13 = or i32 %12, 128
%14 = tail call i32 (i32*, i8*, i8, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %11, i32 %13)
br label %15
15: ; preds = %8, %4
ret void
}