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

/* Variables and functions */
int /*<<< orphan*/ LC_CTYPE;
int /*<<< orphan*/ assert(int);
int mbrlen(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
main() {
  static mbstate_t ps;
  setlocale(LC_CTYPE, "de_DE.UTF8");
  assert(mbrlen("\xc2\xa9", 2, &ps) == 2);
  assert(mbrlen("\xa9", 1, &ps) == (size_t)-1);
  printf("%d\n", mbrlen("\xc2\xa9", 1, &ps));
  printf("%d\n", mbrlen("\xa9"
                        "fnord",
                        6, &ps));
  assert(mbrlen("f", 1, &ps) == 1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
call   1060 <setlocale@plt>
lea    0xeab(%rip),%rdi
mov    $0x2,%esi
lea    0x2ed8(%rip),%rdx
call   1050 <mbrlen@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe84(%rip),%rdi
mov    $0x1,%esi
lea    0x2eb0(%rip),%rdx
call   1050 <mbrlen@plt>
cltq
cmp    $0xffffffffffffffff,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe58(%rip),%rdi
mov    $0x1,%esi
lea    0x2e85(%rip),%rdx
call   1050 <mbrlen@plt>
mov    %eax,%esi
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
lea    0xe39(%rip),%rdi
mov    $0x6,%esi
lea    0x2e5f(%rip),%rdx
call   1050 <mbrlen@plt>
mov    %eax,%esi
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
lea    0xe1a(%rip),%rdi
mov    $0x1,%esi
lea    0x2e39(%rip),%rdx
call   1050 <mbrlen@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
call   1060 <setlocale@plt>
lea    0xeaa(%rip),%r14
lea    0x2edc(%rip),%r15
mov    %r14,%rdi
mov    $0x2,%esi
mov    %r15,%rdx
call   1050 <mbrlen@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1040 <assert@plt>
lea    0xe7f(%rip),%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   1050 <mbrlen@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   1050 <mbrlen@plt>
lea    0xe4f(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0xe42(%rip),%rdi
mov    $0x6,%esi
mov    %r15,%rdx
call   1050 <mbrlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0xe2b(%rip),%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   1050 <mbrlen@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@main.ps = internal global i32 0
@LC_CTYPE = global i32 0
@.str = [11 x i8] c"de_DE.UTF8\00"
@.str.1 = [3 x i8] c"\C2\A9\00"
@.str.2 = [2 x i8] c"\A9\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [7 x i8] c"\A9fnord\00"
@.str.5 = [2 x i8] c"f\00"
define i32 @main() {
%1 = load i32, i32* @LC_CTYPE
%2 = call i32 @setlocale(i32 %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @mbrlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2, i32* @main.ps)
%4 = icmp eq i32 %3, 2
%5 = zext i1 %4 to i32
%6 = call i32 @assert(i32 %5)
%7 = call i32 @mbrlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1, i32* @main.ps)
%8 = sext i32 %7 to i64
%9 = icmp eq i64 %8, -1
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = call i32 @mbrlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1, i32* @main.ps)
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = call i32 @mbrlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6, i32* @main.ps)
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = call i32 @mbrlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1, i32* @main.ps)
%17 = icmp eq i32 %16, 1
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
ret i32 0
}

LLVM IR (-O2):
@main.ps = internal global i32 0
@LC_CTYPE = global i32 0
@.str = [11 x i8] c"de_DE.UTF8\00"
@.str.1 = [3 x i8] c"\C2\A9\00"
@.str.2 = [2 x i8] c"\A9\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [7 x i8] c"\A9fnord\00"
@.str.5 = [2 x i8] c"f\00"
define i32 @main() {
%1 = load i32, i32* @LC_CTYPE
%2 = tail call i32 @setlocale(i32 %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @mbrlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2, i32* @main.ps)
%4 = icmp eq i32 %3, 2
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 @mbrlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1, i32* @main.ps)
%8 = icmp eq i32 %7, -1
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @mbrlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1, i32* @main.ps)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = tail call i32 @mbrlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6, i32* @main.ps)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = tail call i32 @mbrlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1, i32* @main.ps)
%16 = icmp eq i32 %15, 1
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
ret i32 0
}