#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ free(char *);
char *get_output_charset();
int /*<<< orphan*/ *stderr;
char *utf8tostr(char *, char *);
int output(FILE *stream, char *str) {
  char *cs_to = get_output_charset();
  char *output = utf8tostr(cs_to, str);
  if (output == NULL) {
    fprintf(stderr, "conversion from 'UTF-8' to '%s' failed\n", cs_to);
    return 0;
  }
  fprintf(stream, "%s", output);
  free(output);
  return 1;
}


x86 assembly (clang, -O0):
<output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1060 <get_output_charset@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <utf8tostr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119d <output+0x5d>
mov    0x2e62(%rip),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe74(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <output+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe7c(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%r14
xor    %r15d,%r15d
xor    %eax,%eax
call   1070 <get_output_charset@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1060 <utf8tostr@plt>
test   %rax,%rax
je     1198 <output+0x48>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    $0x1,%r15d
jmp    11b1 <output+0x61>
mov    0x2e41(%rip),%rax
mov    (%rax),%rdi
lea    0xe57(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32* null
@.str = [40 x i8] c"conversion from 'UTF-8' to '%s' failed\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @output(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = call i8* (...) @get_output_charset()
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = load i8*, i8** %5
%11 = call i8* @utf8tostr(i8* %9, i8* %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32*, i32** @stderr
%16 = load i8*, i8** %6
%17 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 0, i32* %3
br label %24
18: ; preds = %2
%19 = load i32*, i32** %4
%20 = load i8*, i8** %7
%21 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %7
%23 = call i32 @free(i8* %22)
store i32 1, i32* %3
br label %24
24: ; preds = %18, %14
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [40 x i8] c"conversion from 'UTF-8' to '%s' failed\0A\00"
define i32 @output(i32* nocapture %0, i8* %1) {
%3 = tail call i8* (...) @get_output_charset()
%4 = tail call i8* @utf8tostr(i8* %3, i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32*, i32** @stderr
%8 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %12
9: ; preds = %2
%10 = tail call i32 @fputs(i8* %4, i32* %0)
%11 = tail call i32 @free(i8* %4)
br label %12
12: ; preds = %9, %6
%13 = phi i32 [ 0, %6 ], [ 1, %9 ]
ret i32 %13
}