#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 void *iconv_t;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
size_t find_charmap(char const *);
iconv_t iconv_open(const char *to, const char *from) {
  size_t f, t;
  if ((t = find_charmap(to)) == -1 || (f = find_charmap(from)) == -1) {
    errno = EINVAL;
    return (iconv_t)-1;
  }
  return (void *)(f << 16 | t);
}


x86 assembly (clang, -O0):
<iconv_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <find_charmap@plt>
mov    %rax,-0x28(%rbp)
cmp    $0xffffffffffffffff,%rax
je     114e <iconv_open+0x3e>
mov    -0x18(%rbp),%rdi
call   1030 <find_charmap@plt>
mov    %rax,-0x20(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    1170 <iconv_open+0x60>
mov    0x2e83(%rip),%rax
mov    (%rax),%ecx
mov    0x2e82(%rip),%rax
mov    %ecx,(%rax)
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1180 <iconv_open+0x70>
mov    -0x20(%rbp),%rax
shl    $0x10,%rax
or     -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iconv_open>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1030 <find_charmap@plt>
cmp    $0xffffffffffffffff,%rax
je     113c <iconv_open+0x2c>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <find_charmap@plt>
cmp    $0xffffffffffffffff,%rax
je     113c <iconv_open+0x2c>
shl    $0x10,%rax
or     %rbx,%rax
jmp    1155 <iconv_open+0x45>
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    0x2e94(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffffffffffff,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define i8* @iconv_open(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i64 @find_charmap(i8* %8)
store i64 %9, i64* %7
%10 = icmp eq i64 %9, -1
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i64 @find_charmap(i8* %12)
store i64 %13, i64* %6
%14 = icmp eq i64 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %11, %2
%16 = load i32, i32* @EINVAL
store i32 %16, i32* @errno
store i8* inttoptr (i64 -1 to i8*), i8** %3
br label %23
17: ; preds = %11
%18 = load i64, i64* %6
%19 = shl i64 %18, 16
%20 = load i64, i64* %7
%21 = or i64 %19, %20
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %3
br label %23
23: ; preds = %17, %15
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i8* @iconv_open(i8* %0, i8* %1) {
%3 = tail call i64 @find_charmap(i8* %0)
%4 = icmp eq i64 %3, -1
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i64 @find_charmap(i8* %1)
%7 = icmp eq i64 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %5, %2
%9 = load i32, i32* @EINVAL
store i32 %9, i32* @errno
br label %14
10: ; preds = %5
%11 = shl i64 %6, 16
%12 = or i64 %11, %3
%13 = inttoptr i64 %12 to i8*
br label %14
14: ; preds = %10, %8
%15 = phi i8* [ inttoptr (i64 -1 to i8*), %8 ], [ %13, %10 ]
ret i8* %15
}