#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 u_int32_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const, char *, int);
int /*<<< orphan*/ stderr;
int u8_seqlen(char const *);
u_int32_t next_u8_carac(const char *s, int *i) {
  u_int32_t u8_char;
  int nb_bytes = u8_seqlen(&s[*i]);
  switch (nb_bytes) {
  case 1:
    u8_char = (s[*i + 0] & 0xFF);
    break;
  case 2:
    u8_char = ((s[*i + 0] & 0xFF) * 0x0100) + (s[*i + 1] & 0xFF);
    break;
  case 3:
    u8_char = ((s[*i + 0] & 0xFF) * 0x100 * 0x100) +
              ((s[*i + 1] & 0xFF) * 0x100) + (s[*i + 2] & 0xFF);
    u8_char &= 0x00FFFFFF;
    break;
  case 4:
    u8_char = ((s[*i + 0] & 0xFF) * 0x100 * 0x100 * 0x100) +
              ((s[*i + 1] & 0xFF) * 0x100 * 0x100) +
              ((s[*i + 2] & 0xFF) * 0x100) + (s[*i + 3] & 0xFF);
    u8_char &= 0xFFFFFFFF;
    break;
  default:
    fprintf(stderr,
            "next_u8_char() failed - invalid character %c."
            " - %s:%d\n",
            s[*i + 0],
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/msoula/romhacking/refs/heads/master/"
            "hacks/knt/src/utils/spc_utf8.c",
            82);
    exit(EXIT_FAILURE);
    break;
  }
  (*i) += nb_bytes;
  return u8_char;
}


x86 assembly (clang, -O0):
<next_u8_carac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rdi
call   1030 <u8_seqlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     12dd <next_u8_carac+0x1ad>
mov    -0x20(%rbp),%rax
lea    0xe8a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
jmp    1321 <next_u8_carac+0x1f1>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rdx
mov    (%rdx),%edx
add    $0x1,%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1321 <next_u8_carac+0x1f1>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
shl    $0x8,%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rdx
mov    (%rdx),%edx
add    $0x1,%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
and    $0xff,%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rdx
mov    (%rdx),%edx
add    $0x2,%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1321 <next_u8_carac+0x1f1>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
shl    $0x8,%eax
shl    $0x8,%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rdx
mov    (%rdx),%edx
add    $0x1,%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
and    $0xff,%ecx
shl    $0x8,%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rdx
mov    (%rdx),%edx
add    $0x2,%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
and    $0xff,%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rdx
mov    (%rdx),%edx
add    $0x3,%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1321 <next_u8_carac+0x1f1>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x0,%ecx
movslq %ecx,%rdx
lea    0xd13(%rip),%rsi
lea    0xd43(%rip),%rcx
mov    $0x52,%r8d
movsbl (%rax,%rdx,1),%edx
call   1040 <fprintf@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_u8_carac>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movslq (%rsi),%rdi
add    %rbx,%rdi
call   1030 <u8_seqlen@plt>
lea    -0x1(%rax),%ecx
cmp    $0x3,%ecx
ja     11a6 <next_u8_carac+0x76>
lea    0xeac(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
movslq (%r14),%rdx
movzbl (%rbx,%rdx,1),%ecx
jmp    1197 <next_u8_carac+0x67>
movslq (%r14),%rdx
movzbl (%rbx,%rdx,1),%ecx
shl    $0x10,%ecx
movzbl 0x1(%rbx,%rdx,1),%esi
shl    $0x8,%esi
or     %ecx,%esi
movzbl 0x2(%rbx,%rdx,1),%ecx
or     %esi,%ecx
jmp    1197 <next_u8_carac+0x67>
movslq (%r14),%rdx
movzwl (%rbx,%rdx,1),%ecx
shl    $0x10,%ecx
jmp    1195 <next_u8_carac+0x65>
movslq (%r14),%rdx
mov    (%rbx,%rdx,1),%ecx
bswap  %ecx
add    %eax,%edx
mov    %edx,(%r14)
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
movslq (%r14),%rax
movsbl (%rbx,%rax,1),%edx
lea    0xe53(%rip),%rsi
lea    0xe83(%rip),%rcx
mov    $0x52,%r8d
call   1040 <fprintf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [55 x i8] c"next_u8_char() failed - invalid character %c. - %s:%d\0A\00"
@.str.1 = [157 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/msoula/romhacking/refs/heads/master/hacks/knt/src/utils/spc_utf8.c\00"
@EXIT_FAILURE = global i32 0
define i32 @next_u8_carac(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%7 = load i8*, i8** %3
%8 = load i32*, i32** %4
%9 = load i32, i32* %8
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
%12 = call i32 @u8_seqlen(i8* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
switch i32 %13, label %128 [
i32 1, label %14
i32 2, label %24
i32 3, label %45
i32 4, label %80
]
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i32*, i32** %4
%17 = load i32, i32* %16
%18 = add nsw i32 %17, 0
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = and i32 %22, 255
store i32 %23, i32* %5
br label %140
24: ; preds = %2
%25 = load i8*, i8** %3
%26 = load i32*, i32** %4
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 0
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = and i32 %32, 255
%34 = mul nsw i32 %33, 256
%35 = load i8*, i8** %3
%36 = load i32*, i32** %4
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %35, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = and i32 %42, 255
%44 = add nsw i32 %34, %43
store i32 %44, i32* %5
br label %140
45: ; preds = %2
%46 = load i8*, i8** %3
%47 = load i32*, i32** %4
%48 = load i32, i32* %47
%49 = add nsw i32 %48, 0
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %46, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = and i32 %53, 255
%55 = mul nsw i32 %54, 256
%56 = mul nsw i32 %55, 256
%57 = load i8*, i8** %3
%58 = load i32*, i32** %4
%59 = load i32, i32* %58
%60 = add nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %57, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = and i32 %64, 255
%66 = mul nsw i32 %65, 256
%67 = add nsw i32 %56, %66
%68 = load i8*, i8** %3
%69 = load i32*, i32** %4
%70 = load i32, i32* %69
%71 = add nsw i32 %70, 2
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %68, i64 %72
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = and i32 %75, 255
%77 = add nsw i32 %67, %76
store i32 %77, i32* %5
%78 = load i32, i32* %5
%79 = and i32 %78, 16777215
store i32 %79, i32* %5
br label %140
80: ; preds = %2
%81 = load i8*, i8** %3
%82 = load i32*, i32** %4
%83 = load i32, i32* %82
%84 = add nsw i32 %83, 0
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %81, i64 %85
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = and i32 %88, 255
%90 = mul nsw i32 %89, 256
%91 = mul nsw i32 %90, 256
%92 = mul nsw i32 %91, 256
%93 = load i8*, i8** %3
%94 = load i32*, i32** %4
%95 = load i32, i32* %94
%96 = add nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %93, i64 %97
%99 = load i8, i8* %98
%100 = sext i8 %99 to i32
%101 = and i32 %100, 255
%102 = mul nsw i32 %101, 256
%103 = mul nsw i32 %102, 256
%104 = add nsw i32 %92, %103
%105 = load i8*, i8** %3
%106 = load i32*, i32** %4
%107 = load i32, i32* %106
%108 = add nsw i32 %107, 2
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8, i8* %105, i64 %109
%111 = load i8, i8* %110
%112 = sext i8 %111 to i32
%113 = and i32 %112, 255
%114 = mul nsw i32 %113, 256
%115 = add nsw i32 %104, %114
%116 = load i8*, i8** %3
%117 = load i32*, i32** %4
%118 = load i32, i32* %117
%119 = add nsw i32 %118, 3
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds i8, i8* %116, i64 %120
%122 = load i8, i8* %121
%123 = sext i8 %122 to i32
%124 = and i32 %123, 255
%125 = add nsw i32 %115, %124
store i32 %125, i32* %5
%126 = load i32, i32* %5
%127 = and i32 %126, -1
store i32 %127, i32* %5
br label %140
128: ; preds = %2
%129 = load i32, i32* @stderr
%130 = load i8*, i8** %3
%131 = load i32*, i32** %4
%132 = load i32, i32* %131
%133 = add nsw i32 %132, 0
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds i8, i8* %130, i64 %134
%136 = load i8, i8* %135
%137 = call i32 @fprintf(i32 %129, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8 signext %136, i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.1, i64 0, i64 0), i32 82)
%138 = load i32, i32* @EXIT_FAILURE
%139 = call i32 @exit(i32 %138)
unreachable
140: ; preds = %80, %45, %24, %14
%141 = load i32, i32* %6
%142 = load i32*, i32** %4
%143 = load i32, i32* %142
%144 = add nsw i32 %143, %141
store i32 %144, i32* %142
%145 = load i32, i32* %5
ret i32 %145
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [55 x i8] c"next_u8_char() failed - invalid character %c. - %s:%d\0A\00"
@.str.1 = [157 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/msoula/romhacking/refs/heads/master/hacks/knt/src/utils/spc_utf8.c\00"
@EXIT_FAILURE = global i32 0
define i32 @next_u8_carac(i8* %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = tail call i32 @u8_seqlen(i8* %5)
switch i32 %6, label %73 [
i32 1, label %7
i32 2, label %13
i32 3, label %26
i32 4, label %46
]
7: ; preds = %2
%8 = load i32, i32* %1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
br label %82
13: ; preds = %2
%14 = load i32, i32* %1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = shl nuw nsw i32 %18, 8
%20 = add nsw i32 %14, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = or i32 %19, %24
br label %82
26: ; preds = %2
%27 = load i32, i32* %1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = shl nuw nsw i32 %31, 16
%33 = add nsw i32 %27, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %0, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = shl nuw nsw i32 %37, 8
%39 = or i32 %38, %32
%40 = add nsw i32 %27, 2
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %0, i64 %41
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = or i32 %39, %44
br label %82
46: ; preds = %2
%47 = load i32, i32* %1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %0, i64 %48
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = shl nuw nsw i32 %51, 24
%53 = add nsw i32 %47, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %0, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = shl nuw nsw i32 %57, 16
%59 = or i32 %58, %52
%60 = add nsw i32 %47, 2
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %0, i64 %61
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = shl nuw nsw i32 %64, 8
%66 = or i32 %59, %65
%67 = add nsw i32 %47, 3
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %0, i64 %68
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = or i32 %66, %71
br label %82
73: ; preds = %2
%74 = load i32, i32* @stderr
%75 = load i32, i32* %1
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %0, i64 %76
%78 = load i8, i8* %77
%79 = tail call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8 signext %78, i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.1, i64 0, i64 0), i32 82)
%80 = load i32, i32* @EXIT_FAILURE
%81 = tail call i32 @exit(i32 %80)
unreachable
82: ; preds = %46, %26, %13, %7
%83 = phi i32 [ %47, %46 ], [ %27, %26 ], [ %14, %13 ], [ %8, %7 ]
%84 = phi i32 [ %72, %46 ], [ %45, %26 ], [ %25, %13 ], [ %12, %7 ]
%85 = add nsw i32 %83, %6
store i32 %85, i32* %1
ret i32 %84
}