#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*/ internalCheckFail(char *, char *, int);
void putLexCompacted(int value, char **writePointer) {
  {
    if (!(((unsigned)value) < 4194304))
      internalCheckFail("((unsigned) value)<4194304",
                        "/scratch/repos/new/home/jordi_armengol_estape/"
                        "c-scraper/outputs/2022-01-22/02-19-57/repos/thoni56/"
                        "c-xrefactory/refs/heads/main/src/lexembuffer.c",
                        87);
  };
  if (((unsigned)value) < 128) {
    **writePointer = ((unsigned char)value);
    (*writePointer)++;
  } else if (((unsigned)value) < 16384) {
    **writePointer = ((unsigned)value) % 128 + 128;
    (*writePointer)++;
    **writePointer = ((unsigned)value) / 128;
    (*writePointer)++;
  } else {
    **writePointer = ((unsigned)value) % 128 + 128;
    (*writePointer)++;
    **writePointer = ((unsigned)value) / 128 % 128 + 128;
    (*writePointer)++;
    **writePointer = ((unsigned)value) / 16384;
    (*writePointer)++;
  }
}


x86 assembly (clang, -O0):
<putLexCompacted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x400000,-0x4(%rbp)
jb     1144 <putLexCompacted+0x34>
lea    0xecd(%rip),%rdi
lea    0xee1(%rip),%rsi
mov    $0x57,%edx
call   1030 <internalCheckFail@plt>
cmpl   $0x80,-0x4(%rbp)
jae    1172 <putLexCompacted+0x62>
mov    -0x4(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1236 <putLexCompacted+0x126>
cmpl   $0x4000,-0x4(%rbp)
jae    11c7 <putLexCompacted+0xb7>
mov    -0x4(%rbp),%eax
and    $0x7f,%eax
add    $0x80,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x4(%rbp),%eax
shr    $0x7,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1231 <putLexCompacted+0x121>
mov    -0x4(%rbp),%eax
and    $0x7f,%eax
add    $0x80,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x4(%rbp),%eax
shr    $0x7,%eax
and    $0x7f,%eax
add    $0x80,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x4(%rbp),%eax
shr    $0xe,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1236 <putLexCompacted+0x126>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putLexCompacted>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x400000,%edi
jae    112d <putLexCompacted+0x1d>
cmp    $0x7f,%ebp
ja     117f <putLexCompacted+0x6f>
mov    (%rbx),%rax
mov    %bpl,(%rax)
jmp    1174 <putLexCompacted+0x64>
lea    0xecc(%rip),%rdi
lea    0xee0(%rip),%rsi
mov    $0x57,%edx
call   1030 <internalCheckFail@plt>
mov    %ebp,%eax
or     $0x80,%al
mov    (%rbx),%rcx
mov    %al,(%rcx)
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
mov    %ebp,%ecx
shr    $0x7,%ecx
or     $0x80,%cl
mov    %cl,0x1(%rax)
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
shr    $0xe,%ebp
mov    %bpl,0x1(%rax)
addq   $0x1,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
cmp    $0x3fff,%ebp
ja     1145 <putLexCompacted+0x35>
mov    %ebp,%eax
or     $0x80,%al
mov    (%rbx),%rcx
mov    %al,(%rcx)
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
shr    $0x7,%ebp
jmp    1170 <putLexCompacted+0x60>

LLVM IR (-O0):
@.str = [27 x i8] c"((unsigned) value)<4194304\00"
@.str.1 = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/thoni56/c-xrefactory/refs/heads/main/src/lexembuffer.c\00"
define void @putLexCompacted(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
store i32 %0, i32* %3
store i8** %1, i8*** %4
%5 = load i32, i32* %3
%6 = icmp ult i32 %5, 4194304
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 @internalCheckFail(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0), i32 87)
br label %9
9: ; preds = %7, %2
%10 = load i32, i32* %3
%11 = icmp ult i32 %10, 128
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32, i32* %3
%14 = trunc i32 %13 to i8
%15 = load i8**, i8*** %4
%16 = load i8*, i8** %15
store i8 %14, i8* %16
%17 = load i8**, i8*** %4
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %17
br label %70
20: ; preds = %9
%21 = load i32, i32* %3
%22 = icmp ult i32 %21, 16384
br i1 %22, label %23, label %41
23: ; preds = %20
%24 = load i32, i32* %3
%25 = urem i32 %24, 128
%26 = add i32 %25, 128
%27 = trunc i32 %26 to i8
%28 = load i8**, i8*** %4
%29 = load i8*, i8** %28
store i8 %27, i8* %29
%30 = load i8**, i8*** %4
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %30
%33 = load i32, i32* %3
%34 = udiv i32 %33, 128
%35 = trunc i32 %34 to i8
%36 = load i8**, i8*** %4
%37 = load i8*, i8** %36
store i8 %35, i8* %37
%38 = load i8**, i8*** %4
%39 = load i8*, i8** %38
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %38
br label %69
41: ; preds = %20
%42 = load i32, i32* %3
%43 = urem i32 %42, 128
%44 = add i32 %43, 128
%45 = trunc i32 %44 to i8
%46 = load i8**, i8*** %4
%47 = load i8*, i8** %46
store i8 %45, i8* %47
%48 = load i8**, i8*** %4
%49 = load i8*, i8** %48
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %48
%51 = load i32, i32* %3
%52 = udiv i32 %51, 128
%53 = urem i32 %52, 128
%54 = add i32 %53, 128
%55 = trunc i32 %54 to i8
%56 = load i8**, i8*** %4
%57 = load i8*, i8** %56
store i8 %55, i8* %57
%58 = load i8**, i8*** %4
%59 = load i8*, i8** %58
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %58
%61 = load i32, i32* %3
%62 = udiv i32 %61, 16384
%63 = trunc i32 %62 to i8
%64 = load i8**, i8*** %4
%65 = load i8*, i8** %64
store i8 %63, i8* %65
%66 = load i8**, i8*** %4
%67 = load i8*, i8** %66
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %66
br label %69
69: ; preds = %41, %23
br label %70
70: ; preds = %69, %12
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"((unsigned) value)<4194304\00"
@.str.1 = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/thoni56/c-xrefactory/refs/heads/main/src/lexembuffer.c\00"
define void @putLexCompacted(i32 %0, i8** nocapture %1) {
%3 = icmp ult i32 %0, 4194304
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @internalCheckFail(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0), i32 87)
br label %21
6: ; preds = %2
%7 = icmp ult i32 %0, 128
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = trunc i32 %0 to i8
%10 = load i8*, i8** %1
store i8 %9, i8* %10
br label %34
11: ; preds = %6
%12 = icmp ult i32 %0, 16384
br i1 %12, label %13, label %21
13: ; preds = %11
%14 = trunc i32 %0 to i8
%15 = or i8 %14, -128
%16 = load i8*, i8** %1
store i8 %15, i8* %16
%17 = load i8*, i8** %1
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %18, i8** %1
%19 = lshr i32 %0, 7
%20 = trunc i32 %19 to i8
store i8 %20, i8* %18
br label %34
21: ; preds = %4, %11
%22 = trunc i32 %0 to i8
%23 = or i8 %22, -128
%24 = load i8*, i8** %1
store i8 %23, i8* %24
%25 = load i8*, i8** %1
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %26, i8** %1
%27 = lshr i32 %0, 7
%28 = trunc i32 %27 to i8
%29 = or i8 %28, -128
store i8 %29, i8* %26
%30 = load i8*, i8** %1
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8* %31, i8** %1
%32 = lshr i32 %0, 14
%33 = trunc i32 %32 to i8
store i8 %33, i8* %31
br label %34
34: ; preds = %13, %21, %8
%35 = load i8*, i8** %1
%36 = getelementptr inbounds i8, i8* %35, i64 1
store i8* %36, i8** %1
ret void
}