#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ stderr;
void ut_unicode_to_utf8c(unsigned long unicode, char **dst_p) {
  if (!(unicode & ~0x7F)) {
    *(*dst_p)++ = (char)unicode;
  } else if (!(unicode & ~0x7FF)) {
    *(*dst_p)++ = ((char)(unicode >> 6) & 0x1F) | 0xC0;
    *(*dst_p)++ = ((char)unicode & 0x3F) | 0x80;
  } else if (!(unicode & ~0xFFFF)) {
    *(*dst_p)++ = ((char)(unicode >> 12) & 0x0F) | 0xE0;
    *(*dst_p)++ = ((char)(unicode >> 6) & 0x3F) | 0x80;
    *(*dst_p)++ = ((char)unicode & 0x3F) | 0x80;
  } else {
    {
      fprintf(stderr,
              "ERROR %s:%d:"
              "*** UTF8 CHAR ON 4 BYTES!!!***"
              "\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/Amineahd/utrac/refs/heads/master/src/"
              "ut_conversion.c",
              185);
      exit(-1);
    };
  }
}


x86 assembly (clang, -O0):
<ut_unicode_to_utf8c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
and    $0xffffffffffffff80,%rax
cmp    $0x0,%rax
jne    1160 <ut_unicode_to_utf8c+0x40>
mov    -0x8(%rbp),%rax
mov    %al,%cl
mov    -0x10(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
jmp    1287 <ut_unicode_to_utf8c+0x167>
mov    -0x8(%rbp),%rax
and    $0xfffffffffffff800,%rax
cmp    $0x0,%rax
jne    11c5 <ut_unicode_to_utf8c+0xa5>
mov    -0x8(%rbp),%rax
shr    $0x6,%rax
movsbl %al,%eax
and    $0x1f,%eax
or     $0xc0,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movsbl %al,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
jmp    1282 <ut_unicode_to_utf8c+0x162>
mov    -0x8(%rbp),%rax
and    $0xffffffffffff0000,%rax
cmp    $0x0,%rax
jne    1252 <ut_unicode_to_utf8c+0x132>
mov    -0x8(%rbp),%rax
shr    $0xc,%rax
movsbl %al,%eax
and    $0xf,%eax
or     $0xe0,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
shr    $0x6,%rax
movsbl %al,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movsbl %al,%eax
and    $0x3f,%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
jmp    127d <ut_unicode_to_utf8c+0x15d>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
lea    0xdc3(%rip),%rdx
mov    $0xb9,%ecx
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
jmp    1282 <ut_unicode_to_utf8c+0x162>
jmp    1287 <ut_unicode_to_utf8c+0x167>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ut_unicode_to_utf8c>:
push   %rax
cmp    $0x7f,%rdi
jbe    1178 <ut_unicode_to_utf8c+0x58>
cmp    $0x7ff,%rdi
ja     113b <ut_unicode_to_utf8c+0x1b>
mov    %rdi,%rax
shr    $0x6,%rax
or     $0xc0,%al
jmp    1164 <ut_unicode_to_utf8c+0x44>
cmp    $0xffff,%rdi
ja     1187 <ut_unicode_to_utf8c+0x67>
mov    %rdi,%rax
shr    $0xc,%rax
or     $0xe0,%al
mov    (%rsi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rsi)
mov    %al,(%rcx)
mov    %rdi,%rax
shr    $0x6,%rax
and    $0x3f,%al
or     $0x80,%al
mov    (%rsi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rsi)
mov    %al,(%rcx)
and    $0x3f,%dil
or     $0x80,%dil
mov    (%rsi),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rsi)
mov    %dil,(%rax)
pop    %rax
ret
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
lea    0xe8e(%rip),%rdx
mov    $0xb9,%ecx
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"ERROR %s:%d:*** UTF8 CHAR ON 4 BYTES!!!***\0A\00"
@.str.1 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Amineahd/utrac/refs/heads/master/src/ut_conversion.c\00"
define void @ut_unicode_to_utf8c(i64 %0, i8** %1) {
%3 = alloca i64
%4 = alloca i8**
store i64 %0, i64* %3
store i8** %1, i8*** %4
%5 = load i64, i64* %3
%6 = and i64 %5, -128
%7 = icmp ne i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i64, i64* %3
%10 = trunc i64 %9 to i8
%11 = load i8**, i8*** %4
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %11
store i8 %10, i8* %12
br label %78
14: ; preds = %2
%15 = load i64, i64* %3
%16 = and i64 %15, -2048
%17 = icmp ne i64 %16, 0
br i1 %17, label %38, label %18
18: ; preds = %14
%19 = load i64, i64* %3
%20 = lshr i64 %19, 6
%21 = trunc i64 %20 to i8
%22 = sext i8 %21 to i32
%23 = and i32 %22, 31
%24 = or i32 %23, 192
%25 = trunc i32 %24 to i8
%26 = load i8**, i8*** %4
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %26
store i8 %25, i8* %27
%29 = load i64, i64* %3
%30 = trunc i64 %29 to i8
%31 = sext i8 %30 to i32
%32 = and i32 %31, 63
%33 = or i32 %32, 128
%34 = trunc i32 %33 to i8
%35 = load i8**, i8*** %4
%36 = load i8*, i8** %35
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %35
store i8 %34, i8* %36
br label %77
38: ; preds = %14
%39 = load i64, i64* %3
%40 = and i64 %39, -65536
%41 = icmp ne i64 %40, 0
br i1 %41, label %72, label %42
42: ; preds = %38
%43 = load i64, i64* %3
%44 = lshr i64 %43, 12
%45 = trunc i64 %44 to i8
%46 = sext i8 %45 to i32
%47 = and i32 %46, 15
%48 = or i32 %47, 224
%49 = trunc i32 %48 to i8
%50 = load i8**, i8*** %4
%51 = load i8*, i8** %50
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %50
store i8 %49, i8* %51
%53 = load i64, i64* %3
%54 = lshr i64 %53, 6
%55 = trunc i64 %54 to i8
%56 = sext i8 %55 to i32
%57 = and i32 %56, 63
%58 = or i32 %57, 128
%59 = trunc i32 %58 to i8
%60 = load i8**, i8*** %4
%61 = load i8*, i8** %60
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %60
store i8 %59, i8* %61
%63 = load i64, i64* %3
%64 = trunc i64 %63 to i8
%65 = sext i8 %64 to i32
%66 = and i32 %65, 63
%67 = or i32 %66, 128
%68 = trunc i32 %67 to i8
%69 = load i8**, i8*** %4
%70 = load i8*, i8** %69
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %69
store i8 %68, i8* %70
br label %76
72: ; preds = %38
%73 = load i32, i32* @stderr
%74 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 185)
%75 = call i32 @exit(i32 -1)
unreachable
76: ; preds = %42
br label %77
77: ; preds = %76, %18
br label %78
78: ; preds = %77, %8
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"ERROR %s:%d:*** UTF8 CHAR ON 4 BYTES!!!***\0A\00"
@.str.1 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Amineahd/utrac/refs/heads/master/src/ut_conversion.c\00"
define void @ut_unicode_to_utf8c(i64 %0, i8** nocapture %1) {
%3 = icmp ult i64 %0, 128
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = trunc i64 %0 to i8
%6 = load i8*, i8** %1
%7 = getelementptr inbounds i8, i8* %6, i64 1
store i8* %7, i8** %1
store i8 %5, i8* %6
br label %44
8: ; preds = %2
%9 = icmp ult i64 %0, 2048
br i1 %9, label %10, label %21
10: ; preds = %8
%11 = lshr i64 %0, 6
%12 = trunc i64 %11 to i8
%13 = or i8 %12, -64
%14 = load i8*, i8** %1
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %15, i8** %1
store i8 %13, i8* %14
%16 = trunc i64 %0 to i8
%17 = and i8 %16, 63
%18 = or i8 %17, -128
%19 = load i8*, i8** %1
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8* %20, i8** %1
store i8 %18, i8* %19
br label %44
21: ; preds = %8
%22 = icmp ult i64 %0, 65536
br i1 %22, label %23, label %40
23: ; preds = %21
%24 = lshr i64 %0, 12
%25 = trunc i64 %24 to i8
%26 = or i8 %25, -32
%27 = load i8*, i8** %1
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %1
store i8 %26, i8* %27
%29 = lshr i64 %0, 6
%30 = trunc i64 %29 to i8
%31 = and i8 %30, 63
%32 = or i8 %31, -128
%33 = load i8*, i8** %1
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %1
store i8 %32, i8* %33
%35 = trunc i64 %0 to i8
%36 = and i8 %35, 63
%37 = or i8 %36, -128
%38 = load i8*, i8** %1
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8* %39, i8** %1
store i8 %37, i8* %38
br label %44
40: ; preds = %21
%41 = load i32, i32* @stderr
%42 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 185)
%43 = tail call i32 @exit(i32 -1)
unreachable
44: ; preds = %10, %23, %4
ret void
}