#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 *, char *);
int /*<<< orphan*/ fputc(unsigned int, int /*<<< orphan*/ *);
void fputcUTF8(int c, FILE *file) {
  unsigned int c1 = c;
  unsigned int c2;
  char buff[10];
  int n;
  int m;
  if (c1 < 0x80) {
    fputc(c1, file);
    return;
  }
  buff[6] = 0;
  n = 5;
  m = 32;
  c2 = 0x1F80;
  while (c1) {
    buff[n] = (c1 & 0x3f) | 0x80;
    c1 = c1 >> 6;
    c2 = c2 >> 1;
    if (c1 < m) {
      n--;
      buff[n] = ((c2 & 0xFF) | c1);
      c1 = 0;
    } else {
      n--;
      m /= 2;
    }
  }
  fprintf(file, "%s", &buff[n]);
}


x86 assembly (clang, -O0):
<fputcUTF8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jae    1153 <fputcUTF8+0x33>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <fputc@plt>
jmp    120a <fputcUTF8+0xea>
movb   $0x0,-0x1c(%rbp)
movl   $0x5,-0x28(%rbp)
movl   $0x20,-0x2c(%rbp)
movl   $0x1f80,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ef <fputcUTF8+0xcf>
mov    -0x14(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x22(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
shr    $0x6,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jae    11d3 <fputcUTF8+0xb3>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
or     -0x14(%rbp),%eax
mov    %al,%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x22(%rbp,%rax,1)
movl   $0x0,-0x14(%rbp)
jmp    11ea <fputcUTF8+0xca>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
jmp    116c <fputcUTF8+0x4c>
mov    -0x10(%rbp),%rdi
movslq -0x28(%rbp),%rax
lea    -0x22(%rbp),%rdx
add    %rax,%rdx
lea    0xdfb(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputcUTF8>:
sub    $0x18,%rsp
cmp    $0x7f,%edi
ja     1132 <fputcUTF8+0x12>
add    $0x18,%rsp
jmp    1040 <fputc@plt>
movb   $0x0,0x14(%rsp)
lea    0x12(%rsp),%rcx
mov    $0x1f80,%r9d
mov    $0x20,%r10d
mov    %edi,%edx
nopw   0x0(%rax,%rax,1)
mov    %rcx,%r8
mov    %edi,%ecx
and    $0x3f,%cl
or     $0x80,%cl
mov    %cl,0x1(%r8)
shr    $0x6,%edx
shr    %r9d
cmp    %r10d,%edx
jb     1185 <fputcUTF8+0x65>
mov    %r10d,%eax
shr    $0x1f,%eax
add    %r10d,%eax
sar    %eax
lea    -0x1(%r8),%rcx
mov    %eax,%r10d
cmp    $0x3f,%edi
mov    %edx,%edi
ja     1150 <fputcUTF8+0x30>
jmp    118b <fputcUTF8+0x6b>
or     %edx,%r9d
mov    %r9b,(%r8)
mov    %r8,%rdi
call   1030 <fputs@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define void @fputcUTF8(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [10 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%10 = load i32, i32* %3
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp ult i32 %11, 128
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* %5
%15 = load i32*, i32** %4
%16 = call i32 @fputc(i32 %14, i32* %15)
br label %60
17: ; preds = %2
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 6
store i8 0, i8* %18
store i32 5, i32* %8
store i32 32, i32* %9
store i32 8064, i32* %6
br label %19
19: ; preds = %53, %17
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %54
22: ; preds = %19
%23 = load i32, i32* %5
%24 = and i32 %23, 63
%25 = or i32 %24, 128
%26 = trunc i32 %25 to i8
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 %28
store i8 %26, i8* %29
%30 = load i32, i32* %5
%31 = lshr i32 %30, 6
store i32 %31, i32* %5
%32 = load i32, i32* %6
%33 = lshr i32 %32, 1
store i32 %33, i32* %6
%34 = load i32, i32* %5
%35 = load i32, i32* %9
%36 = icmp ult i32 %34, %35
br i1 %36, label %37, label %48
37: ; preds = %22
%38 = load i32, i32* %8
%39 = add nsw i32 %38, -1
store i32 %39, i32* %8
%40 = load i32, i32* %6
%41 = and i32 %40, 255
%42 = load i32, i32* %5
%43 = or i32 %41, %42
%44 = trunc i32 %43 to i8
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 %46
store i8 %44, i8* %47
store i32 0, i32* %5
br label %53
48: ; preds = %22
%49 = load i32, i32* %8
%50 = add nsw i32 %49, -1
store i32 %50, i32* %8
%51 = load i32, i32* %9
%52 = sdiv i32 %51, 2
store i32 %52, i32* %9
br label %53
53: ; preds = %48, %37
br label %19
54: ; preds = %19
%55 = load i32*, i32** %4
%56 = load i32, i32* %8
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 %57
%59 = call i32 @fprintf(i32* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %58)
br label %60
60: ; preds = %54, %13
ret void
}

LLVM IR (-O2):
define void @fputcUTF8(i32 %0, i32* nocapture %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp ult i32 %0, 128
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @fputc(i32 %0, i32* %1)
br label %36
8: ; preds = %2
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 6
store i8 0, i8* %9
br label %10
10: ; preds = %8, %29
%11 = phi i32 [ 32, %8 ], [ %30, %29 ]
%12 = phi i32 [ 5, %8 ], [ %23, %29 ]
%13 = phi i32 [ 8064, %8 ], [ %21, %29 ]
%14 = phi i32 [ %0, %8 ], [ %20, %29 ]
%15 = trunc i32 %14 to i8
%16 = and i8 %15, 63
%17 = or i8 %16, -128
%18 = sext i32 %12 to i64
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %18
store i8 %17, i8* %19
%20 = lshr i32 %14, 6
%21 = lshr i32 %13, 1
%22 = icmp ult i32 %20, %11
%23 = add nsw i32 %12, -1
br i1 %22, label %24, label %29
24: ; preds = %10
%25 = or i32 %21, %20
%26 = trunc i32 %25 to i8
%27 = sext i32 %23 to i64
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %27
store i8 %26, i8* %28
br label %32
29: ; preds = %10
%30 = sdiv i32 %11, 2
%31 = icmp ult i32 %14, 64
br i1 %31, label %32, label %10
32: ; preds = %29, %24
%33 = sext i32 %23 to i64
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %33
%35 = call i32 @fputs(i8* %34, i32* %1)
br label %36
36: ; preds = %32, %6
ret void
}