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

/* Variables and functions */
size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) {
  if (s == NULL) {
    s = "";
    pwc = NULL;
  }
  if (n == 0) {
    if (pwc)
      *pwc = 0;
    return 0;
  }
  if (pwc)
    *pwc = *s;
  return (*s != 0);
}


x86 assembly (clang, -O0):
<mbrtowc>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1132 <mbrtowc+0x32>
lea    0xeda(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115c <mbrtowc+0x5c>
cmpq   $0x0,-0x10(%rbp)
je     114f <mbrtowc+0x4f>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    118b <mbrtowc+0x8b>
cmpq   $0x0,-0x10(%rbp)
je     1173 <mbrtowc+0x73>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<mbrtowc>:
test   %rsi,%rsi
lea    0xef6(%rip),%rcx
cmovne %rsi,%rcx
cmove  %rsi,%rdi
test   %rdx,%rdx
je     1129 <mbrtowc+0x29>
test   %rdi,%rdi
je     1120 <mbrtowc+0x20>
mov    (%rcx),%al
mov    %al,(%rdi)
xor    %eax,%eax
cmpb   $0x0,(%rcx)
setne  %al
ret
test   %rdi,%rdi
je     1131 <mbrtowc+0x31>
movb   $0x0,(%rdi)
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i64 @mbrtowc(i8* %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32* %3, i32** %9
%10 = load i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %4
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* null, i8** %6
br label %13
13: ; preds = %12, %4
%14 = load i64, i64* %8
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load i8*, i8** %6
store i8 0, i8* %20
br label %21
21: ; preds = %19, %16
store i64 0, i64* %5
br label %36
22: ; preds = %13
%23 = load i8*, i8** %6
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i8*, i8** %7
%27 = load i8, i8* %26
%28 = load i8*, i8** %6
store i8 %27, i8* %28
br label %29
29: ; preds = %25, %22
%30 = load i8*, i8** %7
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i32
%35 = sext i32 %34 to i64
store i64 %35, i64* %5
br label %36
36: ; preds = %29, %21
%37 = load i64, i64* %5
ret i64 %37
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i64 @mbrtowc(i8* writeonly %0, i8* %1, i64 %2, i32* nocapture readnone %3) {
%5 = icmp eq i8* %1, null
%6 = select i1 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %1
%7 = select i1 %5, i8* null, i8* %0
%8 = icmp eq i64 %2, 0
%9 = icmp eq i8* %7, null
br i1 %8, label %10, label %12
10: ; preds = %4
br i1 %9, label %19, label %11
11: ; preds = %10
store i8 0, i8* %7
br label %19
12: ; preds = %4
br i1 %9, label %15, label %13
13: ; preds = %12
%14 = load i8, i8* %6
store i8 %14, i8* %7
br label %15
15: ; preds = %13, %12
%16 = load i8, i8* %6
%17 = icmp ne i8 %16, 0
%18 = zext i1 %17 to i64
br label %19
19: ; preds = %10, %11, %15
%20 = phi i64 [ %18, %15 ], [ 0, %11 ], [ 0, %10 ]
ret i64 %20
}