#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 cconv {
  int dummy;
};
typedef scalar_t__ iconv_t;

/* Variables and functions */
struct cconv *create(scalar_t__);
int /*<<< orphan*/ encode_replacement(struct cconv *);
scalar_t__ iconv_open(char const *, char *);
struct cconv *cconv_from_utf8(const char *encoding) {
  iconv_t cd = iconv_open(encoding, "UTF-8");
  if (cd == (iconv_t)-1) {
    return NULL;
  }
  struct cconv *c = create(cd);
  encode_replacement(c);
  return c;
}


x86 assembly (clang, -O0):
<cconv_from_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <iconv_open@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    1168 <cconv_from_utf8+0x38>
movq   $0x0,-0x8(%rbp)
jmp    1186 <cconv_from_utf8+0x56>
mov    -0x18(%rbp),%rdi
call   1030 <create@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <encode_replacement@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cconv_from_utf8>:
push   %rbx
lea    0xec8(%rip),%rsi
call   1050 <iconv_open@plt>
cmp    $0xffffffffffffffff,%rax
je     1158 <cconv_from_utf8+0x28>
mov    %rax,%rdi
call   1030 <create@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <encode_replacement@plt>
jmp    115a <cconv_from_utf8+0x2a>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.cconv = type { i32 }
@.str = [6 x i8] c"UTF-8\00"
define %struct.cconv* @cconv_from_utf8(i8* %0) {
%2 = alloca %struct.cconv*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.cconv*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @iconv_open(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i64 %7, i64* %4
%8 = load i64, i64* %4
%9 = icmp eq i64 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %1
store %struct.cconv* null, %struct.cconv** %2
br label %17
11: ; preds = %1
%12 = load i64, i64* %4
%13 = call %struct.cconv* @create(i64 %12)
store %struct.cconv* %13, %struct.cconv** %5
%14 = load %struct.cconv*, %struct.cconv** %5
%15 = call i32 @encode_replacement(%struct.cconv* %14)
%16 = load %struct.cconv*, %struct.cconv** %5
store %struct.cconv* %16, %struct.cconv** %2
br label %17
17: ; preds = %11, %10
%18 = load %struct.cconv*, %struct.cconv** %2
ret %struct.cconv* %18
}

LLVM IR (-O2):
%struct.cconv = type { i32 }
@.str = [6 x i8] c"UTF-8\00"
define %struct.cconv* @cconv_from_utf8(i8* %0) {
%2 = tail call i64 @iconv_open(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, -1
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call %struct.cconv* @create(i64 %2)
%6 = tail call i32 @encode_replacement(%struct.cconv* %5)
br label %7
7: ; preds = %1, %4
%8 = phi %struct.cconv* [ %5, %4 ], [ null, %1 ]
ret %struct.cconv* %8
}