#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ wchar_t;
typedef int /*<<< orphan*/ mbstate_t;

/* Variables and functions */
int mbrtowc(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ *);
int readwc(int c, wchar_t **wcs, mbstate_t *st) {
  char ch = c;
  wchar_t wc;
  switch (mbrtowc(&wc, &ch, 1, st)) {
  case -1:
    return -1;
  case -2:
    break;
  default:
    if (*wcs)
      *(*wcs)++ = wc;
  }
  return 0;
}


x86 assembly (clang, -O0):
<readwc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <mbrtowc@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
sub    $0xfffffffe,%eax
je     116f <readwc+0x5f>
jmp    1152 <readwc+0x42>
mov    -0x24(%rbp),%eax
sub    $0xffffffff,%eax
jne    1174 <readwc+0x64>
jmp    1163 <readwc+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a4 <readwc+0x94>
jmp    119d <readwc+0x8d>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1198 <readwc+0x88>
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x4,%rsi
mov    %rsi,(%rdx)
mov    %ecx,(%rax)
jmp    119d <readwc+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readwc>:
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rcx
mov    %rsi,%rbx
mov    %dil,0xb(%rsp)
lea    0xc(%rsp),%rdi
lea    0xb(%rsp),%rsi
mov    $0x1,%edx
call   1030 <mbrtowc@plt>
cmp    $0xfffffffe,%eax
je     1153 <readwc+0x43>
cmp    $0xffffffff,%eax
je     1155 <readwc+0x45>
mov    (%rbx),%rax
test   %rax,%rax
je     1153 <readwc+0x43>
mov    0xc(%rsp),%ecx
lea    0x4(%rax),%rdx
mov    %rdx,(%rbx)
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @readwc(i32 %0, i32** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32*
%8 = alloca i8
%9 = alloca i32
store i32 %0, i32* %5
store i32** %1, i32*** %6
store i32* %2, i32** %7
%10 = load i32, i32* %5
%11 = trunc i32 %10 to i8
store i8 %11, i8* %8
%12 = load i32*, i32** %7
%13 = call i32 @mbrtowc(i32* %9, i8* %8, i32 1, i32* %12)
switch i32 %13, label %16 [
i32 -1, label %14
i32 -2, label %15
]
14: ; preds = %3
store i32 -1, i32* %4
br label %27
15: ; preds = %3
br label %26
16: ; preds = %3
%17 = load i32**, i32*** %6
%18 = load i32*, i32** %17
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* %9
%22 = load i32**, i32*** %6
%23 = load i32*, i32** %22
%24 = getelementptr inbounds i32, i32* %23, i32 1
store i32* %24, i32** %22
store i32 %21, i32* %23
br label %25
25: ; preds = %20, %16
br label %26
26: ; preds = %25, %15
store i32 0, i32* %4
br label %27
27: ; preds = %26, %14
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
define i32 @readwc(i32 %0, i32** nocapture %1, i32* %2) {
%4 = alloca i8
%5 = alloca i32
%6 = trunc i32 %0 to i8
store i8 %6, i8* %4
%7 = bitcast i32* %5 to i8*
%8 = call i32 @mbrtowc(i32* %5, i8* %4, i32 1, i32* %2)
switch i32 %8, label %9 [
i32 -1, label %16
i32 -2, label %15
]
9: ; preds = %3
%10 = load i32*, i32** %1
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* %5
%14 = getelementptr inbounds i32, i32* %10, i64 1
store i32* %14, i32** %1
store i32 %13, i32* %10
br label %15
15: ; preds = %9, %12, %3
br label %16
16: ; preds = %3, %15
%17 = phi i32 [ 0, %15 ], [ %8, %3 ]
ret i32 %17
}