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

/* Variables and functions */
int /*<<< orphan*/ LC_CTYPE;
int /*<<< orphan*/ MB_CUR_MAX;
int /*<<< orphan*/ SIZE_MAX;
int mbtowc(int *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ *setlocale(int /*<<< orphan*/, char *);
int main(void) {
  wchar_t wc;
  if (setlocale(LC_CTYPE, "de_DE.UTF-8") == NULL) {
    puts("setlocale failed");
    return 1;
  }
  if (mbtowc(&wc, "\xc3\xa1", MB_CUR_MAX) != 2 || wc != 0xE1) {
    puts("1st mbtowc failed");
    return 1;
  }
  if (mbtowc(&wc, "\xc3\xa1", SIZE_MAX) != 2 || wc != 0xE1) {
    puts("2nd mbtowc failed");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    0xeb1(%rip),%rsi
call   1050 <setlocale@plt>
cmp    $0x0,%rax
jne    1176 <main+0x46>
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    120b <main+0xdb>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1040 <mbtowc@plt>
cmp    $0x2,%eax
jne    11a5 <main+0x75>
cmpl   $0xe1,-0x8(%rbp)
je     11bd <main+0x8d>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    120b <main+0xdb>
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1040 <mbtowc@plt>
cmp    $0x2,%eax
jne    11ec <main+0xbc>
cmpl   $0xe1,-0x8(%rbp)
je     1204 <main+0xd4>
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    120b <main+0xdb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ea8(%rip),%rax
mov    (%rax),%edi
lea    0xebf(%rip),%rsi
call   1050 <setlocale@plt>
test   %rax,%rax
je     11a1 <main+0x71>
mov    0x2ea6(%rip),%rax
mov    (%rax),%edx
lea    0xec2(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1040 <mbtowc@plt>
cmp    $0x2,%eax
jne    11aa <main+0x7a>
cmpl   $0xe1,0x4(%rsp)
jne    11aa <main+0x7a>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edx
lea    0xe99(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1040 <mbtowc@plt>
cmp    $0x2,%eax
jne    11b3 <main+0x83>
xor    %eax,%eax
cmpl   $0xe1,0x4(%rsp)
jne    11b3 <main+0x83>
pop    %rcx
ret
lea    0xe64(%rip),%rdi
jmp    11ba <main+0x8a>
lea    0xe6f(%rip),%rdi
jmp    11ba <main+0x8a>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@LC_CTYPE = global i32 0
@.str = [12 x i8] c"de_DE.UTF-8\00"
@.str.1 = [17 x i8] c"setlocale failed\00"
@.str.2 = [3 x i8] c"\C3\A1\00"
@MB_CUR_MAX = global i32 0
@.str.3 = [18 x i8] c"1st mbtowc failed\00"
@SIZE_MAX = global i32 0
@.str.4 = [18 x i8] c"2nd mbtowc failed\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @LC_CTYPE
%4 = call i32* @setlocale(i32 %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %27
8: ; preds = %0
%9 = load i32, i32* @MB_CUR_MAX
%10 = call i32 @mbtowc(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = icmp ne i32 %10, 2
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 225
br i1 %14, label %15, label %17
15: ; preds = %12, %8
%16 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %27
17: ; preds = %12
%18 = load i32, i32* @SIZE_MAX
%19 = call i32 @mbtowc(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = icmp ne i32 %19, 2
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = load i32, i32* %2
%23 = icmp ne i32 %22, 225
br i1 %23, label %24, label %26
24: ; preds = %21, %17
%25 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %27
26: ; preds = %21
store i32 0, i32* %1
br label %27
27: ; preds = %26, %24, %15, %6
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@LC_CTYPE = global i32 0
@.str = [12 x i8] c"de_DE.UTF-8\00"
@.str.1 = [17 x i8] c"setlocale failed\00"
@.str.2 = [3 x i8] c"\C3\A1\00"
@MB_CUR_MAX = global i32 0
@.str.3 = [18 x i8] c"1st mbtowc failed\00"
@SIZE_MAX = global i32 0
@.str.4 = [18 x i8] c"2nd mbtowc failed\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @LC_CTYPE
%4 = tail call i32* @setlocale(i32 %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %26
8: ; preds = %0
%9 = load i32, i32* @MB_CUR_MAX
%10 = call i32 @mbtowc(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = icmp ne i32 %10, 2
%12 = load i32, i32* %1
%13 = icmp ne i32 %12, 225
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %26
17: ; preds = %8
%18 = load i32, i32* @SIZE_MAX
%19 = call i32 @mbtowc(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = icmp ne i32 %19, 2
%21 = load i32, i32* %1
%22 = icmp ne i32 %21, 225
%23 = select i1 %20, i1 true, i1 %22
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %17, %24, %15, %6
%27 = phi i32 [ 1, %6 ], [ 1, %15 ], [ 1, %24 ], [ 0, %17 ]
ret i32 %27
}