#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 scalar_t__ wchar_t;

/* Variables and functions */
int _citrus_NONE_ctype_mbsrtowcs(void *__restrict cl, wchar_t *__restrict pwcs,
                                 const char **__restrict s, size_t n,
                                 void *__restrict pspriv,
                                 size_t *__restrict nresult) {
  int cnt;
  const char *s0;
  if (pwcs == NULL)
    n = 1;
  cnt = 0;
  s0 = *s;
  while (n > 0) {
    if (pwcs != NULL) {
      *pwcs = (wchar_t)(unsigned char)*s0;
    }
    if (*s0 == '\0') {
      s0 = NULL;
      break;
    }
    s0++;
    if (pwcs != NULL) {
      pwcs++;
      n--;
    }
    cnt++;
  }
  if (pwcs)
    *s = s0;
  *nresult = (size_t)cnt;
  return (0);
}


x86 assembly (clang, -O0):
<_citrus_NONE_ctype_mbsrtowcs>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    112f <_citrus_NONE_ctype_mbsrtowcs+0x2f>
movq   $0x1,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    11c1 <_citrus_NONE_ctype_mbsrtowcs+0xc1>
cmpq   $0x0,-0x10(%rbp)
je     1167 <_citrus_NONE_ctype_mbsrtowcs+0x67>
mov    -0x40(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1184 <_citrus_NONE_ctype_mbsrtowcs+0x84>
movq   $0x0,-0x40(%rbp)
jmp    11c1 <_citrus_NONE_ctype_mbsrtowcs+0xc1>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b3 <_citrus_NONE_ctype_mbsrtowcs+0xb3>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1141 <_citrus_NONE_ctype_mbsrtowcs+0x41>
cmpq   $0x0,-0x10(%rbp)
je     11d7 <_citrus_NONE_ctype_mbsrtowcs+0xd7>
mov    -0x40(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movslq -0x34(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_citrus_NONE_ctype_mbsrtowcs>:
test   %rsi,%rsi
mov    (%rdx),%r8
mov    $0x1,%edi
cmovne %rcx,%rdi
xor    %ecx,%ecx
test   %rdi,%rdi
je     1150 <_citrus_NONE_ctype_mbsrtowcs+0x50>
cs nopw 0x0(%rax,%rax,1)
test   %rsi,%rsi
je     112d <_citrus_NONE_ctype_mbsrtowcs+0x2d>
movzbl (%r8,%rcx,1),%eax
mov    %rax,(%rsi)
cmpb   $0x0,(%r8,%rcx,1)
je     1160 <_citrus_NONE_ctype_mbsrtowcs+0x60>
lea    0x8(%rsi),%r10
xor    %eax,%eax
test   %rsi,%rsi
setne  %al
cmovne %r10,%rsi
add    $0x1,%rcx
sub    %rax,%rdi
jne    1120 <_citrus_NONE_ctype_mbsrtowcs+0x20>
add    %rcx,%r8
test   %rsi,%rsi
je     1158 <_citrus_NONE_ctype_mbsrtowcs+0x58>
mov    %r8,(%rdx)
mov    %ecx,%eax
mov    %rax,(%r9)
xor    %eax,%eax
ret
xor    %r8d,%r8d
test   %rsi,%rsi
jne    1155 <_citrus_NONE_ctype_mbsrtowcs+0x55>
jmp    1158 <_citrus_NONE_ctype_mbsrtowcs+0x58>

LLVM IR (-O0):
define i32 @_citrus_NONE_ctype_mbsrtowcs(i8* noalias %0, i64* noalias %1, i8** noalias %2, i64 %3, i8* noalias %4, i64* noalias %5) {
%7 = alloca i8*
%8 = alloca i64*
%9 = alloca i8**
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64*
%13 = alloca i32
%14 = alloca i8*
store i8* %0, i8** %7
store i64* %1, i64** %8
store i8** %2, i8*** %9
store i64 %3, i64* %10
store i8* %4, i8** %11
store i64* %5, i64** %12
%15 = load i64*, i64** %8
%16 = icmp eq i64* %15, null
br i1 %16, label %17, label %18
17: ; preds = %6
store i64 1, i64* %10
br label %18
18: ; preds = %17, %6
store i32 0, i32* %13
%19 = load i8**, i8*** %9
%20 = load i8*, i8** %19
store i8* %20, i8** %14
br label %21
21: ; preds = %48, %18
%22 = load i64, i64* %10
%23 = icmp ugt i64 %22, 0
br i1 %23, label %24, label %51
24: ; preds = %21
%25 = load i64*, i64** %8
%26 = icmp ne i64* %25, null
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i8*, i8** %14
%29 = load i8, i8* %28
%30 = zext i8 %29 to i64
%31 = load i64*, i64** %8
store i64 %30, i64* %31
br label %32
32: ; preds = %27, %24
%33 = load i8*, i8** %14
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i8* null, i8** %14
br label %51
38: ; preds = %32
%39 = load i8*, i8** %14
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %14
%41 = load i64*, i64** %8
%42 = icmp ne i64* %41, null
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = load i64*, i64** %8
%45 = getelementptr inbounds i64, i64* %44, i32 1
store i64* %45, i64** %8
%46 = load i64, i64* %10
%47 = add i64 %46, -1
store i64 %47, i64* %10
br label %48
48: ; preds = %43, %38
%49 = load i32, i32* %13
%50 = add nsw i32 %49, 1
store i32 %50, i32* %13
br label %21
51: ; preds = %37, %21
%52 = load i64*, i64** %8
%53 = icmp ne i64* %52, null
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i8*, i8** %14
%56 = load i8**, i8*** %9
store i8* %55, i8** %56
br label %57
57: ; preds = %54, %51
%58 = load i32, i32* %13
%59 = sext i32 %58 to i64
%60 = load i64*, i64** %12
store i64 %59, i64* %60
ret i32 0
}

LLVM IR (-O2):
define i32 @_citrus_NONE_ctype_mbsrtowcs(i8* noalias nocapture readnone %0, i64* noalias writeonly %1, i8** noalias nocapture %2, i64 %3, i8* noalias nocapture readnone %4, i64* noalias nocapture writeonly %5) {
%7 = icmp eq i64* %1, null
%8 = load i8*, i8** %2
%9 = select i1 %7, i64 1, i64 %3
%10 = icmp eq i64 %9, 0
br i1 %10, label %32, label %11
11: ; preds = %6, %23
%12 = phi i8* [ %24, %23 ], [ %8, %6 ]
%13 = phi i32 [ %26, %23 ], [ 0, %6 ]
%14 = phi i64* [ %30, %23 ], [ %1, %6 ]
%15 = phi i64 [ %29, %23 ], [ %9, %6 ]
%16 = icmp eq i64* %14, null
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = load i8, i8* %12
%19 = zext i8 %18 to i64
store i64 %19, i64* %14
br label %20
20: ; preds = %17, %11
%21 = load i8, i8* %12
%22 = icmp eq i8 %21, 0
br i1 %22, label %32, label %23
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %12, i64 1
%25 = getelementptr inbounds i64, i64* %14, i64 1
%26 = add nuw nsw i32 %13, 1
%27 = xor i1 %16, true
%28 = sext i1 %27 to i64
%29 = add i64 %15, %28
%30 = select i1 %16, i64* null, i64* %25
%31 = icmp eq i64 %29, 0
br i1 %31, label %32, label %11
32: ; preds = %23, %20, %6
%33 = phi i64* [ %1, %6 ], [ %14, %20 ], [ %30, %23 ]
%34 = phi i32 [ 0, %6 ], [ %13, %20 ], [ %26, %23 ]
%35 = phi i8* [ %8, %6 ], [ null, %20 ], [ %24, %23 ]
%36 = icmp eq i64* %33, null
br i1 %36, label %38, label %37
37: ; preds = %32
store i8* %35, i8** %2
br label %38
38: ; preds = %37, %32
%39 = zext i32 %34 to i64
store i64 %39, i64* %5
ret i32 0
}