#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*/ il_str2;
typedef int /*<<< orphan*/ il_str1;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EILSEQ;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ LC_ALL;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int *fgetws(int *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fwrite(char const *, int, int, int /*<<< orphan*/ *);
int mkstemp(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ *setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unlink(char *);
int wcslen(int *);
int main(int argc, char *argv[]) {
  size_t i;
  FILE *fp;
  wchar_t *ret, wcs[32];
  int result = 0;
  const char il_str1[] = {0xe3, 0x81, '\0'};
  const char il_str2[] = {'0', '\n', 'A', 'B', 0xe3, 0x81, 'E', '\0'};
  char name1[] = "/tmp/tst-fgetws.out.XXXXXX";
  char name2[] = "/tmp/tst-fgetws.out.XXXXXX";
  int fd;
  puts("This program runs on de_DE.UTF-8 locale.");
  if (setlocale(LC_ALL, "de_DE.UTF-8") == NULL) {
    fprintf(stderr, "Err: Cannot run on the de_DE.UTF-8 locale");
    exit(EXIT_FAILURE);
  }
  fd = mkstemp(name1);
  if (fd == -1) {
    printf("cannot open temp file: %m\n");
    exit(EXIT_FAILURE);
  }
  if ((fp = fdopen(fd, "w")) == NULL) {
    printf("Can't open %s.\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  fwrite(il_str1, sizeof(char), sizeof(il_str1), fp);
  fclose(fp);
  fd = mkstemp(name2);
  if (fd == -1) {
    printf("cannot open temp file: %m\n");
    exit(EXIT_FAILURE);
  }
  if ((fp = fdopen(fd, "w")) == NULL) {
    fprintf(stderr, "Can't open %s.\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  fwrite(il_str2, sizeof(char), sizeof(il_str2), fp);
  fclose(fp);
  if ((fp = fopen(name1, "r")) == NULL) {
    fprintf(stderr, "Can't open %s.\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  puts("--");
  puts("Read a byte sequence which is invalid as a wide character string.");
  puts(" bytes: 0xe3, 0x81, '\\0'");
  errno = 0;
  ret = fgetws(wcs, 32, fp);
  if (ret == NULL) {
    puts("Return Value: NULL");
    if (errno == EILSEQ)
      puts("errno = EILSEQ");
    else {
      printf("errno = %d\n", errno);
      result = 1;
    }
  } else {
    printf("Return Value: %p\n", ret);
    for (i = 0; i < wcslen(wcs) + 1; i++)
      printf(" wcs[%zd] = %04x", i, (unsigned int)wcs[i]);
    printf("\n");
    result = 1;
  }
  if ((fp = fopen(name2, "r")) == NULL) {
    fprintf(stderr, "Can't open %s.\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  puts("--");
  puts("Read a byte sequence which is invalid as a wide character string.");
  puts(" bytes: '0', '\\n', 'A', 'B', 0xe3, 0x81, 'c', '\\0'");
  errno = 0;
  ret = fgetws(wcs, 32, fp);
  if (ret == NULL) {
    puts("Return Value: NULL");
    if (errno == EILSEQ)
      puts("errno = EILSEQ");
    else
      printf("errno = %d\n", errno);
    result = 1;
  } else {
    size_t i;
    printf("Return Value: %p\n", ret);
    for (i = 0; i < wcslen(wcs) + 1; i++)
      printf(" wcs[%zd] = 0x%04x", i, (unsigned int)wcs[i]);
    printf("\n");
    for (i = 0; il_str2[i] != '\n'; ++i)
      if ((wchar_t)il_str2[i] != wcs[i]) {
        puts("read string not correct");
        result = 1;
        break;
      }
    if (il_str2[i] == '\n') {
      if (wcs[i] != L'\n') {
        puts("newline missing");
        result = 1;
      } else if (wcs[i + 1] != L'\0') {
        puts("read string not NUL-terminated");
        result = 1;
      }
    }
  }
  puts("\nsecond line");
  errno = 0;
  ret = fgetws(wcs, 32, fp);
  if (ret == NULL) {
    puts("Return Value: NULL");
    if (errno == EILSEQ)
      puts("errno = EILSEQ");
    else {
      printf("errno = %d\n", errno);
      result = 1;
    }
  } else {
    printf("Return Value: %p\n", ret);
    for (i = 0; i < wcslen(wcs) + 1; i++)
      printf(" wcs[%zd] = 0x%04x", i, (unsigned int)wcs[i]);
    printf("\n");
  }
  fclose(fp);
  unlink(name1);
  unlink(name2);
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xb4(%rbp)
mov    0xe06(%rip),%ax
mov    %ax,-0xb7(%rbp)
mov    0xdfb(%rip),%al
mov    %al,-0xb5(%rbp)
mov    0xdef(%rip),%rax
mov    %rax,-0xbf(%rbp)
mov    0xfce(%rip),%rax
mov    %rax,-0xe0(%rbp)
mov    0xfc8(%rip),%rax
mov    %rax,-0xd8(%rbp)
mov    0xfc2(%rip),%rax
mov    %rax,-0xd0(%rbp)
mov    0xfbc(%rip),%ax
mov    %ax,-0xc8(%rbp)
mov    0xfb1(%rip),%al
mov    %al,-0xc6(%rbp)
mov    0xf8a(%rip),%rax
mov    %rax,-0x100(%rbp)
mov    0xf84(%rip),%rax
mov    %rax,-0xf8(%rbp)
mov    0xf7e(%rip),%rax
mov    %rax,-0xf0(%rbp)
mov    0xf78(%rip),%ax
mov    %ax,-0xe8(%rbp)
mov    0xf6d(%rip),%al
mov    %al,-0xe6(%rbp)
lea    0xd61(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd75(%rip),%rsi
call   10c0 <setlocale@plt>
cmp    $0x0,%rax
jne    12f3 <main+0x123>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0xe0(%rbp),%rdi
call   10a0 <mkstemp@plt>
mov    %eax,-0x104(%rbp)
cmpl   $0xffffffff,-0x104(%rbp)
jne    132e <main+0x15e>
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x104(%rbp),%edi
lea    0xd4a(%rip),%rsi
call   10b0 <fdopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1372 <main+0x1a2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0xb7(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   10f0 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0x100(%rbp),%rdi
call   10a0 <mkstemp@plt>
mov    %eax,-0x104(%rbp)
cmpl   $0xffffffff,-0x104(%rbp)
jne    13d0 <main+0x200>
lea    0xcaf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2bff(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x104(%rbp),%edi
lea    0xca8(%rip),%rsi
call   10b0 <fdopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    141d <main+0x24d>
mov    0x2be1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc7f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2bb2(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0xbf(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   10f0 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0xe0(%rbp),%rdi
lea    0xc49(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    148e <main+0x2be>
mov    0x2b70(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc0e(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2b41(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xc04(%rip),%rdi
call   1050 <puts@plt>
lea    0xbfb(%rip),%rdi
call   1050 <puts@plt>
lea    0xc31(%rip),%rdi
call   1050 <puts@plt>
mov    0x2b17(%rip),%rax
movl   $0x0,(%rax)
lea    -0xb0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x20,%esi
call   1040 <fgetws@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    153e <main+0x36e>
lea    0xc0d(%rip),%rdi
call   1050 <puts@plt>
mov    0x2ada(%rip),%rax
mov    (%rax),%eax
mov    0x2af1(%rip),%rcx
cmp    (%rcx),%eax
jne    1518 <main+0x348>
lea    0xbfc(%rip),%rdi
call   1050 <puts@plt>
jmp    1539 <main+0x369>
mov    0x2ab1(%rip),%rax
mov    (%rax),%esi
lea    0xbf1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0xb4(%rbp)
jmp    15cd <main+0x3fd>
mov    -0x28(%rbp),%rsi
lea    0xbdc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x118(%rbp)
lea    -0xb0(%rbp),%rdi
call   1080 <wcslen@plt>
mov    %eax,%ecx
mov    -0x118(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    15b5 <main+0x3e5>
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%edx
lea    0xb9a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1558 <main+0x388>
lea    0xad9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0xb4(%rbp)
lea    -0x100(%rbp),%rdi
lea    0xabc(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    161b <main+0x44b>
mov    0x29e3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xa81(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x29b4(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xa77(%rip),%rdi
call   1050 <puts@plt>
lea    0xa6e(%rip),%rdi
call   1050 <puts@plt>
lea    0xb0e(%rip),%rdi
call   1050 <puts@plt>
mov    0x298a(%rip),%rax
movl   $0x0,(%rax)
lea    -0xb0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x20,%esi
call   1040 <fgetws@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    16cb <main+0x4fb>
lea    0xa80(%rip),%rdi
call   1050 <puts@plt>
mov    0x294d(%rip),%rax
mov    (%rax),%eax
mov    0x2964(%rip),%rcx
cmp    (%rcx),%eax
jne    16a5 <main+0x4d5>
lea    0xa6f(%rip),%rdi
call   1050 <puts@plt>
jmp    16bc <main+0x4ec>
mov    0x2924(%rip),%rax
mov    (%rax),%esi
lea    0xa64(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0xb4(%rbp)
jmp    1861 <main+0x691>
mov    -0x28(%rbp),%rsi
lea    0xa4f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movq   $0x0,-0x110(%rbp)
mov    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0xb0(%rbp),%rdi
call   1080 <wcslen@plt>
mov    %eax,%ecx
mov    -0x120(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    1754 <main+0x584>
mov    -0x110(%rbp),%rsi
mov    -0x110(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%edx
lea    0xa45(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x110(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x110(%rbp)
jmp    16e8 <main+0x518>
lea    0x93a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movq   $0x0,-0x110(%rbp)
mov    -0x110(%rbp),%rax
movsbl -0xbf(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     17df <main+0x60f>
mov    -0x110(%rbp),%rax
movsbl -0xbf(%rbp,%rax,1),%eax
ff
mov    -0x110(%rbp),%rcx
cmp    -0xb0(%rbp,%rcx,4),%eax
je     17c3 <main+0x5f3>
lea    0x9df(%rip),%rdi
call   1050 <puts@plt>
movl   $0x1,-0xb4(%rbp)
jmp    17df <main+0x60f>
jmp    17c8 <main+0x5f8>
mov    -0x110(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x110(%rbp)
jmp    176d <main+0x59d>
mov    -0x110(%rbp),%rax
movsbl -0xbf(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    185c <main+0x68c>
mov    -0x110(%rbp),%rax
cmpl   $0xa,-0xb0(%rbp,%rax,4)
0a
je     1827 <main+0x657>
lea    0x993(%rip),%rdi
call   1050 <puts@plt>
movl   $0x1,-0xb4(%rbp)
jmp    1857 <main+0x687>
mov    -0x110(%rbp),%rax
cmpl   $0x0,-0xac(%rbp,%rax,4)
je     1852 <main+0x682>
lea    0x973(%rip),%rdi
call   1050 <puts@plt>
movl   $0x1,-0xb4(%rbp)
jmp    1857 <main+0x687>
jmp    185c <main+0x68c>
jmp    1861 <main+0x691>
lea    0x96d(%rip),%rdi
call   1050 <puts@plt>
mov    0x275c(%rip),%rax
movl   $0x0,(%rax)
lea    -0xb0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x20,%esi
call   1040 <fgetws@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    18f9 <main+0x729>
lea    0x852(%rip),%rdi
call   1050 <puts@plt>
mov    0x271f(%rip),%rax
mov    (%rax),%eax
mov    0x2736(%rip),%rcx
cmp    (%rcx),%eax
jne    18d3 <main+0x703>
lea    0x841(%rip),%rdi
call   1050 <puts@plt>
jmp    18f4 <main+0x724>
mov    0x26f6(%rip),%rax
mov    (%rax),%esi
lea    0x836(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0xb4(%rbp)
jmp    197e <main+0x7ae>
mov    -0x28(%rbp),%rsi
lea    0x821(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0xb0(%rbp),%rdi
call   1080 <wcslen@plt>
mov    %eax,%ecx
mov    -0x128(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    1970 <main+0x7a0>
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%edx
lea    0x823(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1913 <main+0x743>
lea    0x71e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0xe0(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x100(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0xb4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rsi,%r14
movb   $0x0,0x6(%rsp)
movw   $0x81e3,0x4(%rsp)
movabs $0x4581e342410a30,%rax
mov    %rax,0x8(%rsp)
movups 0xfd5(%rip),%xmm0
movups %xmm0,0x3b(%rsp)
movaps 0xfbe(%rip),%xmm1
movaps %xmm1,0x30(%rsp)
movups %xmm0,0x1b(%rsp)
movaps %xmm1,0x10(%rsp)
lea    0xdcb(%rip),%rdi
call   1060 <puts@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
call   10d0 <setlocale@plt>
test   %rax,%rax
je     168e <main+0x4ae>
lea    0x30(%rsp),%rdi
call   10b0 <mkstemp@plt>
cmp    $0xffffffff,%eax
je     167e <main+0x49e>
lea    0xe08(%rip),%rsi
mov    %eax,%edi
call   10c0 <fdopen@plt>
test   %rax,%rax
je     16a7 <main+0x4c7>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %rax,%rcx
call   1100 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0x10(%rsp),%rdi
call   10b0 <mkstemp@plt>
cmp    $0xffffffff,%eax
je     167e <main+0x49e>
lea    0xdbc(%rip),%rsi
mov    %eax,%edi
call   10c0 <fdopen@plt>
test   %rax,%rax
je     1661 <main+0x481>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %rax,%rcx
call   1100 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0xd95(%rip),%rsi
lea    0x30(%rsp),%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1661 <main+0x481>
mov    %rax,%rbx
lea    0xd7a(%rip),%rdi
call   1060 <puts@plt>
lea    0xd71(%rip),%rdi
call   1060 <puts@plt>
lea    0xda7(%rip),%rdi
call   1060 <puts@plt>
mov    0x2c95(%rip),%r13
movl   $0x0,0x0(%r13)
lea    0x50(%rsp),%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
call   1050 <fgetws@plt>
test   %rax,%rax
je     13c3 <main+0x1e3>
lea    0xdbc(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x50(%rsp),%rdi
call   1090 <wcslen@plt>
cmp    $0xffffffff,%eax
je     13b7 <main+0x1d7>
lea    0xdae(%rip),%r15
lea    0x50(%rsp),%rbp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x50(%rsp,%rbx,4),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x1,%rbx
mov    %rbp,%rdi
call   1090 <wcslen@plt>
add    $0x1,%eax
cltq
cmp    %rax,%rbx
jb     1390 <main+0x1b0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    13fd <main+0x21d>
lea    0xd25(%rip),%rdi
call   1060 <puts@plt>
mov    0x0(%r13),%esi
mov    0x2c16(%rip),%rax
cmp    (%rax),%esi
jne    13ef <main+0x20f>
lea    0xd1d(%rip),%rdi
call   1060 <puts@plt>
xor    %r15d,%r15d
jmp    1403 <main+0x223>
lea    0xd1b(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%r15d
lea    0xc85(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1661 <main+0x481>
mov    %rax,%r12
lea    0xc6a(%rip),%rdi
call   1060 <puts@plt>
lea    0xc61(%rip),%rdi
call   1060 <puts@plt>
lea    0xd01(%rip),%rdi
call   1060 <puts@plt>
movl   $0x0,0x0(%r13)
lea    0x50(%rsp),%rdi
mov    $0x20,%esi
mov    %r12,%rdx
call   1050 <fgetws@plt>
test   %rax,%rax
je     150e <main+0x32e>
lea    0xcaf(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x50(%rsp),%rdi
call   1090 <wcslen@plt>
cmp    $0xffffffff,%eax
je     14c7 <main+0x2e7>
lea    0xce5(%rip),%r14
lea    0x50(%rsp),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x50(%rsp,%rbp,4),%edx
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1090 <wcslen@plt>
add    $0x1,%eax
cltq
cmp    %rax,%rbp
jb     14a0 <main+0x2c0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%cl
xor    %eax,%eax
cmp    $0xa,%cl
je     14f7 <main+0x317>
nopl   0x0(%rax)
movsbl %cl,%ecx
cmp    %ecx,0x50(%rsp,%rax,4)
jne    154b <main+0x36b>
movzbl 0x9(%rsp,%rax,1),%ecx
add    $0x1,%rax
cmp    $0xa,%cl
jne    14e0 <main+0x300>
cmpl   $0xa,0x50(%rsp,%rax,4)
jne    1532 <main+0x352>
cmpl   $0x0,0x54(%rsp,%rax,4)
je     155d <main+0x37d>
lea    0xca2(%rip),%rdi
jmp    1552 <main+0x372>
lea    0xbda(%rip),%rdi
call   1060 <puts@plt>
mov    0x0(%r13),%esi
mov    0x2acb(%rip),%rax
cmp    (%rax),%esi
jne    153b <main+0x35b>
lea    0xbd2(%rip),%rdi
jmp    1552 <main+0x372>
lea    0xc65(%rip),%rdi
jmp    1552 <main+0x372>
lea    0xbcf(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1557 <main+0x377>
lea    0xc34(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%r15d
lea    0xc69(%rip),%rdi
call   1060 <puts@plt>
movl   $0x0,0x0(%r13)
lea    0x50(%rsp),%rdi
mov    $0x20,%esi
mov    %r12,%rdx
call   1050 <fgetws@plt>
test   %rax,%rax
je     15f3 <main+0x413>
lea    0xb8e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x50(%rsp),%rdi
call   1090 <wcslen@plt>
cmp    $0xffffffff,%eax
je     15e7 <main+0x407>
lea    0xbc4(%rip),%r14
lea    0x50(%rsp),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    0x50(%rsp,%rbp,4),%edx
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1090 <wcslen@plt>
add    $0x1,%eax
cltq
cmp    %rax,%rbp
jb     15c0 <main+0x3e0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1630 <main+0x450>
lea    0xaf5(%rip),%rdi
call   1060 <puts@plt>
mov    0x0(%r13),%esi
mov    0x29e6(%rip),%rax
cmp    (%rax),%esi
jne    161c <main+0x43c>
lea    0xaed(%rip),%rdi
call   1060 <puts@plt>
jmp    1630 <main+0x450>
lea    0xaee(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%r15d
mov    %r12,%rdi
call   1070 <fclose@plt>
lea    0x30(%rsp),%rdi
call   1040 <unlink@plt>
lea    0x10(%rsp),%rdi
call   1040 <unlink@plt>
mov    %r15d,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2970(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xa0a(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    16b9 <main+0x4d9>
lea    0x9dd(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    16b9 <main+0x4d9>
mov    0x2943(%rip),%rax
mov    (%rax),%edi
lea    0x99a(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    16b9 <main+0x4d9>
mov    0x8(%r14),%rsi
lea    0x9cd(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2908(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@__const.main.il_str1 = [3 x i8] c"\E3\81\00"
@__const.main.il_str2 = [8 x i8] c"0\0AAB\E3\81E\00"
@__const.main.name1 = [27 x i8] c"/tmp/tst-fgetws.out.XXXXXX\00"
@__const.main.name2 = [27 x i8] c"/tmp/tst-fgetws.out.XXXXXX\00"
@.str = [41 x i8] c"This program runs on de_DE.UTF-8 locale.\00"
@LC_ALL = global i32 0
@.str.1 = [12 x i8] c"de_DE.UTF-8\00"
@stderr = global i32 0
@.str.2 = [42 x i8] c"Err: Cannot run on the de_DE.UTF-8 locale\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [27 x i8] c"cannot open temp file: %m\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [16 x i8] c"Can't open %s.\0A\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [3 x i8] c"--\00"
@.str.8 = [66 x i8] c"Read a byte sequence which is invalid as a wide character string.\00"
@.str.9 = [25 x i8] c" bytes: 0xe3, 0x81, '\\0'\00"
@errno = global i32 0
@.str.10 = [19 x i8] c"Return Value: NULL\00"
@EILSEQ = global i32 0
@.str.11 = [15 x i8] c"errno = EILSEQ\00"
@.str.12 = [12 x i8] c"errno = %d\0A\00"
@.str.13 = [18 x i8] c"Return Value: %p\0A\00"
@.str.14 = [17 x i8] c" wcs[%zd] = %04x\00"
@.str.15 = [2 x i8] c"\0A\00"
@.str.16 = [51 x i8] c" bytes: '0', '\\n', 'A', 'B', 0xe3, 0x81, 'c', '\\0'\00"
@.str.17 = [19 x i8] c" wcs[%zd] = 0x%04x\00"
@.str.18 = [24 x i8] c"read string not correct\00"
@.str.19 = [16 x i8] c"newline missing\00"
@.str.20 = [31 x i8] c"read string not NUL-terminated\00"
@.str.21 = [13 x i8] c"\0Asecond line\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [32 x i32]
%10 = alloca i32
%11 = alloca [3 x i8]
%12 = alloca [8 x i8]
%13 = alloca [27 x i8]
%14 = alloca [27 x i8]
%15 = alloca i32
%16 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%17 = bitcast [3 x i8]* %11 to i8*
%18 = bitcast [8 x i8]* %12 to i8*
%19 = bitcast [27 x i8]* %13 to i8*
%20 = bitcast [27 x i8]* %14 to i8*
%21 = call i32 @puts(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @LC_ALL
%23 = call i32* @setlocale(i32 %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %30
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %2
%31 = getelementptr inbounds [27 x i8], [27 x i8]* %13, i64 0, i64 0
%32 = call i32 @mkstemp(i8* %31)
store i32 %32, i32* %15
%33 = load i32, i32* %15
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %30
%40 = load i32, i32* %15
%41 = call i32* @fdopen(i32 %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %41, i32** %7
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %50
43: ; preds = %39
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %39
%51 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%52 = load i32*, i32** %7
%53 = call i32 @fwrite(i8* %51, i32 1, i32 3, i32* %52)
%54 = load i32*, i32** %7
%55 = call i32 @fclose(i32* %54)
%56 = getelementptr inbounds [27 x i8], [27 x i8]* %14, i64 0, i64 0
%57 = call i32 @mkstemp(i8* %56)
store i32 %57, i32* %15
%58 = load i32, i32* %15
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %50
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %50
%65 = load i32, i32* %15
%66 = call i32* @fdopen(i32 %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %66, i32** %7
%67 = icmp eq i32* %66, null
br i1 %67, label %68, label %76
68: ; preds = %64
%69 = load i32, i32* @stderr
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 1
%72 = load i8*, i8** %71
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %72)
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %64
%77 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%78 = load i32*, i32** %7
%79 = call i32 @fwrite(i8* %77, i32 1, i32 8, i32* %78)
%80 = load i32*, i32** %7
%81 = call i32 @fclose(i32* %80)
%82 = getelementptr inbounds [27 x i8], [27 x i8]* %13, i64 0, i64 0
%83 = call i32* @fopen(i8* %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %83, i32** %7
%84 = icmp eq i32* %83, null
br i1 %84, label %85, label %93
85: ; preds = %76
%86 = load i32, i32* @stderr
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 1
%89 = load i8*, i8** %88
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %89)
%91 = load i32, i32* @EXIT_FAILURE
%92 = call i32 @exit(i32 %91)
unreachable
93: ; preds = %76
%94 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%95 = call i32 @puts(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.8, i64 0, i64 0))
%96 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* @errno
%97 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 0
%98 = load i32*, i32** %7
%99 = call i32* @fgetws(i32* %97, i32 32, i32* %98)
store i32* %99, i32** %8
%100 = load i32*, i32** %8
%101 = icmp eq i32* %100, null
br i1 %101, label %102, label %113
102: ; preds = %93
%103 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%104 = load i32, i32* @errno
%105 = load i32, i32* @EILSEQ
%106 = icmp eq i32 %104, %105
br i1 %106, label %107, label %109
107: ; preds = %102
%108 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %112
109: ; preds = %102
%110 = load i32, i32* @errno
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), i32 %110)
store i32 1, i32* %10
br label %112
112: ; preds = %109, %107
br label %134
113: ; preds = %93
%114 = load i32*, i32** %8
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0), i32* %114)
store i64 0, i64* %6
br label %116
116: ; preds = %129, %113
%117 = load i64, i64* %6
%118 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 0
%119 = call i32 @wcslen(i32* %118)
%120 = add nsw i32 %119, 1
%121 = sext i32 %120 to i64
%122 = icmp ult i64 %117, %121
br i1 %122, label %123, label %132
123: ; preds = %116
%124 = load i64, i64* %6
%125 = load i64, i64* %6
%126 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 %125
%127 = load i32, i32* %126
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.14, i64 0, i64 0), i64 %124, i32 %127)
br label %129
129: ; preds = %123
%130 = load i64, i64* %6
%131 = add i64 %130, 1
store i64 %131, i64* %6
br label %116
132: ; preds = %116
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
store i32 1, i32* %10
br label %134
134: ; preds = %132, %112
%135 = getelementptr inbounds [27 x i8], [27 x i8]* %14, i64 0, i64 0
%136 = call i32* @fopen(i8* %135, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %136, i32** %7
%137 = icmp eq i32* %136, null
br i1 %137, label %138, label %146
138: ; preds = %134
%139 = load i32, i32* @stderr
%140 = load i8**, i8*** %5
%141 = getelementptr inbounds i8*, i8** %140, i64 1
%142 = load i8*, i8** %141
%143 = call i32 (i32, i8*, ...) @fprintf(i32 %139, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %142)
%144 = load i32, i32* @EXIT_FAILURE
%145 = call i32 @exit(i32 %144)
unreachable
146: ; preds = %134
%147 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%148 = call i32 @puts(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.8, i64 0, i64 0))
%149 = call i32 @puts(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.16, i64 0, i64 0))
store i32 0, i32* @errno
%150 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 0
%151 = load i32*, i32** %7
%152 = call i32* @fgetws(i32* %150, i32 32, i32* %151)
store i32* %152, i32** %8
%153 = load i32*, i32** %8
%154 = icmp eq i32* %153, null
br i1 %154, label %155, label %166
155: ; preds = %146
%156 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%157 = load i32, i32* @errno
%158 = load i32, i32* @EILSEQ
%159 = icmp eq i32 %157, %158
br i1 %159, label %160, label %162
160: ; preds = %155
%161 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %165
162: ; preds = %155
%163 = load i32, i32* @errno
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), i32 %163)
br label %165
165: ; preds = %162, %160
store i32 1, i32* %10
br label %232
166: ; preds = %146
%167 = load i32*, i32** %8
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0), i32* %167)
store i64 0, i64* %16
br label %169
169: ; preds = %182, %166
%170 = load i64, i64* %16
%171 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 0
%172 = call i32 @wcslen(i32* %171)
%173 = add nsw i32 %172, 1
%174 = sext i32 %173 to i64
%175 = icmp ult i64 %170, %174
br i1 %175, label %176, label %185
176: ; preds = %169
%177 = load i64, i64* %16
%178 = load i64, i64* %16
%179 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 %178
%180 = load i32, i32* %179
%181 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.17, i64 0, i64 0), i64 %177, i32 %180)
br label %182
182: ; preds = %176
%183 = load i64, i64* %16
%184 = add i64 %183, 1
store i64 %184, i64* %16
br label %169
185: ; preds = %169
%186 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
store i64 0, i64* %16
br label %187
187: ; preds = %205, %185
%188 = load i64, i64* %16
%189 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 %188
%190 = load i8, i8* %189
%191 = sext i8 %190 to i32
%192 = icmp ne i32 %191, 10
br i1 %192, label %193, label %208
193: ; preds = %187
%194 = load i64, i64* %16
%195 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 %194
%196 = load i8, i8* %195
%197 = sext i8 %196 to i32
%198 = load i64, i64* %16
%199 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 %198
%200 = load i32, i32* %199
%201 = icmp ne i32 %197, %200
br i1 %201, label %202, label %204
202: ; preds = %193
%203 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.18, i64 0, i64 0))
store i32 1, i32* %10
br label %208
204: ; preds = %193
br label %205
205: ; preds = %204
%206 = load i64, i64* %16
%207 = add i64 %206, 1
store i64 %207, i64* %16
br label %187
208: ; preds = %202, %187
%209 = load i64, i64* %16
%210 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 %209
%211 = load i8, i8* %210
%212 = sext i8 %211 to i32
%213 = icmp eq i32 %212, 10
br i1 %213, label %214, label %231
214: ; preds = %208
%215 = load i64, i64* %16
%216 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 %215
%217 = load i32, i32* %216
%218 = icmp ne i32 %217, 10
br i1 %218, label %219, label %221
219: ; preds = %214
%220 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.19, i64 0, i64 0))
store i32 1, i32* %10
br label %230
221: ; preds = %214
%222 = load i64, i64* %16
%223 = add i64 %222, 1
%224 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 %223
%225 = load i32, i32* %224
%226 = icmp ne i32 %225, 0
br i1 %226, label %227, label %229
227: ; preds = %221
%228 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.20, i64 0, i64 0))
store i32 1, i32* %10
br label %229
229: ; preds = %227, %221
br label %230
230: ; preds = %229, %219
br label %231
231: ; preds = %230, %208
br label %232
232: ; preds = %231, %165
%233 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.21, i64 0, i64 0))
store i32 0, i32* @errno
%234 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 0
%235 = load i32*, i32** %7
%236 = call i32* @fgetws(i32* %234, i32 32, i32* %235)
store i32* %236, i32** %8
%237 = load i32*, i32** %8
%238 = icmp eq i32* %237, null
br i1 %238, label %239, label %250
239: ; preds = %232
%240 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%241 = load i32, i32* @errno
%242 = load i32, i32* @EILSEQ
%243 = icmp eq i32 %241, %242
br i1 %243, label %244, label %246
244: ; preds = %239
%245 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %249
246: ; preds = %239
%247 = load i32, i32* @errno
%248 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), i32 %247)
store i32 1, i32* %10
br label %249
249: ; preds = %246, %244
br label %271
250: ; preds = %232
%251 = load i32*, i32** %8
%252 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0), i32* %251)
store i64 0, i64* %6
br label %253
253: ; preds = %266, %250
%254 = load i64, i64* %6
%255 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 0
%256 = call i32 @wcslen(i32* %255)
%257 = add nsw i32 %256, 1
%258 = sext i32 %257 to i64
%259 = icmp ult i64 %254, %258
br i1 %259, label %260, label %269
260: ; preds = %253
%261 = load i64, i64* %6
%262 = load i64, i64* %6
%263 = getelementptr inbounds [32 x i32], [32 x i32]* %9, i64 0, i64 %262
%264 = load i32, i32* %263
%265 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.17, i64 0, i64 0), i64 %261, i32 %264)
br label %266
266: ; preds = %260
%267 = load i64, i64* %6
%268 = add i64 %267, 1
store i64 %268, i64* %6
br label %253
269: ; preds = %253
%270 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
br label %271
271: ; preds = %269, %249
%272 = load i32*, i32** %7
%273 = call i32 @fclose(i32* %272)
%274 = getelementptr inbounds [27 x i8], [27 x i8]* %13, i64 0, i64 0
%275 = call i32 @unlink(i8* %274)
%276 = getelementptr inbounds [27 x i8], [27 x i8]* %14, i64 0, i64 0
%277 = call i32 @unlink(i8* %276)
%278 = load i32, i32* %10
ret i32 %278
}

LLVM IR (-O2):
@__const.main.il_str1 = [3 x i8] c"\E3\81\00"
@__const.main.name2 = [27 x i8] c"/tmp/tst-fgetws.out.XXXXXX\00"
@.str = [41 x i8] c"This program runs on de_DE.UTF-8 locale.\00"
@LC_ALL = global i32 0
@.str.1 = [12 x i8] c"de_DE.UTF-8\00"
@stderr = global i32 0
@.str.2 = [42 x i8] c"Err: Cannot run on the de_DE.UTF-8 locale\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [27 x i8] c"cannot open temp file: %m\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [16 x i8] c"Can't open %s.\0A\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [3 x i8] c"--\00"
@.str.8 = [66 x i8] c"Read a byte sequence which is invalid as a wide character string.\00"
@.str.9 = [25 x i8] c" bytes: 0xe3, 0x81, '\\0'\00"
@errno = global i32 0
@.str.10 = [19 x i8] c"Return Value: NULL\00"
@EILSEQ = global i32 0
@.str.11 = [15 x i8] c"errno = EILSEQ\00"
@.str.12 = [12 x i8] c"errno = %d\0A\00"
@.str.13 = [18 x i8] c"Return Value: %p\0A\00"
@.str.14 = [17 x i8] c" wcs[%zd] = %04x\00"
@.str.16 = [51 x i8] c" bytes: '0', '\\n', 'A', 'B', 0xe3, 0x81, 'c', '\\0'\00"
@.str.17 = [19 x i8] c" wcs[%zd] = 0x%04x\00"
@.str.18 = [24 x i8] c"read string not correct\00"
@.str.19 = [16 x i8] c"newline missing\00"
@.str.20 = [31 x i8] c"read string not NUL-terminated\00"
@.str.21 = [13 x i8] c"\0Asecond line\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [32 x i32]
%4 = alloca [3 x i8]
%5 = alloca i64
%6 = bitcast i64* %5 to [8 x i8]*
%7 = alloca [27 x i8]
%8 = alloca [27 x i8]
%9 = bitcast [32 x i32]* %3 to i8*
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%11 = bitcast i64* %5 to i8*
store i64 19564586462153264, i64* %5
%12 = getelementptr inbounds [27 x i8], [27 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [27 x i8], [27 x i8]* %8, i64 0, i64 0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @LC_ALL
%16 = tail call i32* @setlocale(i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = call i32 @mkstemp(i8* %12)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %23
%31 = call i32* @fdopen(i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %30
%40 = call i32 @fwrite(i8* %10, i32 1, i32 3, i32* %31)
%41 = call i32 @fclose(i32* %31)
%42 = call i32 @mkstemp(i8* %13)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %39
%49 = call i32* @fdopen(i32 %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %58
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = getelementptr inbounds i8*, i8** %1, i64 1
%54 = load i8*, i8** %53
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %54)
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %48
%59 = call i32 @fwrite(i8* %11, i32 1, i32 8, i32* %49)
%60 = call i32 @fclose(i32* %49)
%61 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%62 = icmp eq i32* %61, null
br i1 %62, label %63, label %70
63: ; preds = %58
%64 = load i32, i32* @stderr
%65 = getelementptr inbounds i8*, i8** %1, i64 1
%66 = load i8*, i8** %65
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %66)
%68 = load i32, i32* @EXIT_FAILURE
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %58
%71 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.8, i64 0, i64 0))
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* @errno
%74 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%75 = call i32* @fgetws(i32* %74, i32 32, i32* %61)
%76 = icmp eq i32* %75, null
br i1 %76, label %77, label %86
77: ; preds = %70
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%79 = load i32, i32* @errno
%80 = load i32, i32* @EILSEQ
%81 = icmp eq i32 %79, %80
br i1 %81, label %82, label %84
82: ; preds = %77
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %102
84: ; preds = %77
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), i32 %79)
br label %102
86: ; preds = %70
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0), i32* %75)
%88 = call i32 @wcslen(i32* %74)
%89 = icmp eq i32 %88, -1
br i1 %89, label %100, label %90
90: ; preds = %86, %90
%91 = phi i64 [ %95, %90 ], [ 0, %86 ]
%92 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %91
%93 = load i32, i32* %92
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.14, i64 0, i64 0), i64 %91, i32 %93)
%95 = add nuw i64 %91, 1
%96 = call i32 @wcslen(i32* %74)
%97 = add nsw i32 %96, 1
%98 = sext i32 %97 to i64
%99 = icmp ult i64 %95, %98
br i1 %99, label %90, label %100
100: ; preds = %90, %86
%101 = call i32 @putchar(i32 10)
br label %102
102: ; preds = %82, %84, %100
%103 = phi i32 [ 0, %82 ], [ 1, %84 ], [ 1, %100 ]
%104 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%105 = icmp eq i32* %104, null
br i1 %105, label %106, label %113
106: ; preds = %102
%107 = load i32, i32* @stderr
%108 = getelementptr inbounds i8*, i8** %1, i64 1
%109 = load i8*, i8** %108
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %109)
%111 = load i32, i32* @EXIT_FAILURE
%112 = call i32 @exit(i32 %111)
unreachable
113: ; preds = %102
%114 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%115 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.8, i64 0, i64 0))
%116 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.16, i64 0, i64 0))
store i32 0, i32* @errno
%117 = call i32* @fgetws(i32* %74, i32 32, i32* %104)
%118 = icmp eq i32* %117, null
br i1 %118, label %119, label %128
119: ; preds = %113
%120 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%121 = load i32, i32* @errno
%122 = load i32, i32* @EILSEQ
%123 = icmp eq i32 %121, %122
br i1 %123, label %124, label %126
124: ; preds = %119
%125 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %174
126: ; preds = %119
%127 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), i32 %121)
br label %174
128: ; preds = %113
%129 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0), i32* %117)
%130 = call i32 @wcslen(i32* %74)
%131 = icmp eq i32 %130, -1
br i1 %131, label %142, label %132
132: ; preds = %128, %132
%133 = phi i64 [ %137, %132 ], [ 0, %128 ]
%134 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %133
%135 = load i32, i32* %134
%136 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.17, i64 0, i64 0), i64 %133, i32 %135)
%137 = add nuw i64 %133, 1
%138 = call i32 @wcslen(i32* %74)
%139 = add nsw i32 %138, 1
%140 = sext i32 %139 to i64
%141 = icmp ult i64 %137, %140
br i1 %141, label %132, label %142
142: ; preds = %132, %128
%143 = call i32 @putchar(i32 10)
%144 = load i8, i8* %11
%145 = icmp eq i8 %144, 10
br i1 %145, label %160, label %146
146: ; preds = %142, %153
%147 = phi i8 [ %156, %153 ], [ %144, %142 ]
%148 = phi i64 [ %154, %153 ], [ 0, %142 ]
%149 = sext i8 %147 to i32
%150 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %148
%151 = load i32, i32* %150
%152 = icmp eq i32 %151, %149
br i1 %152, label %153, label %158
153: ; preds = %146
%154 = add i64 %148, 1
%155 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %154
%156 = load i8, i8* %155
%157 = icmp eq i8 %156, 10
br i1 %157, label %160, label %146
158: ; preds = %146
%159 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.18, i64 0, i64 0))
br label %174
160: ; preds = %153, %142
%161 = phi i64 [ 0, %142 ], [ %154, %153 ]
%162 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %161
%163 = load i32, i32* %162
%164 = icmp eq i32 %163, 10
br i1 %164, label %167, label %165
165: ; preds = %160
%166 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.19, i64 0, i64 0))
br label %174
167: ; preds = %160
%168 = add i64 %161, 1
%169 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %168
%170 = load i32, i32* %169
%171 = icmp eq i32 %170, 0
br i1 %171, label %174, label %172
172: ; preds = %167
%173 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.20, i64 0, i64 0))
br label %174
174: ; preds = %158, %167, %172, %165, %124, %126
%175 = phi i32 [ 1, %126 ], [ 1, %124 ], [ 1, %165 ], [ 1, %172 ], [ %103, %167 ], [ 1, %158 ]
%176 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.21, i64 0, i64 0))
store i32 0, i32* @errno
%177 = call i32* @fgetws(i32* %74, i32 32, i32* %104)
%178 = icmp eq i32* %177, null
br i1 %178, label %179, label %188
179: ; preds = %174
%180 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%181 = load i32, i32* @errno
%182 = load i32, i32* @EILSEQ
%183 = icmp eq i32 %181, %182
br i1 %183, label %184, label %186
184: ; preds = %179
%185 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %204
186: ; preds = %179
%187 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), i32 %181)
br label %204
188: ; preds = %174
%189 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0), i32* %177)
%190 = call i32 @wcslen(i32* %74)
%191 = icmp eq i32 %190, -1
br i1 %191, label %202, label %192
192: ; preds = %188, %192
%193 = phi i64 [ %197, %192 ], [ 0, %188 ]
%194 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %193
%195 = load i32, i32* %194
%196 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.17, i64 0, i64 0), i64 %193, i32 %195)
%197 = add nuw i64 %193, 1
%198 = call i32 @wcslen(i32* %74)
%199 = add nsw i32 %198, 1
%200 = sext i32 %199 to i64
%201 = icmp ult i64 %197, %200
br i1 %201, label %192, label %202
202: ; preds = %192, %188
%203 = call i32 @putchar(i32 10)
br label %204
204: ; preds = %184, %186, %202
%205 = phi i32 [ %175, %184 ], [ 1, %186 ], [ %175, %202 ]
%206 = call i32 @fclose(i32* %104)
%207 = call i32 @unlink(i8* %12)
%208 = call i32 @unlink(i8* %13)
ret i32 %205
}