#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 */

/* Variables and functions */
int istrsenvisx(char *, size_t *, char *, int, int, char *,
                int /*<<< orphan*/ *);
char *nvis(char *mbdst, size_t dlen, int c, int flags, int nextc) {
  char cc[2];
  int ret;
  cc[0] = (char)c;
  cc[1] = (char)nextc;
  ret = istrsenvisx(mbdst, &dlen, cc, 1, flags, "", NULL);
  if (ret < 0) {
    return NULL;
  }
  return mbdst + ret;
}


x86 assembly (clang, -O0):
<nvis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,-0x26(%rbp)
mov    -0x24(%rbp),%eax
mov    %al,-0x25(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x26(%rbp),%rdx
mov    -0x20(%rbp),%r8d
lea    -0x18(%rbp),%rsi
mov    $0x1,%ecx
lea    0xeae(%rip),%r9
xor    %eax,%eax
movq   $0x0,(%rsp)
call   1030 <istrsenvisx@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    117b <nvis+0x6b>
movq   $0x0,-0x8(%rbp)
jmp    118a <nvis+0x7a>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nvis>:
push   %rbx
sub    $0x20,%rsp
mov    %ecx,%eax
mov    %rdi,%rbx
mov    %rsi,0x18(%rsp)
mov    %dl,0x16(%rsp)
mov    %r8b,0x17(%rsp)
movq   $0x0,(%rsp)
lea    0xec9(%rip),%r9
lea    0x18(%rsp),%rsi
lea    0x16(%rsp),%rdx
mov    $0x1,%ecx
mov    %eax,%r8d
call   1030 <istrsenvisx@plt>
movslq %eax,%rcx
add    %rcx,%rbx
xor    %eax,%eax
test   %ecx,%ecx
cmovns %rbx,%rax
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @nvis(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i64
%7 = alloca [2 x i8]
store i64 %1, i64* %6
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%9 = trunc i32 %2 to i8
store i8 %9, i8* %8
%10 = trunc i32 %4 to i8
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
store i8 %10, i8* %11
%12 = call i32 @istrsenvisx(i8* %0, i64* %6, i8* %8, i32 1, i32 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32* null)
%13 = icmp slt i32 %12, 0
%14 = sext i32 %12 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = select i1 %13, i8* null, i8* %15
ret i8* %16
}