#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 int /*<<< orphan*/ iconv_t;

/* Variables and functions */
scalar_t__ EILSEQ;
scalar_t__ errno;
size_t iconv(int /*<<< orphan*/, char **, size_t *, char **, size_t *);
size_t tripcode_sjis(iconv_t cd, char *s, size_t len, char *dest, size_t size) {
  size_t e;
  size_t l = size;
  errno = 0;
  e = iconv(cd, &s, &len, &dest, &l);
  if (errno && e == (size_t)-1) {
    if (errno != EILSEQ)
      return (size_t)-1;
  }
  dest[0] = '\0';
  return size - l;
}


x86 assembly (clang, -O0):
<tripcode_sjis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e9e(%rip),%rax
movq   $0x0,(%rax)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x40(%rbp),%r8
call   1030 <iconv@plt>
mov    %rax,-0x38(%rbp)
mov    0x2e74(%rip),%rax
cmpq   $0x0,(%rax)
je     11a5 <tripcode_sjis+0x95>
cmpq   $0xffffffffffffffff,-0x38(%rbp)
jne    11a5 <tripcode_sjis+0x95>
mov    0x2e58(%rip),%rax
mov    (%rax),%rax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
je     11a0 <tripcode_sjis+0x90>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11b8 <tripcode_sjis+0xa8>
jmp    11a5 <tripcode_sjis+0x95>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
sub    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tripcode_sjis>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %r8,%rbx
mov    %rsi,0x20(%rsp)
mov    %rdx,0x18(%rsp)
mov    %rcx,0x10(%rsp)
mov    %r8,0x8(%rsp)
mov    0x2ea3(%rip),%r14
movq   $0x0,(%r14)
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1030 <iconv@plt>
mov    (%r14),%rcx
test   %rcx,%rcx
je     1176 <tripcode_sjis+0x66>
cmp    $0xffffffffffffffff,%rax
jne    1176 <tripcode_sjis+0x66>
mov    0x2e86(%rip),%rdx
mov    $0xffffffffffffffff,%rax
cmp    (%rdx),%rcx
jne    1186 <tripcode_sjis+0x76>
mov    0x10(%rsp),%rax
movb   $0x0,(%rax)
sub    0x8(%rsp),%rbx
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@EILSEQ = global i64 0
define i64 @tripcode_sjis(i32 %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i32 %0, i32* %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i8* %3, i8** %10
store i64 %4, i64* %11
%14 = load i64, i64* %11
store i64 %14, i64* %13
store i64 0, i64* @errno
%15 = load i32, i32* %7
%16 = call i64 @iconv(i32 %15, i8** %8, i64* %9, i8** %10, i64* %13)
store i64 %16, i64* %12
%17 = load i64, i64* @errno
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %5
%20 = load i64, i64* %12
%21 = icmp eq i64 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i64, i64* @errno
%24 = load i64, i64* @EILSEQ
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
store i64 -1, i64* %6
br label %34
27: ; preds = %22
br label %28
28: ; preds = %27, %19, %5
%29 = load i8*, i8** %10
%30 = getelementptr inbounds i8, i8* %29, i64 0
store i8 0, i8* %30
%31 = load i64, i64* %11
%32 = load i64, i64* %13
%33 = sub i64 %31, %32
store i64 %33, i64* %6
br label %34
34: ; preds = %28, %26
%35 = load i64, i64* %6
ret i64 %35
}

LLVM IR (-O2):
@errno = global i64 0
@EILSEQ = global i64 0
define i64 @tripcode_sjis(i32 %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
store i8* %1, i8** %6
store i64 %2, i64* %7
store i8* %3, i8** %8
%10 = bitcast i64* %9 to i8*
store i64 %4, i64* %9
store i64 0, i64* @errno
%11 = call i64 @iconv(i32 %0, i8** %6, i64* %7, i8** %8, i64* %9)
%12 = load i64, i64* @errno
%13 = icmp eq i64 %12, 0
%14 = icmp ne i64 %11, -1
%15 = select i1 %13, i1 true, i1 %14
%16 = load i64, i64* @EILSEQ
%17 = icmp eq i64 %12, %16
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %23
19: ; preds = %5
%20 = load i8*, i8** %8
store i8 0, i8* %20
%21 = load i64, i64* %9
%22 = sub i64 %4, %21
br label %23
23: ; preds = %5, %19
%24 = phi i64 [ %22, %19 ], [ -1, %5 ]
ret i64 %24
}