#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 */
struct _citrus_iconv {
  int dummy;
};
typedef scalar_t__ iconv_t;

/* Variables and functions */
int EBADF;
int _citrus_iconv_convert(struct _citrus_iconv *, char **, size_t *, char **,
                          size_t *, int /*<<< orphan*/, size_t *);
int errno;
size_t libiconv(iconv_t handle, char **in, size_t *szin, char **out,
                size_t *szout) {
  size_t ret;
  int err;
  if ((!(handle) || (handle) == (iconv_t)-1)) {
    errno = EBADF;
    return ((size_t)-1);
  }
  err = _citrus_iconv_convert((struct _citrus_iconv *)(void *)handle, in, szin,
                              out, szout, 0, &ret);
  if (err) {
    errno = err;
    ret = (size_t)-1;
  }
  return (ret);
}


x86 assembly (clang, -O0):
<libiconv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1142 <libiconv+0x32>
cmpq   $0xffffffffffffffff,-0x10(%rbp)
jne    1161 <libiconv+0x51>
mov    0x2e8f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8e(%rip),%rax
mov    %ecx,(%rax)
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11ae <libiconv+0x9e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
xor    %r9d,%r9d
lea    -0x38(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <_citrus_iconv_convert@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11a6 <libiconv+0x96>
mov    -0x3c(%rbp),%ecx
mov    0x2e44(%rip),%rax
mov    %ecx,(%rax)
movq   $0xffffffffffffffff,-0x38(%rbp)
ff
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libiconv>:
sub    $0x18,%rsp
lea    0x1(%rdi),%rax
cmp    $0x1,%rax
ja     1129 <libiconv+0x19>
mov    0x2eb3(%rip),%rax
mov    (%rax),%eax
jmp    113e <libiconv+0x2e>
lea    0x10(%rsp),%rax
mov    %rax,(%rsp)
xor    %r9d,%r9d
call   1030 <_citrus_iconv_convert@plt>
test   %eax,%eax
je     1153 <libiconv+0x43>
mov    0x2e9b(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffffffffffff,%rax
add    $0x18,%rsp
ret
mov    0x10(%rsp),%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct._citrus_iconv = type { i32 }
@EBADF = global i32 0
@errno = global i32 0
define i64 @libiconv(i64 %0, i8** %1, i64* %2, i8** %3, i64* %4) {
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8**
%9 = alloca i64*
%10 = alloca i8**
%11 = alloca i64*
%12 = alloca i64
%13 = alloca i32
store i64 %0, i64* %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* %7
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %5
%17 = load i64, i64* %7
%18 = icmp eq i64 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %16, %5
%20 = load i32, i32* @EBADF
store i32 %20, i32* @errno
store i64 -1, i64* %6
br label %36
21: ; preds = %16
%22 = load i64, i64* %7
%23 = inttoptr i64 %22 to i8*
%24 = bitcast i8* %23 to %struct._citrus_iconv*
%25 = load i8**, i8*** %8
%26 = load i64*, i64** %9
%27 = load i8**, i8*** %10
%28 = load i64*, i64** %11
%29 = call i32 @_citrus_iconv_convert(%struct._citrus_iconv* %24, i8** %25, i64* %26, i8** %27, i64* %28, i32 0, i64* %12)
store i32 %29, i32* %13
%30 = load i32, i32* %13
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = load i32, i32* %13
store i32 %33, i32* @errno
store i64 -1, i64* %12
br label %34
34: ; preds = %32, %21
%35 = load i64, i64* %12
store i64 %35, i64* %6
br label %36
36: ; preds = %34, %19
%37 = load i64, i64* %6
ret i64 %37
}

LLVM IR (-O2):
%struct._citrus_iconv = type { i32 }
@EBADF = global i32 0
@errno = global i32 0
define i64 @libiconv(i64 %0, i8** %1, i64* %2, i8** %3, i64* %4) {
%6 = alloca i64
%7 = bitcast i64* %6 to i8*
%8 = add i64 %0, 1
%9 = icmp ult i64 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = load i32, i32* @EBADF
store i32 %11, i32* @errno
br label %19
12: ; preds = %5
%13 = inttoptr i64 %0 to %struct._citrus_iconv*
%14 = call i32 @_citrus_iconv_convert(%struct._citrus_iconv* %13, i8** %1, i64* %2, i8** %3, i64* %4, i32 0, i64* %6)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i64, i64* %6
br label %19
18: ; preds = %12
store i32 %14, i32* @errno
br label %19
19: ; preds = %18, %16, %10
%20 = phi i64 [ -1, %10 ], [ %17, %16 ], [ -1, %18 ]
ret i64 %20
}