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

/* Variables and functions */
scalar_t__ EINVAL;
int /*<<< orphan*/ abort();
scalar_t__ errno;
size_t iconv(int /*<<< orphan*/, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_open(char *, char *);
int main() {
  iconv_t cd = iconv_open("wchar_t", "UTF-8");
  char inbuf[2] = {0xc2, 0xa0};
  wchar_t outbuf[10];
  char *inptr = inbuf;
  size_t inbytesleft = 1;
  char *outptr = (char *)outbuf;
  size_t outbytesleft = sizeof(outbuf);
  size_t r = iconv(cd, (char **)&inptr, &inbytesleft, &outptr, &outbytesleft);
  if (!(r == (size_t)(-1) && errno == EINVAL))
    abort();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1050 <iconv_open@plt>
mov    %eax,-0x8(%rbp)
mov    0xeb2(%rip),%ax
mov    %ax,-0xa(%rbp)
lea    -0xa(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x1,-0x50(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
movq   $0x28,-0x60(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
lea    -0x60(%rbp),%r8
call   1040 <iconv@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0xffffffffffffffff,-0x68(%rbp)
jne    11c1 <main+0x91>
mov    0x2e32(%rip),%rax
mov    (%rax),%rax
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%rax
je     11c8 <main+0x98>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x58,%rsp
lea    0xec5(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1050 <iconv_open@plt>
movw   $0xa0c2,0xe(%rsp)
lea    0xe(%rsp),%rcx
mov    %rcx,0x28(%rsp)
movq   $0x1,0x20(%rsp)
lea    0x30(%rsp),%rcx
mov    %rcx,0x18(%rsp)
movq   $0x28,0x10(%rsp)
lea    0x28(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %eax,%edi
call   1040 <iconv@plt>
cmp    $0xffffffffffffffff,%rax
jne    11b2 <main+0x82>
mov    0x2e44(%rip),%rax
mov    (%rax),%rax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
jne    11b2 <main+0x82>
xor    %eax,%eax
add    $0x58,%rsp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"wchar_t\00"
@.str.1 = [6 x i8] c"UTF-8\00"
@__const.main.inbuf = [2 x i8] c"\C2\A0"
@errno = global i64 0
@EINVAL = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i8]
%4 = alloca [10 x i32]
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %1
%10 = call i32 @iconv_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %10, i32* %2
%11 = bitcast [2 x i8]* %3 to i8*
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8* %12, i8** %5
store i64 1, i64* %6
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 0
%14 = bitcast i32* %13 to i8*
store i8* %14, i8** %7
store i64 40, i64* %8
%15 = load i32, i32* %2
%16 = call i64 @iconv(i32 %15, i8** %5, i64* %6, i8** %7, i64* %8)
store i64 %16, i64* %9
%17 = load i64, i64* %9
%18 = icmp eq i64 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %0
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINVAL
%22 = icmp eq i64 %20, %21
br i1 %22, label %25, label %23
23: ; preds = %19, %0
%24 = call i32 (...) @abort()
unreachable
25: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"wchar_t\00"
@.str.1 = [6 x i8] c"UTF-8\00"
@errno = global i64 0
@EINVAL = global i64 0
define i32 @main() {
%1 = alloca i16
%2 = alloca [10 x i32]
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = tail call i32 @iconv_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%8 = bitcast i16* %1 to i8*
store i16 -24382, i16* %1
%9 = bitcast [10 x i32]* %2 to i8*
%10 = bitcast i8** %3 to i8*
%11 = bitcast i8** %3 to i16**
store i16* %1, i16** %11
%12 = bitcast i64* %4 to i8*
store i64 1, i64* %4
%13 = bitcast i8** %5 to i8*
%14 = bitcast i8** %5 to [10 x i32]**
store [10 x i32]* %2, [10 x i32]** %14
%15 = bitcast i64* %6 to i8*
store i64 40, i64* %6
%16 = call i64 @iconv(i32 %7, i8** %3, i64* %4, i8** %5, i64* %6)
%17 = icmp eq i64 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %0
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINVAL
%21 = icmp eq i64 %19, %20
br i1 %21, label %24, label %22
22: ; preds = %18, %0
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %18
ret i32 0
}