#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 getc(int /*<<< orphan*/ *);
int utf8_getc(FILE *fin) {
  int c1, c2, c3;
again:
  c1 = getc(fin);
  if (c1 < 0 || !(c1 & 0x80))
    return c1;
  c2 = getc(fin);
  if (!(c1 & 0x20))
    return (c1 & 0x1f) << 6 | (c2 & 0x3f);
  c3 = getc(fin);
  if (c1 == 0xEF && c2 == 0xBB && c3 == 0xBF) {
    goto again;
  }
  return (c1 & 0x0f) << 12 | (c2 & 0x3f) << 6 | (c3 & 0x3f);
}


x86 assembly (clang, -O0):
<utf8_getc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1143 <utf8_getc+0x33>
mov    -0x14(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    114e <utf8_getc+0x3e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d9 <utf8_getc+0xc9>
mov    -0x10(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
jne    1182 <utf8_getc+0x72>
mov    -0x14(%rbp),%eax
and    $0x1f,%eax
shl    $0x6,%eax
mov    -0x18(%rbp),%ecx
and    $0x3f,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11d9 <utf8_getc+0xc9>
mov    -0x10(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xef,-0x14(%rbp)
jne    11ba <utf8_getc+0xaa>
cmpl   $0xbb,-0x18(%rbp)
jne    11ba <utf8_getc+0xaa>
cmpl   $0xbf,-0x1c(%rbp)
jne    11ba <utf8_getc+0xaa>
jmp    111c <utf8_getc+0xc>
mov    -0x14(%rbp),%eax
and    $0xf,%eax
shl    $0xc,%eax
mov    -0x18(%rbp),%ecx
and    $0x3f,%ecx
shl    $0x6,%ecx
or     %ecx,%eax
mov    -0x1c(%rbp),%ecx
and    $0x3f,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_getc>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <getc@plt>
mov    %eax,%ebx
and    $0x80000080,%eax
cmp    $0x80,%eax
jne    1186 <utf8_getc+0x76>
mov    %r14,%rdi
call   1030 <getc@plt>
mov    %eax,%ebp
test   $0x20,%bl
je     117b <utf8_getc+0x6b>
mov    %r14,%rdi
call   1030 <getc@plt>
cmp    $0xef,%ebx
jne    1164 <utf8_getc+0x54>
cmp    $0xbb,%ebp
jne    1164 <utf8_getc+0x54>
cmp    $0xbf,%eax
je     1120 <utf8_getc+0x10>
shl    $0xc,%ebx
movzwl %bx,%ecx
and    $0x3f,%ebp
shl    $0x6,%ebp
or     %ecx,%ebp
and    $0x3f,%eax
or     %ebp,%eax
mov    %eax,%ebx
jmp    1186 <utf8_getc+0x76>
and    $0x1f,%ebx
shl    $0x6,%ebx
and    $0x3f,%ebp
or     %ebp,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @utf8_getc(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
br label %7
7: ; preds = %42, %1
%8 = load i32*, i32** %3
%9 = call i32 @getc(i32* %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = load i32, i32* %4
%14 = and i32 %13, 128
%15 = icmp ne i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12, %7
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %54
18: ; preds = %12
%19 = load i32*, i32** %3
%20 = call i32 @getc(i32* %19)
store i32 %20, i32* %5
%21 = load i32, i32* %4
%22 = and i32 %21, 32
%23 = icmp ne i32 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %18
%25 = load i32, i32* %4
%26 = and i32 %25, 31
%27 = shl i32 %26, 6
%28 = load i32, i32* %5
%29 = and i32 %28, 63
%30 = or i32 %27, %29
store i32 %30, i32* %2
br label %54
31: ; preds = %18
%32 = load i32*, i32** %3
%33 = call i32 @getc(i32* %32)
store i32 %33, i32* %6
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 239
br i1 %35, label %36, label %43
36: ; preds = %31
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 187
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* %6
%41 = icmp eq i32 %40, 191
br i1 %41, label %42, label %43
42: ; preds = %39
br label %7
43: ; preds = %39, %36, %31
%44 = load i32, i32* %4
%45 = and i32 %44, 15
%46 = shl i32 %45, 12
%47 = load i32, i32* %5
%48 = and i32 %47, 63
%49 = shl i32 %48, 6
%50 = or i32 %46, %49
%51 = load i32, i32* %6
%52 = and i32 %51, 63
%53 = or i32 %50, %52
store i32 %53, i32* %2
br label %54
54: ; preds = %43, %24, %16
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
define i32 @utf8_getc(i32* nocapture %0) {
br label %2
2: ; preds = %15, %1
%3 = tail call i32 @getc(i32* %0)
%4 = and i32 %3, -2147483520
%5 = icmp eq i32 %4, 128
br i1 %5, label %6, label %30
6: ; preds = %2
%7 = tail call i32 @getc(i32* %0)
%8 = and i32 %3, 32
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = shl i32 %3, 6
%12 = and i32 %11, 1984
%13 = and i32 %7, 63
%14 = or i32 %13, %12
br label %30
15: ; preds = %6
%16 = tail call i32 @getc(i32* %0)
%17 = icmp eq i32 %3, 239
%18 = icmp eq i32 %7, 187
%19 = and i1 %17, %18
%20 = icmp eq i32 %16, 191
%21 = and i1 %19, %20
br i1 %21, label %2, label %22
22: ; preds = %15
%23 = shl i32 %3, 12
%24 = and i32 %23, 61440
%25 = shl i32 %7, 6
%26 = and i32 %25, 4032
%27 = or i32 %26, %24
%28 = and i32 %16, 63
%29 = or i32 %27, %28
br label %30
30: ; preds = %2, %22, %10
%31 = phi i32 [ %29, %22 ], [ %14, %10 ], [ %3, %2 ]
ret i32 %31
}