#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 const *,
                int /*<<< orphan*/ *);
char *snvis(char *mbdst, size_t dlen, int c, int flags, int nextc,
            const char *mbextra) {
  char cc[2];
  int ret;
  cc[0] = (char)c;
  cc[1] = (char)nextc;
  ret = istrsenvisx(mbdst, &dlen, cc, 1, flags, mbextra, NULL);
  if (ret < 0) {
    return NULL;
  }
  return mbdst + ret;
}


x86 assembly (clang, -O0):
<snvis>:
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    %r9,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,-0x32(%rbp)
mov    -0x24(%rbp),%eax
mov    %al,-0x31(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x32(%rbp),%rdx
mov    -0x20(%rbp),%r8d
mov    -0x30(%rbp),%r9
lea    -0x18(%rbp),%rsi
mov    $0x1,%ecx
xor    %eax,%eax
movq   $0x0,(%rsp)
call   1030 <istrsenvisx@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    117c <snvis+0x6c>
movq   $0x0,-0x8(%rbp)
jmp    118b <snvis+0x7b>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snvis>:
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    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):
define i8* @snvis(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca [2 x i8]
%15 = alloca i32
store i8* %0, i8** %8
store i64 %1, i64* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i8* %5, i8** %13
%16 = load i32, i32* %10
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %14, i64 0, i64 0
store i8 %17, i8* %18
%19 = load i32, i32* %12
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %14, i64 0, i64 1
store i8 %20, i8* %21
%22 = load i8*, i8** %8
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %14, i64 0, i64 0
%24 = load i32, i32* %11
%25 = load i8*, i8** %13
%26 = call i32 @istrsenvisx(i8* %22, i64* %9, i8* %23, i32 1, i32 %24, i8* %25, i32* null)
store i32 %26, i32* %15
%27 = load i32, i32* %15
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %6
store i8* null, i8** %7
br label %35
30: ; preds = %6
%31 = load i8*, i8** %8
%32 = load i32, i32* %15
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8* %34, i8** %7
br label %35
35: ; preds = %30, %29
%36 = load i8*, i8** %7
ret i8* %36
}

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