#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 */
char *LIBPTHREAD_SO;
int /*<<< orphan*/ RTLD_NOW;
char *dlerror();
int /*<<< orphan*/ *dlopen(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ iconv_open(char *, char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int do_test(void) {
  (void)iconv_open("ISO-8859-1", "ISO-8859-2");
  if (dlopen(LIBPTHREAD_SO, RTLD_NOW) == NULL) {
    printf("cannot load %s: %s\n", LIBPTHREAD_SO, dlerror());
    exit(1);
  }
  (void)iconv_open("ISO-8859-2", "ISO-8859-3");
  return 0;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1070 <iconv_open@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%rdi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
call   1050 <dlopen@plt>
cmp    $0x0,%rax
jne    11bf <do_test+0x6f>
mov    0x2e44(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x8(%rbp),%rsi
mov    %rax,%rdx
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe45(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1070 <iconv_open@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbx
lea    0xea8(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1070 <iconv_open@plt>
mov    0x2e6d(%rip),%rbx
mov    (%rbx),%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
call   1050 <dlopen@plt>
test   %rax,%rax
je     1198 <do_test+0x48>
lea    0xe83(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <iconv_open@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    (%rbx),%rbx
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe6d(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"ISO-8859-1\00"
@.str.1 = [11 x i8] c"ISO-8859-2\00"
@LIBPTHREAD_SO = global i8* null
@RTLD_NOW = global i32 0
@.str.2 = [20 x i8] c"cannot load %s: %s\0A\00"
@.str.3 = [11 x i8] c"ISO-8859-3\00"
define i32 @do_test() {
%1 = call i32 @iconv_open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%2 = load i8*, i8** @LIBPTHREAD_SO
%3 = load i32, i32* @RTLD_NOW
%4 = call i32* @dlopen(i8* %2, i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i8*, i8** @LIBPTHREAD_SO
%8 = call i8* (...) @dlerror()
%9 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %8)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i32 @iconv_open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"ISO-8859-1\00"
@.str.1 = [11 x i8] c"ISO-8859-2\00"
@LIBPTHREAD_SO = global i8* null
@RTLD_NOW = global i32 0
@.str.2 = [20 x i8] c"cannot load %s: %s\0A\00"
@.str.3 = [11 x i8] c"ISO-8859-3\00"
define i32 @do_test() {
%1 = tail call i32 @iconv_open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%2 = load i8*, i8** @LIBPTHREAD_SO
%3 = load i32, i32* @RTLD_NOW
%4 = tail call i32* @dlopen(i8* %2, i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i8*, i8** @LIBPTHREAD_SO
%8 = tail call i8* (...) @dlerror()
%9 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = tail call i32 @iconv_open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}