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

/* Variables and functions */
int /*<<< orphan*/ LC_CTYPE;
int MB_CUR_MAX;
int /*<<< orphan*/ MB_LEN_MAX;
int /*<<< orphan*/ assert(int);
int mblen(char *, int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int main(int argc, char *argv[]) {
  size_t len;
  char buf[MB_LEN_MAX + 1];
  printf("1..1\n");
  assert(MB_CUR_MAX == 1);
  assert(mblen(NULL, 0) == 0);
  memset(buf, 0xcc, sizeof(buf));
  buf[0] = '\0';
  assert(mblen(buf, 1) == 0);
  buf[0] = 'A';
  assert(mblen(buf, 1) == 1);
  buf[0] = '\0';
  assert(mblen(buf, 0) == -1);
  assert(mblen(NULL, 0) == 0);
  assert(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
  assert(MB_CUR_MAX > 1);
  assert(mblen(NULL, 0) == 0);
  memset(buf, 0xcc, sizeof(buf));
  buf[0] = '\0';
  assert(mblen(buf, 1) == 0);
  buf[0] = 'A';
  assert(mblen(buf, 1) == 1);
  buf[0] = '\0';
  assert(mblen(buf, 0) == -1);
  assert(mblen(NULL, 0) == 0);
  memset(buf, 0xcc, sizeof(buf));
  buf[0] = 0xa3;
  buf[1] = 0x00;
  assert(mblen(buf, 1) == -1);
  assert(mblen(NULL, 0) == 0);
  buf[1] = 0xc1;
  assert(mblen(buf, 2) == 2);
  printf("ok 1 - mblen()\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e3c(%rip),%rax
cmpl   $0x1,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1030 <mblen@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%edx
mov    $0xcc,%esi
call   1050 <memset@plt>
mov    -0x30(%rbp),%rdi
movb   $0x0,(%rdi)
mov    $0x1,%esi
call   1030 <mblen@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x30(%rbp),%rdi
movb   $0x41,(%rdi)
mov    $0x1,%esi
call   1030 <mblen@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x30(%rbp),%rdi
movb   $0x0,(%rdi)
xor    %esi,%esi
call   1030 <mblen@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1030 <mblen@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
call   1080 <setlocale@plt>
mov    %eax,%edi
lea    0xd72(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    0x2d47(%rip),%rax
cmpl   $0x1,(%rax)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1030 <mblen@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%edx
mov    $0xcc,%esi
call   1050 <memset@plt>
mov    -0x30(%rbp),%rdi
movb   $0x0,(%rdi)
mov    $0x1,%esi
call   1030 <mblen@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x30(%rbp),%rdi
movb   $0x41,(%rdi)
mov    $0x1,%esi
call   1030 <mblen@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x30(%rbp),%rdi
movb   $0x0,(%rdi)
xor    %esi,%esi
call   1030 <mblen@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1030 <mblen@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%edx
mov    $0xcc,%esi
call   1050 <memset@plt>
mov    -0x30(%rbp),%rdi
movb   $0xa3,(%rdi)
movb   $0x0,0x1(%rdi)
mov    $0x1,%esi
call   1030 <mblen@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1030 <mblen@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x30(%rbp),%rdi
movb   $0xc1,0x1(%rdi)
mov    $0x2,%esi
call   1030 <mblen@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xc2a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e5b(%rip),%rax
mov    (%rax),%r14d
add    $0x1,%r14d
mov    %rsp,%r12
lea    0xf(%r14),%r13
and    $0xfffffffffffffff0,%r13
mov    %r12,%rbx
sub    %r13,%rbx
mov    %rbx,%rsp
lea    0xe75(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e55(%rip),%rax
xor    %edi,%edi
cmpl   $0x1,(%rax)
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
mov    $0xcc,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
movb   $0x0,(%rbx)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
movb   $0x41,(%rbx)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1070 <assert@plt>
movb   $0x0,(%rbx)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%r15
mov    %r15,%rsi
call   1080 <setlocale@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1060 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
mov    0x2d7c(%rip),%rax
cmpl   $0x2,(%rax)
setge  %dil
call   1070 <assert@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
mov    $0xcc,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
movb   $0x0,(%rbx)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
movb   $0x41,(%rbx)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1070 <assert@plt>
movb   $0x0,(%rbx)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
mov    $0xcc,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
movw   $0xa3,(%rbx)
neg    %r13
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
movb   $0xc1,0x1(%r12,%r13,1)
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <mblen@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1070 <assert@plt>
lea    0xc86(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MB_LEN_MAX = global i32 0
@.str = [6 x i8] c"1..1\0A\00"
@MB_CUR_MAX = global i32 0
@LC_CTYPE = global i32 0
@.str.1 = [12 x i8] c"ja_JP.eucJP\00"
@.str.2 = [16 x i8] c"ok 1 - mblen()\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @MB_LEN_MAX
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @MB_CUR_MAX
%16 = icmp eq i32 %15, 1
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i32 @mblen(i8* null, i32 0)
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = trunc i64 %11 to i32
%24 = call i32 @memset(i8* %13, i32 204, i32 %23)
%25 = getelementptr inbounds i8, i8* %13, i64 0
store i8 0, i8* %25
%26 = call i32 @mblen(i8* %13, i32 1)
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = getelementptr inbounds i8, i8* %13, i64 0
store i8 65, i8* %30
%31 = call i32 @mblen(i8* %13, i32 1)
%32 = icmp eq i32 %31, 1
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = getelementptr inbounds i8, i8* %13, i64 0
store i8 0, i8* %35
%36 = call i32 @mblen(i8* %13, i32 0)
%37 = icmp eq i32 %36, -1
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = call i32 @mblen(i8* null, i32 0)
%41 = icmp eq i32 %40, 0
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i32, i32* @LC_CTYPE
%45 = call i32 @setlocale(i32 %44, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%46 = call i64 @strcmp(i32 %45, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i32, i32* @MB_CUR_MAX
%51 = icmp sgt i32 %50, 1
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = call i32 @mblen(i8* null, i32 0)
%55 = icmp eq i32 %54, 0
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = trunc i64 %11 to i32
%59 = call i32 @memset(i8* %13, i32 204, i32 %58)
%60 = getelementptr inbounds i8, i8* %13, i64 0
store i8 0, i8* %60
%61 = call i32 @mblen(i8* %13, i32 1)
%62 = icmp eq i32 %61, 0
%63 = zext i1 %62 to i32
%64 = call i32 @assert(i32 %63)
%65 = getelementptr inbounds i8, i8* %13, i64 0
store i8 65, i8* %65
%66 = call i32 @mblen(i8* %13, i32 1)
%67 = icmp eq i32 %66, 1
%68 = zext i1 %67 to i32
%69 = call i32 @assert(i32 %68)
%70 = getelementptr inbounds i8, i8* %13, i64 0
store i8 0, i8* %70
%71 = call i32 @mblen(i8* %13, i32 0)
%72 = icmp eq i32 %71, -1
%73 = zext i1 %72 to i32
%74 = call i32 @assert(i32 %73)
%75 = call i32 @mblen(i8* null, i32 0)
%76 = icmp eq i32 %75, 0
%77 = zext i1 %76 to i32
%78 = call i32 @assert(i32 %77)
%79 = trunc i64 %11 to i32
%80 = call i32 @memset(i8* %13, i32 204, i32 %79)
%81 = getelementptr inbounds i8, i8* %13, i64 0
store i8 -93, i8* %81
%82 = getelementptr inbounds i8, i8* %13, i64 1
store i8 0, i8* %82
%83 = call i32 @mblen(i8* %13, i32 1)
%84 = icmp eq i32 %83, -1
%85 = zext i1 %84 to i32
%86 = call i32 @assert(i32 %85)
%87 = call i32 @mblen(i8* null, i32 0)
%88 = icmp eq i32 %87, 0
%89 = zext i1 %88 to i32
%90 = call i32 @assert(i32 %89)
%91 = getelementptr inbounds i8, i8* %13, i64 1
store i8 -63, i8* %91
%92 = call i32 @mblen(i8* %13, i32 2)
%93 = icmp eq i32 %92, 2
%94 = zext i1 %93 to i32
%95 = call i32 @assert(i32 %94)
%96 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
%97 = load i8*, i8** %7
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
@MB_LEN_MAX = global i32 0
@MB_CUR_MAX = global i32 0
@LC_CTYPE = global i32 0
@.str.1 = [12 x i8] c"ja_JP.eucJP\00"
@str = [5 x i8] c"1..1\00"
@str.3 = [15 x i8] c"ok 1 - mblen()\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @MB_LEN_MAX
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* @MB_CUR_MAX
%9 = icmp eq i32 %8, 1
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i32 @mblen(i8* null, i32 0)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = call i32 @memset(i8* %6, i32 204, i32 %4)
store i8 0, i8* %6
%17 = call i32 @mblen(i8* %6, i32 1)
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
store i8 65, i8* %6
%21 = call i32 @mblen(i8* %6, i32 1)
%22 = icmp eq i32 %21, 1
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
store i8 0, i8* %6
%25 = call i32 @mblen(i8* %6, i32 0)
%26 = icmp eq i32 %25, -1
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i32 @mblen(i8* null, i32 0)
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load i32, i32* @LC_CTYPE
%34 = call i32 @setlocale(i32 %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%35 = call i64 @strcmp(i32 %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i32, i32* @MB_CUR_MAX
%40 = icmp sgt i32 %39, 1
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = call i32 @mblen(i8* null, i32 0)
%44 = icmp eq i32 %43, 0
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = call i32 @memset(i8* %6, i32 204, i32 %4)
store i8 0, i8* %6
%48 = call i32 @mblen(i8* %6, i32 1)
%49 = icmp eq i32 %48, 0
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
store i8 65, i8* %6
%52 = call i32 @mblen(i8* %6, i32 1)
%53 = icmp eq i32 %52, 1
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
store i8 0, i8* %6
%56 = call i32 @mblen(i8* %6, i32 0)
%57 = icmp eq i32 %56, -1
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
%60 = call i32 @mblen(i8* null, i32 0)
%61 = icmp eq i32 %60, 0
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
%64 = call i32 @memset(i8* %6, i32 204, i32 %4)
store i8 -93, i8* %6
%65 = getelementptr inbounds i8, i8* %6, i64 1
store i8 0, i8* %65
%66 = call i32 @mblen(i8* %6, i32 1)
%67 = icmp eq i32 %66, -1
%68 = zext i1 %67 to i32
%69 = call i32 @assert(i32 %68)
%70 = call i32 @mblen(i8* null, i32 0)
%71 = icmp eq i32 %70, 0
%72 = zext i1 %71 to i32
%73 = call i32 @assert(i32 %72)
store i8 -63, i8* %65
%74 = call i32 @mblen(i8* %6, i32 2)
%75 = icmp eq i32 %74, 2
%76 = zext i1 %75 to i32
%77 = call i32 @assert(i32 %76)
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.3, i64 0, i64 0))
ret i32 0
}