#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 /*<<< orphan*/ sjis_cpy(unsigned char *, size_t *, unsigned int *, int);
int utf_to_eci(int, unsigned char const *, unsigned char *, size_t *);
__attribute__((visibility("hidden"))) int
sjis_utf8tosb(int eci, const unsigned char source[], size_t *p_length,
              unsigned int *jisdata, int full_multibyte) {
  int error_number;
  unsigned char single_byte[*p_length + 1];
  error_number = utf_to_eci(eci, source, single_byte, p_length);
  if (error_number != 0) {
    return error_number;
  }
  sjis_cpy(single_byte, p_length, jisdata, full_multibyte);
  return 0;
}


x86 assembly (clang, -O0):
<sjis_utf8tosb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rsp,%rdx
mov    %rdx,-0x30(%rbp)
add    $0x10,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
call   1030 <utf_to_eci@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1198 <sjis_utf8tosb+0x78>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    11ba <sjis_utf8tosb+0x9a>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1040 <sjis_cpy@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sjis_utf8tosb>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %rdx,%r12
mov    (%rdx),%rax
mov    %rsp,%rbx
add    $0x10,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdx
mov    %r12,%rcx
call   1030 <utf_to_eci@plt>
mov    %eax,%r13d
test   %eax,%eax
jne    116e <sjis_utf8tosb+0x4e>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1040 <sjis_cpy@plt>
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define hidden i32 @sjis_utf8tosb(i32 %0, i8* %1, i64* %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i64* %2, i64** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
%16 = load i64*, i64** %9
%17 = load i64, i64* %16
%18 = add i64 %17, 1
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %13
%20 = alloca i8, i64 %18
store i64 %18, i64* %14
%21 = load i32, i32* %7
%22 = load i8*, i8** %8
%23 = load i64*, i64** %9
%24 = call i32 @utf_to_eci(i32 %21, i8* %22, i8* %20, i64* %23)
store i32 %24, i32* %12
%25 = load i32, i32* %12
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %5
%28 = load i32, i32* %12
store i32 %28, i32* %6
store i32 1, i32* %15
br label %34
29: ; preds = %5
%30 = load i64*, i64** %9
%31 = load i32*, i32** %10
%32 = load i32, i32* %11
%33 = call i32 @sjis_cpy(i8* %20, i64* %30, i32* %31, i32 %32)
store i32 0, i32* %6
store i32 1, i32* %15
br label %34
34: ; preds = %29, %27
%35 = load i8*, i8** %13
%36 = load i32, i32* %6
ret i32 %36
}

LLVM IR (-O2):
define hidden i32 @sjis_utf8tosb(i32 %0, i8* %1, i64* %2, i32* %3, i32 %4) {
%6 = load i64, i64* %2
%7 = add i64 %6, 1
%8 = alloca i8, i64 %7
%9 = call i32 @utf_to_eci(i32 %0, i8* %1, i8* %8, i64* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = call i32 @sjis_cpy(i8* %8, i64* %2, i32* %3, i32 %4)
br label %13
13: ; preds = %5, %11
ret i32 %9
}