#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 wcsrtombs(char *, int const **, int, int /*<<< orphan*/ *);
int main(void) {
  unsigned char buf[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  const unsigned char bufcheck[6] = {0x25, 0xe2, 0x82, 0xac, 0xce, 0xbb};
  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 = wcsrtombs(dst, &src, 1, &state);
    printf("wcsrtombs (dst, &src, 1, &state)"
           " -> %Zd",
           res);
    dst += res;
    printf(", src = srcbuf+%td, dst = buf+%td", src - srcbuf,
           dst - (char *)buf);
    if (res != 1 || src != (srcbuf + 1) || dst != (char *)(buf + 1)) {
      printf(", expected %Zd and srcbuf+%td and buf+%td", 1,
             (srcbuf + 1) - srcbuf, (buf + 1) - (unsigned char *)buf);
      result = 1;
    }
    putc('\n', stdout);
  };
  {
    size_t res = wcsrtombs(dst, &src, 1, &state);
    printf("wcsrtombs (dst, &src, 1, &state)"
           " -> %Zd",
           res);
    dst += res;
    printf(", src = srcbuf+%td, dst = buf+%td", src - srcbuf,
           dst - (char *)buf);
    if (res != 0 || src != (srcbuf + 1) || dst != (char *)(buf + 1)) {
      printf(", expected %Zd and srcbuf+%td and buf+%td", 0,
             (srcbuf + 1) - srcbuf, (buf + 1) - (unsigned char *)buf);
      result = 1;
    }
    putc('\n', stdout);
  };
  {
    size_t res = wcsrtombs(dst, &src, 4, &state);
    printf("wcsrtombs (dst, &src, 4, &state)"
           " -> %Zd",
           res);
    dst += res;
    printf(", src = srcbuf+%td, dst = buf+%td", src - srcbuf,
           dst - (char *)buf);
    if (res != 3 || src != (srcbuf + 2) || dst != (char *)(buf + 4)) {
      printf(", expected %Zd and srcbuf+%td and buf+%td", 3,
             (srcbuf + 2) - srcbuf, (buf + 4) - (unsigned char *)buf);
      result = 1;
    }
    putc('\n', stdout);
  };
  {
    size_t res = wcsrtombs(dst, &src, 2, &state);
    printf("wcsrtombs (dst, &src, 2, &state)"
           " -> %Zd",
           res);
    dst += res;
    printf(", src = srcbuf+%td, dst = buf+%td", src - srcbuf,
           dst - (char *)buf);
    if (res != 2 || src != (srcbuf + 3) || dst != (char *)(buf + 6)) {
      printf(", expected %Zd and srcbuf+%td and buf+%td", 2,
             (srcbuf + 3) - srcbuf, (buf + 6) - (unsigned char *)buf);
      result = 1;
    }
    putc('\n', stdout);
  };
  if (memcmp(buf, bufcheck, 6)) {
    puts("wrong results");
    result = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe6b(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xe65(%rip),%ax
mov    %ax,-0x6(%rbp)
mov    0xe5d(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xe57(%rip),%ax
mov    %ax,-0xc(%rbp)
mov    0xe52(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe4f(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   10a0 <setlocale@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <setlocale@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1080 <strcmp@plt>
mov    %eax,-0x3c(%rbp)
lea    -0x24(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0xa(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x1,%edx
lea    -0x24(%rbp),%rcx
call   1040 <wcsrtombs@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rsi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x50(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rax
sub    %rax,%rsi
sar    $0x2,%rsi
mov    -0x38(%rbp),%rdx
lea    -0xa(%rbp),%rax
sub    %rax,%rdx
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x1,-0x50(%rbp)
jne    12d9 <main+0x159>
mov    -0x30(%rbp),%rax
lea    -0x20(%rbp),%rcx
add    $0x4,%rcx
cmp    %rcx,%rax
jne    12d9 <main+0x159>
mov    -0x38(%rbp),%rax
lea    -0xa(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
je     1315 <main+0x195>
lea    -0x20(%rbp),%rdx
add    $0x4,%rdx
lea    -0x20(%rbp),%rax
sub    %rax,%rdx
sar    $0x2,%rdx
lea    -0xa(%rbp),%rcx
add    $0x1,%rcx
lea    -0xa(%rbp),%rax
sub    %rax,%rcx
lea    0xd87(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x3c(%rbp)
mov    0x2cbc(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1090 <putc@plt>
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x1,%edx
lea    -0x24(%rbp),%rcx
call   1040 <wcsrtombs@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rsi
lea    0xcf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rax
sub    %rax,%rsi
sar    $0x2,%rsi
mov    -0x38(%rbp),%rdx
lea    -0xa(%rbp),%rax
sub    %rax,%rdx
lea    0xce6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x58(%rbp)
jne    13bd <main+0x23d>
mov    -0x30(%rbp),%rax
lea    -0x20(%rbp),%rcx
add    $0x4,%rcx
cmp    %rcx,%rax
jne    13bd <main+0x23d>
mov    -0x38(%rbp),%rax
lea    -0xa(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
je     13f6 <main+0x276>
lea    -0x20(%rbp),%rdx
add    $0x4,%rdx
lea    -0x20(%rbp),%rax
sub    %rax,%rdx
sar    $0x2,%rdx
lea    -0xa(%rbp),%rcx
add    $0x1,%rcx
lea    -0xa(%rbp),%rax
sub    %rax,%rcx
lea    0xca3(%rip),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x3c(%rbp)
mov    0x2bdb(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1090 <putc@plt>
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
lea    -0x24(%rbp),%rcx
call   1040 <wcsrtombs@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rsi
lea    0xc85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x60(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rax
sub    %rax,%rsi
sar    $0x2,%rsi
mov    -0x38(%rbp),%rdx
lea    -0xa(%rbp),%rax
sub    %rax,%rdx
lea    0xc05(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x3,-0x60(%rbp)
jne    149e <main+0x31e>
mov    -0x30(%rbp),%rax
lea    -0x20(%rbp),%rcx
add    $0x8,%rcx
cmp    %rcx,%rax
jne    149e <main+0x31e>
mov    -0x38(%rbp),%rax
lea    -0xa(%rbp),%rcx
add    $0x4,%rcx
cmp    %rcx,%rax
je     14da <main+0x35a>
lea    -0x20(%rbp),%rdx
add    $0x8,%rdx
lea    -0x20(%rbp),%rax
sub    %rax,%rdx
sar    $0x2,%rdx
lea    -0xa(%rbp),%rcx
add    $0x4,%rcx
lea    -0xa(%rbp),%rax
sub    %rax,%rcx
lea    0xbc2(%rip),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x3c(%rbp)
mov    0x2af7(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1090 <putc@plt>
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x2,%edx
lea    -0x24(%rbp),%rcx
call   1040 <wcsrtombs@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rsi
lea    0xbc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x68(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rax
sub    %rax,%rsi
sar    $0x2,%rsi
mov    -0x38(%rbp),%rdx
lea    -0xa(%rbp),%rax
sub    %rax,%rdx
lea    0xb21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x2,-0x68(%rbp)
jne    1582 <main+0x402>
mov    -0x30(%rbp),%rax
lea    -0x20(%rbp),%rcx
add    $0xc,%rcx
cmp    %rcx,%rax
jne    1582 <main+0x402>
mov    -0x38(%rbp),%rax
lea    -0xa(%rbp),%rcx
add    $0x6,%rcx
cmp    %rcx,%rax
je     15be <main+0x43e>
lea    -0x20(%rbp),%rdx
add    $0xc,%rdx
lea    -0x20(%rbp),%rax
sub    %rax,%rdx
sar    $0x2,%rdx
lea    -0xa(%rbp),%rcx
add    $0x6,%rcx
lea    -0xa(%rbp),%rax
sub    %rax,%rcx
lea    0xade(%rip),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x3c(%rbp)
mov    0x2a13(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1090 <putc@plt>
lea    -0xa(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x6,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     1600 <main+0x480>
lea    0xb0f(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movw   $0xffff,0x4(%rsp)
movl   $0xffffffff,(%rsp)
movw   $0xbbce,0x1c(%rsp)
movl   $0xac82e225,0x18(%rsp)
ac
movaps 0xe5e(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0x2e2a(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe58(%rip),%rbx
mov    %rbx,%rsi
call   10a0 <setlocale@plt>
mov    0x0(%rbp),%edi
xor    %esi,%esi
call   10a0 <setlocale@plt>
mov    %rax,%rbp
lea    0xe48(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
mov    %eax,%r15d
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    0x20(%rsp),%r12
mov    %r12,0x8(%rsp)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <wcsrtombs@plt>
mov    %rax,%rbp
lea    0xe06(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    (%rsp,%rbp,1),%rbx
mov    0x8(%rsp),%rsi
sub    %r12,%rsi
sar    $0x2,%rsi
lea    0xe0d(%rip),%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x24(%rsp),%r14
cmp    $0x1,%rbp
jne    1276 <main+0xf6>
cmp    %r14,0x8(%rsp)
je     1299 <main+0x119>
lea    0xe0c(%rip),%rdi
mov    $0x1,%edx
mov    $0x1,%ecx
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r15d
mov    0x2d38(%rip),%r13
mov    0x0(%r13),%esi
mov    $0xa,%edi
call   1090 <putc@plt>
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1040 <wcsrtombs@plt>
mov    %rax,%rbp
lea    0xd70(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    %rbp,%rbx
mov    0x8(%rsp),%rsi
sub    %r12,%rsi
sar    $0x2,%rsi
mov    %rbx,%rdx
mov    %rsp,%rax
sub    %rax,%rdx
lea    0xd6f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %rbp,%rbp
jne    1315 <main+0x195>
cmp    %r14,0x8(%rsp)
jne    1315 <main+0x195>
lea    0x1(%rsp),%rax
cmp    %rax,%rbx
je     1335 <main+0x1b5>
lea    0xd6d(%rip),%rdi
mov    $0x1,%edx
mov    $0x1,%ecx
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r15d
mov    0x0(%r13),%esi
mov    $0xa,%edi
call   1090 <putc@plt>
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <wcsrtombs@plt>
mov    %rax,%rbp
lea    0xd4f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    %rbp,%rbx
mov    0x8(%rsp),%rsi
sub    %r12,%rsi
sar    $0x2,%rsi
mov    %rbx,%rdx
mov    %rsp,%rax
sub    %rax,%rdx
lea    0xcda(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x3,%rbp
jne    13b0 <main+0x230>
lea    0x28(%rsp),%rax
cmp    %rax,0x8(%rsp)
jne    13b0 <main+0x230>
lea    0x4(%rsp),%rax
cmp    %rax,%rbx
je     13d3 <main+0x253>
lea    0xcd2(%rip),%rdi
mov    $0x2,%edx
mov    $0x4,%ecx
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r15d
mov    0x0(%r13),%esi
mov    $0xa,%edi
call   1090 <putc@plt>
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x2,%edx
call   1040 <wcsrtombs@plt>
mov    %rax,%rbp
lea    0xcd9(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    %rbp,%rbx
mov    0x8(%rsp),%rsi
sub    %r12,%rsi
sar    $0x2,%rsi
mov    %rbx,%rdx
mov    %rsp,%rax
sub    %rax,%rdx
lea    0xc3c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%rbp
jne    144e <main+0x2ce>
lea    0x2c(%rsp),%rax
cmp    %rax,0x8(%rsp)
jne    144e <main+0x2ce>
lea    0x6(%rsp),%rax
cmp    %rax,%rbx
je     1471 <main+0x2f1>
lea    0xc34(%rip),%rdi
mov    $0x3,%edx
mov    $0x6,%ecx
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r15d
mov    0x0(%r13),%esi
mov    $0xa,%edi
call   1090 <putc@plt>
mov    %rsp,%rdi
lea    0x18(%rsp),%rsi
mov    $0x6,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
je     14a8 <main+0x328>
lea    0xc66(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.buf = [6 x i8] c"\FF\FF\FF\FF\FF\FF"
@__const.main.bufcheck = [6 x i8] c"%\E2\82\AC\CE\BB"
@__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 = [40 x i8] c"wcsrtombs (dst, &src, 1, &state) -> %Zd\00"
@.str.3 = [34 x i8] c", src = srcbuf+%td, dst = buf+%td\00"
@.str.4 = [42 x i8] c", expected %Zd and srcbuf+%td and buf+%td\00"
@stdout = global i32 0
@.str.5 = [40 x i8] c"wcsrtombs (dst, &src, 4, &state) -> %Zd\00"
@.str.6 = [40 x i8] c"wcsrtombs (dst, &src, 2, &state) -> %Zd\00"
@.str.7 = [14 x i8] c"wrong results\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [6 x i8]
%3 = alloca [6 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 [6 x i8]* %2 to i8*
%15 = bitcast [6 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 [6 x i8], [6 x i8]* %2, i64 0, i64 0
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = call i64 @wcsrtombs(i8* %28, i32** %6, i32 1, i32* %5)
store i64 %29, i64* %10
%30 = load i64, i64* %10
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i64 %30)
%32 = load i64, i64* %10
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i64 %32
store i8* %34, i8** %7
%35 = load i32*, i32** %6
%36 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%37 = ptrtoint i32* %35 to i64
%38 = ptrtoint i32* %36 to i64
%39 = sub i64 %37, %38
%40 = sdiv exact i64 %39, 4
%41 = load i8*, i8** %7
%42 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%43 = ptrtoint i8* %41 to i64
%44 = ptrtoint i8* %42 to i64
%45 = sub i64 %43, %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %40, i64 %45)
%47 = load i64, i64* %10
%48 = icmp ne i64 %47, 1
br i1 %48, label %59, label %49
49: ; preds = %0
%50 = load i32*, i32** %6
%51 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%52 = getelementptr inbounds i32, i32* %51, i64 1
%53 = icmp ne i32* %50, %52
br i1 %53, label %59, label %54
54: ; preds = %49
%55 = load i8*, i8** %7
%56 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = icmp ne i8* %55, %57
br i1 %58, label %59, label %74
59: ; preds = %54, %49, %0
%60 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%61 = getelementptr inbounds i32, i32* %60, i64 1
%62 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%63 = ptrtoint i32* %61 to i64
%64 = ptrtoint i32* %62 to i64
%65 = sub i64 %63, %64
%66 = sdiv exact i64 %65, 4
%67 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%68 = getelementptr inbounds i8, i8* %67, i64 1
%69 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%70 = ptrtoint i8* %68 to i64
%71 = ptrtoint i8* %69 to i64
%72 = sub i64 %70, %71
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 1, i64 %66, i64 %72)
store i32 1, i32* %8
br label %74
74: ; preds = %59, %54
%75 = load i32, i32* @stdout
%76 = call i32 @putc(i8 signext 10, i32 %75)
%77 = load i8*, i8** %7
%78 = call i64 @wcsrtombs(i8* %77, i32** %6, i32 1, i32* %5)
store i64 %78, i64* %11
%79 = load i64, i64* %11
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i64 %79)
%81 = load i64, i64* %11
%82 = load i8*, i8** %7
%83 = getelementptr inbounds i8, i8* %82, i64 %81
store i8* %83, i8** %7
%84 = load i32*, i32** %6
%85 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%86 = ptrtoint i32* %84 to i64
%87 = ptrtoint i32* %85 to i64
%88 = sub i64 %86, %87
%89 = sdiv exact i64 %88, 4
%90 = load i8*, i8** %7
%91 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%92 = ptrtoint i8* %90 to i64
%93 = ptrtoint i8* %91 to i64
%94 = sub i64 %92, %93
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %89, i64 %94)
%96 = load i64, i64* %11
%97 = icmp ne i64 %96, 0
br i1 %97, label %108, label %98
98: ; preds = %74
%99 = load i32*, i32** %6
%100 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%101 = getelementptr inbounds i32, i32* %100, i64 1
%102 = icmp ne i32* %99, %101
br i1 %102, label %108, label %103
103: ; preds = %98
%104 = load i8*, i8** %7
%105 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%106 = getelementptr inbounds i8, i8* %105, i64 1
%107 = icmp ne i8* %104, %106
br i1 %107, label %108, label %123
108: ; preds = %103, %98, %74
%109 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%110 = getelementptr inbounds i32, i32* %109, i64 1
%111 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%112 = ptrtoint i32* %110 to i64
%113 = ptrtoint i32* %111 to i64
%114 = sub i64 %112, %113
%115 = sdiv exact i64 %114, 4
%116 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%117 = getelementptr inbounds i8, i8* %116, i64 1
%118 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%119 = ptrtoint i8* %117 to i64
%120 = ptrtoint i8* %118 to i64
%121 = sub i64 %119, %120
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 0, i64 %115, i64 %121)
store i32 1, i32* %8
br label %123
123: ; preds = %108, %103
%124 = load i32, i32* @stdout
%125 = call i32 @putc(i8 signext 10, i32 %124)
%126 = load i8*, i8** %7
%127 = call i64 @wcsrtombs(i8* %126, i32** %6, i32 4, i32* %5)
store i64 %127, i64* %12
%128 = load i64, i64* %12
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i64 %128)
%130 = load i64, i64* %12
%131 = load i8*, i8** %7
%132 = getelementptr inbounds i8, i8* %131, i64 %130
store i8* %132, i8** %7
%133 = load i32*, i32** %6
%134 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%135 = ptrtoint i32* %133 to i64
%136 = ptrtoint i32* %134 to i64
%137 = sub i64 %135, %136
%138 = sdiv exact i64 %137, 4
%139 = load i8*, i8** %7
%140 = getelementptr inbounds [6 x i8], [6 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 ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %138, i64 %143)
%145 = load i64, i64* %12
%146 = icmp ne i64 %145, 3
br i1 %146, label %157, label %147
147: ; preds = %123
%148 = load i32*, i32** %6
%149 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%150 = getelementptr inbounds i32, i32* %149, i64 2
%151 = icmp ne i32* %148, %150
br i1 %151, label %157, label %152
152: ; preds = %147
%153 = load i8*, i8** %7
%154 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%155 = getelementptr inbounds i8, i8* %154, i64 4
%156 = icmp ne i8* %153, %155
br i1 %156, label %157, label %172
157: ; preds = %152, %147, %123
%158 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%159 = getelementptr inbounds i32, i32* %158, i64 2
%160 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%161 = ptrtoint i32* %159 to i64
%162 = ptrtoint i32* %160 to i64
%163 = sub i64 %161, %162
%164 = sdiv exact i64 %163, 4
%165 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%166 = getelementptr inbounds i8, i8* %165, i64 4
%167 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%168 = ptrtoint i8* %166 to i64
%169 = ptrtoint i8* %167 to i64
%170 = sub i64 %168, %169
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 3, i64 %164, i64 %170)
store i32 1, i32* %8
br label %172
172: ; preds = %157, %152
%173 = load i32, i32* @stdout
%174 = call i32 @putc(i8 signext 10, i32 %173)
%175 = load i8*, i8** %7
%176 = call i64 @wcsrtombs(i8* %175, i32** %6, i32 2, i32* %5)
store i64 %176, i64* %13
%177 = load i64, i64* %13
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i64 %177)
%179 = load i64, i64* %13
%180 = load i8*, i8** %7
%181 = getelementptr inbounds i8, i8* %180, i64 %179
store i8* %181, i8** %7
%182 = load i32*, i32** %6
%183 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%184 = ptrtoint i32* %182 to i64
%185 = ptrtoint i32* %183 to i64
%186 = sub i64 %184, %185
%187 = sdiv exact i64 %186, 4
%188 = load i8*, i8** %7
%189 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%190 = ptrtoint i8* %188 to i64
%191 = ptrtoint i8* %189 to i64
%192 = sub i64 %190, %191
%193 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %187, i64 %192)
%194 = load i64, i64* %13
%195 = icmp ne i64 %194, 2
br i1 %195, label %206, label %196
196: ; preds = %172
%197 = load i32*, i32** %6
%198 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%199 = getelementptr inbounds i32, i32* %198, i64 3
%200 = icmp ne i32* %197, %199
br i1 %200, label %206, label %201
201: ; preds = %196
%202 = load i8*, i8** %7
%203 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%204 = getelementptr inbounds i8, i8* %203, i64 6
%205 = icmp ne i8* %202, %204
br i1 %205, label %206, label %221
206: ; preds = %201, %196, %172
%207 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%208 = getelementptr inbounds i32, i32* %207, i64 3
%209 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%210 = ptrtoint i32* %208 to i64
%211 = ptrtoint i32* %209 to i64
%212 = sub i64 %210, %211
%213 = sdiv exact i64 %212, 4
%214 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%215 = getelementptr inbounds i8, i8* %214, i64 6
%216 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%217 = ptrtoint i8* %215 to i64
%218 = ptrtoint i8* %216 to i64
%219 = sub i64 %217, %218
%220 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 2, i64 %213, i64 %219)
store i32 1, i32* %8
br label %221
221: ; preds = %206, %201
%222 = load i32, i32* @stdout
%223 = call i32 @putc(i8 signext 10, i32 %222)
%224 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%225 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%226 = call i64 @memcmp(i8* %224, i8* %225, i32 6)
%227 = icmp ne i64 %226, 0
br i1 %227, label %228, label %230
228: ; preds = %221
%229 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %8
br label %230
230: ; preds = %228, %221
%231 = load i32, i32* %8
ret i32 %231
}

LLVM IR (-O2):
@__const.main.bufcheck = [6 x i8] c"%\E2\82\AC\CE\BB"
@__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 = [40 x i8] c"wcsrtombs (dst, &src, 1, &state) -> %Zd\00"
@.str.3 = [34 x i8] c", src = srcbuf+%td, dst = buf+%td\00"
@.str.4 = [42 x i8] c", expected %Zd and srcbuf+%td and buf+%td\00"
@stdout = global i32 0
@.str.5 = [40 x i8] c"wcsrtombs (dst, &src, 4, &state) -> %Zd\00"
@.str.6 = [40 x i8] c"wcsrtombs (dst, &src, 2, &state) -> %Zd\00"
@.str.7 = [14 x i8] c"wrong results\00"
define i32 @main() {
%1 = alloca [6 x i8]
%2 = alloca [6 x i8]
%3 = alloca [4 x i32]
%4 = alloca i32
%5 = alloca i32*
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%8 = bitcast [4 x i32]* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32** %5 to i8*
%11 = load i32, i32* @LC_CTYPE
%12 = tail call i8* @setlocale(i32 %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @LC_CTYPE
%14 = tail call i8* @setlocale(i32 %13, i8* null)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @memset(i32* %4, i8 signext 0, i32 4)
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
store i32* %18, i32** %5
%19 = call i64 @wcsrtombs(i8* %6, i32** %5, i32 1, i32* %4)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i64 %19)
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 %19
%22 = load i32*, i32** %5
%23 = ptrtoint i32* %22 to i64
%24 = ptrtoint [4 x i32]* %3 to i64
%25 = sub i64 %23, %24
%26 = ashr exact i64 %25, 2
%27 = ptrtoint [6 x i8]* %1 to i64
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %26, i64 %19)
%29 = load i32*, i32** %5
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%31 = icmp ne i32* %29, %30
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 1
%33 = icmp ne i64 %19, 1
%34 = select i1 %33, i1 true, i1 %31
br i1 %34, label %35, label %37
35: ; preds = %0
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 1, i64 1, i64 1)
br label %37
37: ; preds = %0, %35
%38 = phi i32 [ 1, %35 ], [ %16, %0 ]
%39 = load i32, i32* @stdout
%40 = call i32 @putc(i8 signext 10, i32 %39)
%41 = call i64 @wcsrtombs(i8* %21, i32** %5, i32 1, i32* %4)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i64 %41)
%43 = getelementptr inbounds i8, i8* %21, i64 %41
%44 = load i32*, i32** %5
%45 = ptrtoint i32* %44 to i64
%46 = sub i64 %45, %24
%47 = ashr exact i64 %46, 2
%48 = ptrtoint i8* %43 to i64
%49 = sub i64 %48, %27
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %47, i64 %49)
%51 = icmp ne i64 %41, 0
%52 = load i32*, i32** %5
%53 = icmp ne i32* %52, %30
%54 = select i1 %51, i1 true, i1 %53
%55 = icmp ne i8* %43, %32
%56 = select i1 %54, i1 true, i1 %55
br i1 %56, label %57, label %59
57: ; preds = %37
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 0, i64 1, i64 1)
br label %59
59: ; preds = %37, %57
%60 = phi i32 [ 1, %57 ], [ %38, %37 ]
%61 = load i32, i32* @stdout
%62 = call i32 @putc(i8 signext 10, i32 %61)
%63 = call i64 @wcsrtombs(i8* %43, i32** %5, i32 4, i32* %4)
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i64 %63)
%65 = getelementptr inbounds i8, i8* %43, i64 %63
%66 = load i32*, i32** %5
%67 = ptrtoint i32* %66 to i64
%68 = sub i64 %67, %24
%69 = ashr exact i64 %68, 2
%70 = ptrtoint i8* %65 to i64
%71 = sub i64 %70, %27
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %69, i64 %71)
%73 = icmp ne i64 %63, 3
%74 = load i32*, i32** %5
%75 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%76 = icmp ne i32* %74, %75
%77 = select i1 %73, i1 true, i1 %76
%78 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 4
%79 = icmp ne i8* %65, %78
%80 = select i1 %77, i1 true, i1 %79
br i1 %80, label %81, label %83
81: ; preds = %59
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 3, i64 2, i64 4)
br label %83
83: ; preds = %59, %81
%84 = phi i32 [ 1, %81 ], [ %60, %59 ]
%85 = load i32, i32* @stdout
%86 = call i32 @putc(i8 signext 10, i32 %85)
%87 = call i64 @wcsrtombs(i8* %65, i32** %5, i32 2, i32* %4)
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i64 %87)
%89 = getelementptr inbounds i8, i8* %65, i64 %87
%90 = load i32*, i32** %5
%91 = ptrtoint i32* %90 to i64
%92 = sub i64 %91, %24
%93 = ashr exact i64 %92, 2
%94 = ptrtoint i8* %89 to i64
%95 = sub i64 %94, %27
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %93, i64 %95)
%97 = icmp ne i64 %87, 2
%98 = load i32*, i32** %5
%99 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%100 = icmp ne i32* %98, %99
%101 = select i1 %97, i1 true, i1 %100
%102 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 6
%103 = icmp ne i8* %89, %102
%104 = select i1 %101, i1 true, i1 %103
br i1 %104, label %105, label %107
105: ; preds = %83
%106 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 2, i64 3, i64 6)
br label %107
107: ; preds = %83, %105
%108 = phi i32 [ 1, %105 ], [ %84, %83 ]
%109 = load i32, i32* @stdout
%110 = call i32 @putc(i8 signext 10, i32 %109)
%111 = call i64 @memcmp(i8* %6, i8* %7, i32 6)
%112 = icmp eq i64 %111, 0
br i1 %112, label %115, label %113
113: ; preds = %107
%114 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %115
115: ; preds = %113, %107
%116 = phi i32 [ 1, %113 ], [ %108, %107 ]
ret i32 %116
}