#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 *, int /*<<< orphan*/ *, char *, int, int, char const *,
                int /*<<< orphan*/ *);
char *svis(char *mbdst, 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, NULL, cc, 1, flags, mbextra, NULL);
  if (ret < 0) {
    return NULL;
  }
  return mbdst + ret;
}


x86 assembly (clang, -O0):
<svis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x2a(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,-0x29(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x2a(%rbp),%rdx
mov    -0x18(%rbp),%r8d
mov    -0x28(%rbp),%r9
xor    %eax,%eax
mov    %eax,%esi
mov    $0x1,%ecx
movq   $0x0,(%rsp)
call   1030 <istrsenvisx@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1175 <svis+0x65>
movq   $0x0,-0x8(%rbp)
jmp    1184 <svis+0x74>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<svis>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r9
mov    %edx,%r8d
mov    %rdi,%rbx
mov    %sil,0x16(%rsp)
mov    %cl,0x17(%rsp)
movq   $0x0,(%rsp)
xor    %r14d,%r14d
lea    0x16(%rsp),%rdx
xor    %esi,%esi
mov    $0x1,%ecx
call   1030 <istrsenvisx@plt>
cltq
add    %rax,%rbx
test   %eax,%eax
cmovs  %r14,%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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