#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*/ codepoint;

/* Variables and functions */
int Q_UTF8Width(char const *);
int /*<<< orphan*/ getbit(unsigned char const *, int);
int /*<<< orphan*/ setbit(unsigned char *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ shiftbitsright(unsigned char *, int, int);
unsigned long Q_UTF8CodePoint(const char *str) {
  int i, j;
  int n = 0;
  int size = Q_UTF8Width(str);
  unsigned long codepoint = 0;
  unsigned char *p = (unsigned char *)&codepoint;
  if (size > sizeof(codepoint))
    size = sizeof(codepoint);
  else if (size < 1)
    size = 1;
  for (i = (size > 1 ? size + 1 : 1); i < 8; i++)
    setbit(p, n++, getbit((const unsigned char *)str, i));
  for (i = 1; i < size; i++)
    for (j = 2; j < 8; j++)
      setbit(p, n++, getbit(((const unsigned char *)str) + i, j));
  shiftbitsright(p, 8 * sizeof(codepoint), 8 * sizeof(codepoint) - n);
  return codepoint;
}


x86 assembly (clang, -O0):
<Q_UTF8CodePoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <Q_UTF8Width@plt>
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x8,%rax
jbe    1189 <Q_UTF8CodePoint+0x49>
movl   $0x8,-0x18(%rbp)
jmp    119f <Q_UTF8CodePoint+0x5f>
cmpl   $0x1,-0x18(%rbp)
jge    119a <Q_UTF8CodePoint+0x5a>
movl   $0x1,-0x18(%rbp)
jmp    119f <Q_UTF8CodePoint+0x5f>
cmpl   $0x1,-0x18(%rbp)
jle    11b7 <Q_UTF8CodePoint+0x77>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c4 <Q_UTF8CodePoint+0x84>
mov    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c4 <Q_UTF8CodePoint+0x84>
mov    -0x2c(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    1210 <Q_UTF8CodePoint+0xd0>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <getbit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    %eax,%edx
call   1040 <setbit@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ca <Q_UTF8CodePoint+0x8a>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    128a <Q_UTF8CodePoint+0x14a>
movl   $0x2,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    1277 <Q_UTF8CodePoint+0x137>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%esi
call   1050 <getbit@plt>
mov    -0x48(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    %eax,%edx
call   1040 <setbit@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    122a <Q_UTF8CodePoint+0xea>
jmp    127c <Q_UTF8CodePoint+0x13c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1217 <Q_UTF8CodePoint+0xd7>
mov    -0x28(%rbp),%rdi
movslq -0x14(%rbp),%rcx
mov    $0x40,%eax
sub    %rcx,%rax
mov    %eax,%edx
mov    $0x40,%esi
call   1060 <shiftbitsright@plt>
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Q_UTF8CodePoint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
call   1030 <Q_UTF8Width@plt>
movq   $0x0,0x8(%rsp)
test   %eax,%eax
mov    $0x1,%ecx
mov    $0x1,%r12d
cmovg  %eax,%r12d
cmp    $0x9,%eax
mov    $0x8,%eax
cmovae %eax,%r12d
lea    0x1(%r12),%r13d
cmp    $0x2,%r12d
cmovb  %ecx,%r13d
xor    %ebp,%ebp
cmp    $0x7,%r13d
ja     11cd <Q_UTF8CodePoint+0x8d>
sub    %r13d,%eax
mov    %eax,0x14(%rsp)
xor    %ebx,%ebx
lea    0x8(%rsp),%r14
nop
lea    (%rbx,%r13,1),%esi
lea    0x1(%rbx),%ebp
mov    %r15,%rdi
call   1050 <getbit@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <setbit@plt>
lea    (%rbx,%r13,1),%eax
add    $0x1,%eax
mov    %ebp,%ebx
cmp    $0x8,%eax
jne    11a0 <Q_UTF8CodePoint+0x60>
mov    0x14(%rsp),%ebp
cmp    $0x2,%r12d
jb     12a4 <Q_UTF8CodePoint+0x164>
mov    %r12d,%r13d
add    $0x1,%r15
add    $0xffffffffffffffff,%r13
lea    0x8(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebp,%ebx
lea    0x1(%rbx),%r12d
mov    %r15,%rdi
mov    $0x2,%esi
call   1050 <getbit@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <setbit@plt>
mov    %r15,%rdi
mov    $0x3,%esi
call   1050 <getbit@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %eax,%edx
call   1040 <setbit@plt>
mov    %r15,%rdi
mov    $0x4,%esi
call   1050 <getbit@plt>
lea    0x2(%rbx),%esi
mov    %r14,%rdi
mov    %eax,%edx
call   1040 <setbit@plt>
mov    %r15,%rdi
mov    $0x5,%esi
call   1050 <getbit@plt>
lea    0x3(%rbx),%esi
mov    %r14,%rdi
mov    %eax,%edx
call   1040 <setbit@plt>
mov    %r15,%rdi
mov    $0x6,%esi
call   1050 <getbit@plt>
lea    0x4(%rbx),%esi
mov    %r14,%rdi
mov    %eax,%edx
call   1040 <setbit@plt>
lea    0x6(%rbx),%ebp
mov    %r15,%rdi
mov    $0x7,%esi
call   1050 <getbit@plt>
add    $0x5,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <setbit@plt>
add    $0x1,%r15
add    $0xffffffffffffffff,%r13
jne    11f0 <Q_UTF8CodePoint+0xb0>
mov    $0x40,%edx
sub    %ebp,%edx
lea    0x8(%rsp),%rdi
mov    $0x40,%esi
call   1060 <shiftbitsright@plt>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @Q_UTF8CodePoint(i8* %0) {
%2 = alloca i64
%3 = tail call i32 @Q_UTF8Width(i8* %0)
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = icmp ugt i32 %3, 8
%6 = icmp sgt i32 %3, 1
%7 = select i1 %6, i32 %3, i32 1
%8 = select i1 %5, i32 8, i32 %7
%9 = icmp ugt i32 %8, 1
%10 = add nuw nsw i32 %8, 1
%11 = select i1 %9, i32 %10, i32 1
%12 = icmp ult i32 %11, 8
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = sub nuw nsw i32 8, %11
br label %19
15: ; preds = %19, %1
%16 = phi i32 [ 0, %1 ], [ %14, %19 ]
br i1 %9, label %17, label %51
17: ; preds = %15
%18 = zext i32 %8 to i64
br label %27
19: ; preds = %13, %19
%20 = phi i32 [ %25, %19 ], [ %11, %13 ]
%21 = phi i32 [ %22, %19 ], [ 0, %13 ]
%22 = add nuw nsw i32 %21, 1
%23 = call i32 @getbit(i8* %0, i32 %20)
%24 = call i32 @setbit(i8* %4, i32 %21, i32 %23)
%25 = add nuw nsw i32 %20, 1
%26 = icmp eq i32 %22, %14
br i1 %26, label %15, label %19
27: ; preds = %17, %27
%28 = phi i64 [ 1, %17 ], [ %49, %27 ]
%29 = phi i32 [ %16, %17 ], [ %46, %27 ]
%30 = getelementptr inbounds i8, i8* %0, i64 %28
%31 = add i32 %29, 1
%32 = call i32 @getbit(i8* %30, i32 2)
%33 = call i32 @setbit(i8* %4, i32 %29, i32 %32)
%34 = add i32 %29, 2
%35 = call i32 @getbit(i8* %30, i32 3)
%36 = call i32 @setbit(i8* %4, i32 %31, i32 %35)
%37 = add i32 %29, 3
%38 = call i32 @getbit(i8* %30, i32 4)
%39 = call i32 @setbit(i8* %4, i32 %34, i32 %38)
%40 = add i32 %29, 4
%41 = call i32 @getbit(i8* %30, i32 5)
%42 = call i32 @setbit(i8* %4, i32 %37, i32 %41)
%43 = add i32 %29, 5
%44 = call i32 @getbit(i8* %30, i32 6)
%45 = call i32 @setbit(i8* %4, i32 %40, i32 %44)
%46 = add i32 %29, 6
%47 = call i32 @getbit(i8* %30, i32 7)
%48 = call i32 @setbit(i8* %4, i32 %43, i32 %47)
%49 = add nuw nsw i64 %28, 1
%50 = icmp eq i64 %49, %18
br i1 %50, label %51, label %27
51: ; preds = %27, %15
%52 = phi i32 [ %16, %15 ], [ %46, %27 ]
%53 = sub i32 64, %52
%54 = call i32 @shiftbitsright(i8* %4, i32 64, i32 %53)
%55 = load i64, i64* %2
ret i64 %55
}