#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;
typedef int /*<<< orphan*/ state;
typedef int /*<<< orphan*/ mbstate_t;

/* Variables and functions */
int /*<<< orphan*/ LC_CTYPE;
scalar_t__ memcmp(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
char *setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stdout;
int strcmp(char const *, char *);
size_t wcrtomb(char *, int const, int /*<<< orphan*/ *);
int main(void) {
  unsigned char buf[7] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  const unsigned char bufcheck[7] = {0x25, 0xe2, 0x82, 0xac, 0xce, 0xbb, 0};
  const wchar_t srcbuf[4] = {0x25, 0x20ac, 0x03bb, 0};
  mbstate_t state;
  const wchar_t *src;
  char *dst;
  int result = 0;
  const char *used_locale;
  setlocale(LC_CTYPE, "de_DE.UTF-8");
  used_locale = setlocale(LC_CTYPE, NULL);
  printf("used locale: \"%s\"\n", used_locale);
  result = strcmp(used_locale, "de_DE.UTF-8");
  memset(&state, '\0', sizeof(state));
  src = srcbuf;
  dst = (char *)buf;
  {
    size_t res = wcrtomb(dst, *src++, &state);
    printf("wcrtomb (dst, *src++, &state)"
           " -> %Zd",
           res);
    dst += res;
    printf(", dst = buf+%td", dst - (char *)buf);
    if (res != 1 || dst != (char *)(buf + 1)) {
      printf(", expected %Zd and buf+%td", 1, (buf + 1) - (unsigned char *)buf);
      result = 1;
    }
    putc('\n', stdout);
  };
  {
    size_t res = wcrtomb(dst, *src++, &state);
    printf("wcrtomb (dst, *src++, &state)"
           " -> %Zd",
           res);
    dst += res;
    printf(", dst = buf+%td", dst - (char *)buf);
    if (res != 3 || dst != (char *)(buf + 4)) {
      printf(", expected %Zd and buf+%td", 3, (buf + 4) - (unsigned char *)buf);
      result = 1;
    }
    putc('\n', stdout);
  };
  {
    size_t res = wcrtomb(dst, *src++, &state);
    printf("wcrtomb (dst, *src++, &state)"
           " -> %Zd",
           res);
    dst += res;
    printf(", dst = buf+%td", dst - (char *)buf);
    if (res != 2 || dst != (char *)(buf + 6)) {
      printf(", expected %Zd and buf+%td", 2, (buf + 6) - (unsigned char *)buf);
      result = 1;
    }
    putc('\n', stdout);
  };
  {
    size_t res = wcrtomb(dst, *src, &state);
    printf("wcrtomb (dst, *src, &state)"
           " -> %Zd",
           res);
    dst += res;
    printf(", dst = buf+%td", dst - (char *)buf);
    if (res != 1 || dst != (char *)(buf + 7)) {
      printf(", expected %Zd and buf+%td", 1, (buf + 7) - (unsigned char *)buf);
      result = 1;
    }
    putc('\n', stdout);
  };
  if (memcmp(buf, bufcheck, 7)) {
    puts("wrong results");
    result = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe68(%rip),%eax
mov    %eax,-0xb(%rbp)
mov    0xe62(%rip),%ax
mov    %ax,-0x7(%rbp)
mov    0xe5a(%rip),%al
mov    %al,-0x5(%rbp)
mov    0xe52(%rip),%eax
mov    %eax,-0x12(%rbp)
mov    0xe4c(%rip),%ax
mov    %ax,-0xe(%rbp)
mov    0xe44(%rip),%al
mov    %al,-0xc(%rbp)
mov    0xedd(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
call   10a0 <setlocale@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <setlocale@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rdi
lea    0xddd(%rip),%rsi
call   1070 <strcmp@plt>
mov    %eax,-0x4c(%rbp)
lea    -0x34(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0xb(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x40(%rbp)
mov    (%rax),%esi
lea    -0x34(%rbp),%rdx
call   1090 <wcrtomb@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rsi
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x60(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    -0xb(%rbp),%rax
sub    %rax,%rsi
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x1,-0x60(%rbp)
jne    12d2 <main+0x152>
mov    -0x48(%rbp),%rax
lea    -0xb(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
je     12fb <main+0x17b>
lea    -0xb(%rbp),%rdx
add    $0x1,%rdx
lea    -0xb(%rbp),%rax
sub    %rax,%rdx
lea    0xd7a(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4c(%rbp)
mov    0x2cd6(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1080 <putc@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x40(%rbp)
mov    (%rax),%esi
lea    -0x34(%rbp),%rdx
call   1090 <wcrtomb@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rsi
lea    0xcf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x68(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    -0xb(%rbp),%rax
sub    %rax,%rsi
lea    0xcf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x3,-0x68(%rbp)
jne    1387 <main+0x207>
mov    -0x48(%rbp),%rax
lea    -0xb(%rbp),%rcx
add    $0x4,%rcx
cmp    %rcx,%rax
je     13b0 <main+0x230>
lea    -0xb(%rbp),%rdx
add    $0x4,%rdx
lea    -0xb(%rbp),%rax
sub    %rax,%rdx
lea    0xcc5(%rip),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4c(%rbp)
mov    0x2c21(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1080 <putc@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x40(%rbp)
mov    (%rax),%esi
lea    -0x34(%rbp),%rdx
call   1090 <wcrtomb@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rsi
lea    0xc3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x70(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    -0xb(%rbp),%rax
sub    %rax,%rsi
lea    0xc3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x2,-0x70(%rbp)
jne    143c <main+0x2bc>
mov    -0x48(%rbp),%rax
lea    -0xb(%rbp),%rcx
add    $0x6,%rcx
cmp    %rcx,%rax
je     1465 <main+0x2e5>
lea    -0xb(%rbp),%rdx
add    $0x6,%rdx
lea    -0xb(%rbp),%rax
sub    %rax,%rdx
lea    0xc10(%rip),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4c(%rbp)
mov    0x2b6c(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1080 <putc@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
lea    -0x34(%rbp),%rdx
call   1090 <wcrtomb@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rsi
lea    0xbe3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x78(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    -0xb(%rbp),%rax
sub    %rax,%rsi
lea    0xb93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x1,-0x78(%rbp)
jne    14e6 <main+0x366>
mov    -0x48(%rbp),%rax
lea    -0xb(%rbp),%rcx
add    $0x7,%rcx
cmp    %rcx,%rax
je     150f <main+0x38f>
lea    -0xb(%rbp),%rdx
add    $0x7,%rdx
lea    -0xb(%rbp),%rax
sub    %rax,%rdx
lea    0xb66(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4c(%rbp)
mov    0x2ac2(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1080 <putc@plt>
lea    -0xb(%rbp),%rdi
lea    -0x12(%rbp),%rsi
mov    $0x7,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     1551 <main+0x3d1>
lea    0xb5b(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
movl   $0xffffff,0xf(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
movl   $0xbbceac,0x1b(%rsp)
movl   $0xac82e225,0x18(%rsp)
ac
mov    0x2e35(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe51(%rip),%rbx
mov    %rbx,%rsi
call   10a0 <setlocale@plt>
mov    0x0(%rbp),%edi
xor    %esi,%esi
call   10a0 <setlocale@plt>
mov    %rax,%rbp
lea    0xe41(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
mov    %eax,%r15d
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    $0x25,%esi
mov    %rbx,%rdx
call   1090 <wcrtomb@plt>
mov    %rax,%rbp
lea    0xe09(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%rsp,%rbp,1),%rbx
add    $0xc,%rbx
lea    0xe15(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%rbp
je     126b <main+0xeb>
lea    0xe0e(%rip),%rdi
mov    $0x1,%r15d
mov    $0x1,%edx
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d66(%rip),%r12
mov    (%r12),%esi
mov    $0xa,%edi
call   1080 <putc@plt>
lea    0x14(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x20ac,%esi
call   1090 <wcrtomb@plt>
mov    %rax,%rbp
lea    0xd91(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    %rbp,%rbx
mov    %rbx,%rsi
sub    %r14,%rsi
lea    0xd9c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x3,%rbp
jne    12cd <main+0x14d>
lea    0x10(%rsp),%rax
cmp    %rax,%rbx
je     12eb <main+0x16b>
lea    0xd8e(%rip),%rdi
mov    $0x4,%edx
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r15d
mov    (%r12),%esi
mov    $0xa,%edi
call   1080 <putc@plt>
lea    0x14(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x3bb,%esi
call   1090 <wcrtomb@plt>
mov    %rax,%rbp
lea    0xd18(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    %rbp,%rbx
mov    %rbx,%rsi
sub    %r14,%rsi
lea    0xd23(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%rbp
jne    1346 <main+0x1c6>
lea    0x12(%rsp),%rax
cmp    %rax,%rbx
je     1364 <main+0x1e4>
lea    0xd15(%rip),%rdi
mov    $0x6,%edx
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r15d
mov    (%r12),%esi
mov    $0xa,%edi
call   1080 <putc@plt>
lea    0x14(%rsp),%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <wcrtomb@plt>
mov    %rax,%rbp
lea    0xcf2(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    %rbp,%rbx
mov    %rbx,%rsi
sub    %r14,%rsi
lea    0xcad(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%rbp
jne    13bc <main+0x23c>
lea    0x13(%rsp),%rax
cmp    %rax,%rbx
je     13da <main+0x25a>
lea    0xc9f(%rip),%rdi
mov    $0x1,%r15d
mov    $0x7,%edx
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%esi
mov    $0xa,%edi
call   1080 <putc@plt>
lea    0xc(%rsp),%rdi
lea    0x18(%rsp),%rsi
mov    $0x7,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
je     1413 <main+0x293>
lea    0xc98(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.buf = [7 x i8] c"\FF\FF\FF\FF\FF\FF\00"
@__const.main.bufcheck = [7 x i8] c"%\E2\82\AC\CE\BB\00"
@__const.main.srcbuf = [4 x i32] [i32 37, i32 8364, i32 955, i32 0]
@LC_CTYPE = global i32 0
@.str = [12 x i8] c"de_DE.UTF-8\00"
@.str.1 = [19 x i8] c"used locale: \22%s\22\0A\00"
@.str.2 = [37 x i8] c"wcrtomb (dst, *src++, &state) -> %Zd\00"
@.str.3 = [16 x i8] c", dst = buf+%td\00"
@.str.4 = [27 x i8] c", expected %Zd and buf+%td\00"
@stdout = global i32 0
@.str.5 = [35 x i8] c"wcrtomb (dst, *src, &state) -> %Zd\00"
@.str.6 = [14 x i8] c"wrong results\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [7 x i8]
%3 = alloca [7 x i8]
%4 = alloca [4 x i32]
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %1
%14 = bitcast [7 x i8]* %2 to i8*
%15 = bitcast [7 x i8]* %3 to i8*
%16 = bitcast [4 x i32]* %4 to i8*
store i32 0, i32* %8
%17 = load i32, i32* @LC_CTYPE
%18 = call i8* @setlocale(i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @LC_CTYPE
%20 = call i8* @setlocale(i32 %19, i8* null)
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %9
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %24, i32* %8
%25 = call i32 @memset(i32* %5, i8 signext 0, i32 4)
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
store i32* %26, i32** %6
%27 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = load i32*, i32** %6
%30 = getelementptr inbounds i32, i32* %29, i32 1
store i32* %30, i32** %6
%31 = load i32, i32* %29
%32 = call i64 @wcrtomb(i8* %28, i32 %31, i32* %5)
store i64 %32, i64* %10
%33 = load i64, i64* %10
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %33)
%35 = load i64, i64* %10
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i64 %35
store i8* %37, i8** %7
%38 = load i8*, i8** %7
%39 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %42)
%44 = load i64, i64* %10
%45 = icmp ne i64 %44, 1
br i1 %45, label %51, label %46
46: ; preds = %0
%47 = load i8*, i8** %7
%48 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = icmp ne i8* %47, %49
br i1 %50, label %51, label %59
51: ; preds = %46, %0
%52 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%55 = ptrtoint i8* %53 to i64
%56 = ptrtoint i8* %54 to i64
%57 = sub i64 %55, %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 1, i64 %57)
store i32 1, i32* %8
br label %59
59: ; preds = %51, %46
%60 = load i32, i32* @stdout
%61 = call i32 @putc(i8 signext 10, i32 %60)
%62 = load i8*, i8** %7
%63 = load i32*, i32** %6
%64 = getelementptr inbounds i32, i32* %63, i32 1
store i32* %64, i32** %6
%65 = load i32, i32* %63
%66 = call i64 @wcrtomb(i8* %62, i32 %65, i32* %5)
store i64 %66, i64* %11
%67 = load i64, i64* %11
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %67)
%69 = load i64, i64* %11
%70 = load i8*, i8** %7
%71 = getelementptr inbounds i8, i8* %70, i64 %69
store i8* %71, i8** %7
%72 = load i8*, i8** %7
%73 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%74 = ptrtoint i8* %72 to i64
%75 = ptrtoint i8* %73 to i64
%76 = sub i64 %74, %75
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %76)
%78 = load i64, i64* %11
%79 = icmp ne i64 %78, 3
br i1 %79, label %85, label %80
80: ; preds = %59
%81 = load i8*, i8** %7
%82 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%83 = getelementptr inbounds i8, i8* %82, i64 4
%84 = icmp ne i8* %81, %83
br i1 %84, label %85, label %93
85: ; preds = %80, %59
%86 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%87 = getelementptr inbounds i8, i8* %86, i64 4
%88 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%89 = ptrtoint i8* %87 to i64
%90 = ptrtoint i8* %88 to i64
%91 = sub i64 %89, %90
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 3, i64 %91)
store i32 1, i32* %8
br label %93
93: ; preds = %85, %80
%94 = load i32, i32* @stdout
%95 = call i32 @putc(i8 signext 10, i32 %94)
%96 = load i8*, i8** %7
%97 = load i32*, i32** %6
%98 = getelementptr inbounds i32, i32* %97, i32 1
store i32* %98, i32** %6
%99 = load i32, i32* %97
%100 = call i64 @wcrtomb(i8* %96, i32 %99, i32* %5)
store i64 %100, i64* %12
%101 = load i64, i64* %12
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %101)
%103 = load i64, i64* %12
%104 = load i8*, i8** %7
%105 = getelementptr inbounds i8, i8* %104, i64 %103
store i8* %105, i8** %7
%106 = load i8*, i8** %7
%107 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%108 = ptrtoint i8* %106 to i64
%109 = ptrtoint i8* %107 to i64
%110 = sub i64 %108, %109
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %110)
%112 = load i64, i64* %12
%113 = icmp ne i64 %112, 2
br i1 %113, label %119, label %114
114: ; preds = %93
%115 = load i8*, i8** %7
%116 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%117 = getelementptr inbounds i8, i8* %116, i64 6
%118 = icmp ne i8* %115, %117
br i1 %118, label %119, label %127
119: ; preds = %114, %93
%120 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%121 = getelementptr inbounds i8, i8* %120, i64 6
%122 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%123 = ptrtoint i8* %121 to i64
%124 = ptrtoint i8* %122 to i64
%125 = sub i64 %123, %124
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 2, i64 %125)
store i32 1, i32* %8
br label %127
127: ; preds = %119, %114
%128 = load i32, i32* @stdout
%129 = call i32 @putc(i8 signext 10, i32 %128)
%130 = load i8*, i8** %7
%131 = load i32*, i32** %6
%132 = load i32, i32* %131
%133 = call i64 @wcrtomb(i8* %130, i32 %132, i32* %5)
store i64 %133, i64* %13
%134 = load i64, i64* %13
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i64 %134)
%136 = load i64, i64* %13
%137 = load i8*, i8** %7
%138 = getelementptr inbounds i8, i8* %137, i64 %136
store i8* %138, i8** %7
%139 = load i8*, i8** %7
%140 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%141 = ptrtoint i8* %139 to i64
%142 = ptrtoint i8* %140 to i64
%143 = sub i64 %141, %142
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %143)
%145 = load i64, i64* %13
%146 = icmp ne i64 %145, 1
br i1 %146, label %152, label %147
147: ; preds = %127
%148 = load i8*, i8** %7
%149 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%150 = getelementptr inbounds i8, i8* %149, i64 7
%151 = icmp ne i8* %148, %150
br i1 %151, label %152, label %160
152: ; preds = %147, %127
%153 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%154 = getelementptr inbounds i8, i8* %153, i64 7
%155 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%156 = ptrtoint i8* %154 to i64
%157 = ptrtoint i8* %155 to i64
%158 = sub i64 %156, %157
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 1, i64 %158)
store i32 1, i32* %8
br label %160
160: ; preds = %152, %147
%161 = load i32, i32* @stdout
%162 = call i32 @putc(i8 signext 10, i32 %161)
%163 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%164 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%165 = call i64 @memcmp(i8* %163, i8* %164, i32 7)
%166 = icmp ne i64 %165, 0
br i1 %166, label %167, label %169
167: ; preds = %160
%168 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %8
br label %169
169: ; preds = %167, %160
%170 = load i32, i32* %8
ret i32 %170
}

LLVM IR (-O2):
@__const.main.buf = [7 x i8] c"\FF\FF\FF\FF\FF\FF\00"
@__const.main.bufcheck = [7 x i8] c"%\E2\82\AC\CE\BB\00"
@LC_CTYPE = global i32 0
@.str = [12 x i8] c"de_DE.UTF-8\00"
@.str.1 = [19 x i8] c"used locale: \22%s\22\0A\00"
@.str.2 = [37 x i8] c"wcrtomb (dst, *src++, &state) -> %Zd\00"
@.str.3 = [16 x i8] c", dst = buf+%td\00"
@.str.4 = [27 x i8] c", expected %Zd and buf+%td\00"
@stdout = global i32 0
@.str.5 = [35 x i8] c"wcrtomb (dst, *src, &state) -> %Zd\00"
@.str.6 = [14 x i8] c"wrong results\00"
define i32 @main() {
%1 = alloca [7 x i8]
%2 = alloca [7 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = load i32, i32* @LC_CTYPE
%8 = tail call i8* @setlocale(i32 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @LC_CTYPE
%10 = tail call i8* @setlocale(i32 %9, i8* null)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @memset(i32* %3, i8 signext 0, i32 4)
%14 = call i64 @wcrtomb(i8* %4, i32 37, i32* %3)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %14)
%16 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 %14
%17 = ptrtoint [7 x i8]* %1 to i64
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %14)
%19 = icmp eq i64 %14, 1
br i1 %19, label %22, label %20
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 1, i64 1)
br label %22
22: ; preds = %0, %20
%23 = phi i32 [ 1, %20 ], [ %12, %0 ]
%24 = load i32, i32* @stdout
%25 = call i32 @putc(i8 signext 10, i32 %24)
%26 = call i64 @wcrtomb(i8* %16, i32 8364, i32* %3)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %26)
%28 = getelementptr inbounds i8, i8* %16, i64 %26
%29 = ptrtoint i8* %28 to i64
%30 = sub i64 %29, %17
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %30)
%32 = icmp ne i64 %26, 3
%33 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 4
%34 = icmp ne i8* %28, %33
%35 = select i1 %32, i1 true, i1 %34
br i1 %35, label %36, label %38
36: ; preds = %22
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 3, i64 4)
br label %38
38: ; preds = %22, %36
%39 = phi i32 [ 1, %36 ], [ %23, %22 ]
%40 = load i32, i32* @stdout
%41 = call i32 @putc(i8 signext 10, i32 %40)
%42 = call i64 @wcrtomb(i8* %28, i32 955, i32* %3)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %42)
%44 = getelementptr inbounds i8, i8* %28, i64 %42
%45 = ptrtoint i8* %44 to i64
%46 = sub i64 %45, %17
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %46)
%48 = icmp ne i64 %42, 2
%49 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 6
%50 = icmp ne i8* %44, %49
%51 = select i1 %48, i1 true, i1 %50
br i1 %51, label %52, label %54
52: ; preds = %38
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 2, i64 6)
br label %54
54: ; preds = %38, %52
%55 = phi i32 [ 1, %52 ], [ %39, %38 ]
%56 = load i32, i32* @stdout
%57 = call i32 @putc(i8 signext 10, i32 %56)
%58 = call i64 @wcrtomb(i8* %44, i32 0, i32* %3)
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i64 %58)
%60 = getelementptr inbounds i8, i8* %44, i64 %58
%61 = ptrtoint i8* %60 to i64
%62 = sub i64 %61, %17
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %62)
%64 = icmp ne i64 %58, 1
%65 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 7
%66 = icmp ne i8* %60, %65
%67 = select i1 %64, i1 true, i1 %66
br i1 %67, label %68, label %70
68: ; preds = %54
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 1, i64 7)
br label %70
70: ; preds = %54, %68
%71 = phi i32 [ 1, %68 ], [ %55, %54 ]
%72 = load i32, i32* @stdout
%73 = call i32 @putc(i8 signext 10, i32 %72)
%74 = call i64 @memcmp(i8* %4, i8* %5, i32 7)
%75 = icmp eq i64 %74, 0
br i1 %75, label %78, label %76
76: ; preds = %70
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %78
78: ; preds = %76, %70
%79 = phi i32 [ 1, %76 ], [ %71, %70 ]
ret i32 %79
}